Example usage for com.liferay.portal.kernel.util StringPool UTF8

List of usage examples for com.liferay.portal.kernel.util StringPool UTF8

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool UTF8.

Prototype

String UTF8

To view the source code for com.liferay.portal.kernel.util StringPool UTF8.

Click Source Link

Usage

From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java

License:Open Source License

protected void initContexts(PortletRequest portletRequest, PortletResponse portletResponse,
        WSRPConsumer wsrpConsumer, WSRPConsumerPortlet wsrpConsumerPortlet,
        WSRPConsumerManager wsrpConsumerManager, MimeRequest mimeRequest, PortletContext portletContext,
        RuntimeContext runtimeContext, UserContext userContext) throws Exception {

    PortletSession portletSession = portletRequest.getPortletSession();

    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    // Markup params

    ClientData clientData = new ClientData();

    clientData.setRequestVerb(request.getMethod());
    clientData.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));

    User user = themeDisplay.getUser();/*from   www .ja  v a 2s.c  o m*/

    List<MessageElement> clientAttributes = new ArrayList<MessageElement>();

    Enumeration<String> enu = request.getHeaderNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        String value = request.getHeader(name);

        ExtensionHelperUtil.addMessageElement(clientAttributes, name, value);
    }

    ExtensionHelperUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_EMAIL_ADDRESS,
            user.getEmailAddress());
    ExtensionHelperUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_SCREEN_NAME,
            user.getScreenName());
    ExtensionHelperUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_USER_ID,
            String.valueOf(user.getUserId()));

    ConsumerRequestExtensionsHelper.addClientAttributes(clientAttributes);

    clientData.setExtensions(ExtensionHelperUtil.getExtensions(clientAttributes));

    mimeRequest.setClientData(clientData);

    List<Locale> locales = Collections.list(portletRequest.getLocales());

    String[] localesArray = new String[locales.size()];

    for (int i = 0; i < locales.size(); i++) {
        Locale locale = locales.get(i);

        localesArray[i] = locale.toString();
    }

    Locale locale = themeDisplay.getLocale();

    if (!locales.contains(locale)) {
        localesArray = ArrayUtil.append(new String[] { locale.toString(), locale.getLanguage() }, localesArray);
    }

    mimeRequest.setLocales(localesArray);

    String[] markupCharacterSets = null;

    if (Validator.isNotNull(wsrpConsumer.getMarkupCharacterSets())) {
        String markupCharacterSetsString = wsrpConsumer.getMarkupCharacterSets();

        markupCharacterSetsString = MarkupCharacterSetsUtil
                .getSupportedMarkupCharacterSets(markupCharacterSetsString);

        markupCharacterSets = StringUtil.split(markupCharacterSetsString);
    } else {
        markupCharacterSets = _CHAR_SETS;
    }

    mimeRequest.setMarkupCharacterSets(markupCharacterSets);

    mimeRequest.setMimeTypes(_MIME_TYPES);
    mimeRequest.setMode(getWSRPMode(portletRequest.getPortletMode()));
    mimeRequest.setWindowState(getWSRPWindowState(portletRequest.getWindowState()));

    String[] modes = { getWSRPMode(PortletMode.EDIT), getWSRPMode(PortletMode.HELP),
            getWSRPMode(PortletMode.VIEW) };

    mimeRequest.setValidNewModes(modes);

    String[] windowStates = { getWSRPWindowState(WindowState.MAXIMIZED),
            getWSRPWindowState(WindowState.MINIMIZED), getWSRPWindowState(WindowState.NORMAL) };

    mimeRequest.setValidNewWindowStates(windowStates);

    // Navigational context

    NavigationalContext navigationalContext = new NavigationalContext();

    String navigationalState = portletRequest.getParameter("wsrp-navigationalState");

    if (Validator.isNotNull(navigationalState)) {
        navigationalState = new String(Base64.decode(Base64.fromURLSafe(navigationalState)), StringPool.UTF8);

        navigationalContext.setOpaqueValue(navigationalState);
    }

    Map<String, String[]> publicParameterMap = portletRequest.getPublicParameterMap();

    List<NamedString> publicValues = new ArrayList<NamedString>();

    for (Map.Entry<String, String[]> entry : publicParameterMap.entrySet()) {

        String name = entry.getKey();
        String[] values = entry.getValue();

        for (String value : values) {
            NamedString publicValue = new NamedString();

            publicValue.setName(name);
            publicValue.setValue(value);

            publicValues.add(publicValue);
        }
    }

    navigationalContext.setPublicValues(publicValues.toArray(new NamedString[publicValues.size()]));

    mimeRequest.setNavigationalContext(navigationalContext);

    if (mimeRequest instanceof MarkupParams) {
        processFormParameters(portletRequest, portletResponse, mimeRequest);
    }

    // Portlet context

    portletContext.setPortletHandle(wsrpConsumerPortlet.getPortletHandle());

    // Runtime context

    runtimeContext.setNamespacePrefix(portletResponse.getNamespace());
    runtimeContext.setPortletInstanceKey(portletResponse.getNamespace());

    SessionContext sessionContext = (SessionContext) portletSession.getAttribute(WebKeys.SESSION_CONTEXT);

    if (sessionContext != null) {
        SessionParams sessionParams = new SessionParams();

        sessionParams.setSessionID(sessionContext.getSessionID());

        runtimeContext.setSessionParams(sessionParams);
    }

    runtimeContext.setUserAuthentication("wsrp:password");

    PortletDescription portletDescription = wsrpConsumerManager
            .getPortletDescription(wsrpConsumerPortlet.getPortletHandle());

    Boolean doesUrlTemplateProcessing = portletDescription.getDoesUrlTemplateProcessing();

    if ((doesUrlTemplateProcessing != null) && doesUrlTemplateProcessing) {
        Templates templates = new Templates();

        templates.setBlockingActionTemplate(_BLOCKING_ACTION_TEMPLATE);
        templates.setRenderTemplate(_RENDER_TEMPLATE);
        templates.setResourceTemplate(_RESOURCE_TEMPLATE);
        templates.setSecureBlockingActionTemplate(_BLOCKING_ACTION_TEMPLATE);
        templates.setSecureRenderTemplate(_RENDER_TEMPLATE);
        templates.setSecureResourceTemplate(_RESOURCE_TEMPLATE);

        runtimeContext.setTemplates(templates);
    }

    // User context

    UserProfile userProfile = getUserProfile(user);

    ConsumerRequestExtensionsHelper.addUserProfileAttributes(userProfile, user);

    userContext.setProfile(userProfile);

    userContext.setUserContextKey(String.valueOf(user.getUserId()));
}

From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java

License:Open Source License

protected void processUpdateResponse(PortletRequest portletRequest, StateAwareResponse stateAwareResponse,
        WSRPConsumerManager wsrpConsumerManager, ServiceHolder serviceHolder, UpdateResponse updateResponse)
        throws Exception {

    PortletSession portletSession = portletRequest.getPortletSession();

    if (updateResponse == null) {
        return;//  w w  w  .  j av a 2  s  .c o  m
    }

    portletSession.setAttribute(WebKeys.MARKUP_CONTEXT, updateResponse.getMarkupContext());

    NavigationalContext navigationalContext = updateResponse.getNavigationalContext();

    if (navigationalContext != null) {
        String opaqueValue = navigationalContext.getOpaqueValue();

        if (Validator.isNotNull(opaqueValue)) {
            byte[] opaqueValueBytes = opaqueValue.getBytes(StringPool.UTF8);

            opaqueValue = Base64.toURLSafe(Base64.encode(opaqueValueBytes));

            stateAwareResponse.setRenderParameter("wsrp-navigationalState", opaqueValue);
        }

        NamedString[] publicValues = navigationalContext.getPublicValues();

        if (publicValues != null) {
            for (NamedString publicValue : publicValues) {
                String name = publicValue.getName();
                String value = publicValue.getValue();

                if (Validator.isNotNull(value)) {
                    stateAwareResponse.setRenderParameter(name, value);
                } else {
                    stateAwareResponse.removePublicRenderParameter(name);
                }
            }
        }
    }

    PortletContext portletContext = updateResponse.getPortletContext();

    if (portletContext != null) {
        portletSession.setAttribute(WebKeys.PORTLET_CONTEXT, portletContext);
    }

    SessionContext sessionContext = updateResponse.getSessionContext();

    updateSessionContext(portletSession, serviceHolder, sessionContext);

    String portletMode = updateResponse.getNewMode();

    if (Validator.isNotNull(portletMode)) {
        stateAwareResponse.setPortletMode(getPortletMode(portletMode));
    }

    String windowState = updateResponse.getNewWindowState();

    if (Validator.isNotNull(windowState)) {
        stateAwareResponse.setWindowState(getWindowState(windowState));
    }

    Event[] events = updateResponse.getEvents();

    if (events != null) {
        for (Event event : events) {
            QName qName = wsrpConsumerManager.getEventQName(event.getName());

            event.setName(qName);

            stateAwareResponse.setEvent(qName, event);
        }
    }
}

From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java

License:Open Source License

protected String rewriteURL(PortletRequest portletRequest, PortletResponse portletResponse,
        Map<String, String> parameterMap) throws Exception {

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) portletResponse;

    String lifecycle = parameterMap.get("wsrp-urlType");

    LiferayPortletURL liferayPortletURL = null;

    if (lifecycle.equals("blockingAction")) {
        liferayPortletURL = (LiferayPortletURL) liferayPortletResponse.createActionURL();
    } else if (lifecycle.equals("render")) {
        liferayPortletURL = (LiferayPortletURL) liferayPortletResponse.createRenderURL();
    } else if (lifecycle.equals("resource")) {
        liferayPortletURL = (LiferayPortletURL) liferayPortletResponse.createResourceURL();

        if (PortletPropsValues.SECURE_RESOURCE_URLS_ENABLED) {
            secureResourceURL(portletRequest, liferayPortletURL, parameterMap);
        }/*from  w w  w  .  ja v  a 2s. c  o m*/
    }

    for (Map.Entry<String, String> parameter : parameterMap.entrySet()) {
        String name = parameter.getKey();
        String value = parameter.getValue();

        if (name.equals("wsrp-mode")) {
            try {
                liferayPortletURL.setPortletMode(getPortletMode(value));
            } catch (Exception e) {
                liferayPortletURL.setPortletMode(PortletMode.VIEW);
            }
        } else if (name.equals("wsrp-navigationalState")) {
            if (Validator.isNotNull(value)) {
                byte[] valueBytes = value.getBytes(StringPool.UTF8);

                value = Base64.toURLSafe(Base64.encode(valueBytes));

                liferayPortletURL.setParameter(name, value);
            }
        } else if (name.equals("wsrp-navigationalValues")) {
            Matcher navigationalValuesMatcher = _navigationalValuesPattern.matcher(value);

            while (navigationalValuesMatcher.find()) {
                String navigationalValuesName = navigationalValuesMatcher.group(1);
                String navigationalValuesValue = navigationalValuesMatcher.group(2);

                if (Validator.isNull(navigationalValuesValue)) {
                    liferayPortletURL.removePublicRenderParameter(navigationalValuesName);
                } else {
                    liferayPortletURL.setParameter(navigationalValuesName, navigationalValuesValue, true);
                }
            }
        } else if (name.equals("wsrp-resourceID")) {
            liferayPortletURL.setResourceID(value);
        } else if (name.equals("wsrp-urlType")) {
        } else if (name.equals("wsrp-windowState")) {
            try {
                liferayPortletURL.setWindowState(getWindowState(value));
            } catch (Exception e) {
                liferayPortletURL.setWindowState(WindowState.NORMAL);
            }
        } else {
            liferayPortletURL.setParameter(name, value);
        }
    }

    String url = liferayPortletURL.toString();

    return url;
}

From source file:com.liferay.wsrp.util.MarkupCharacterSetsUtil.java

License:Open Source License

public static String getSupportedMarkupCharacterSets(String markupCharacterSets) {

    if (Validator.isNull(markupCharacterSets)) {
        return null;
    }/*w  w  w. j ava 2  s.co m*/

    if (!markupCharacterSets.contains(StringPool.UTF8)) {
        markupCharacterSets = markupCharacterSets.concat(StringPool.COMMA).concat(StringPool.UTF8);
    }

    return markupCharacterSets;
}

From source file:com.slemarchand.peoplepublisher.util.PeoplePublisherImpl.java

License:Open Source License

private String _getUserXml(String screenName) {

    String xml = null;//from w ww  .  ja v a  2  s .  c  om

    try {
        Document document = SAXReaderUtil.createDocument(StringPool.UTF8);

        Element userElement = document.addElement("user");

        Element screenNameElement = userElement.addElement("screen-name");

        screenNameElement.addText(screenName);

        xml = document.formattedString(StringPool.BLANK);
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn(ioe);
        }
    }

    return xml;
}

From source file:com.twelve.capital.external.feed.util.HttpImpl.java

License:Open Source License

@Override
public String decodeURL(String url, boolean unescapeSpaces) {
    if (Validator.isNull(url)) {
        return url;
    }//from w w w.  j ava2  s.c  o  m

    return URLCodec.decodeURL(url, StringPool.UTF8, unescapeSpaces);
}

From source file:com.twelve.capital.external.feed.util.HttpImpl.java

License:Open Source License

@Override
public String encodeURL(String url, boolean escapeSpaces) {
    if (Validator.isNull(url)) {
        return url;
    }/*from  w ww  . j  ava  2s  .  c o m*/

    return URLCodec.encodeURL(url, StringPool.UTF8, escapeSpaces);
}

From source file:com.twelve.capital.external.feed.util.HttpImpl.java

License:Open Source License

protected byte[] URLtoByteArray(String location, Http.Method method, Map<String, String> headers,
        Cookie[] cookies, Http.Auth auth, Http.Body body, List<Http.FilePart> fileParts,
        Map<String, String> parts, Http.Response response, boolean followRedirects, String progressId,
        PortletRequest portletRequest) throws IOException {

    byte[] bytes = null;

    HttpMethod httpMethod = null;/* w w  w.java 2 s  . c  om*/
    HttpState httpState = null;

    try {
        _cookies.set(null);

        if (location == null) {
            return null;
        } else if (!location.startsWith(Http.HTTP_WITH_SLASH) && !location.startsWith(Http.HTTPS_WITH_SLASH)) {

            location = Http.HTTP_WITH_SLASH + location;
        }

        HostConfiguration hostConfiguration = getHostConfiguration(location);

        HttpClient httpClient = getClient(hostConfiguration);

        if (method.equals(Http.Method.POST) || method.equals(Http.Method.PUT)) {

            if (method.equals(Http.Method.POST)) {
                httpMethod = new PostMethod(location);
            } else {
                httpMethod = new PutMethod(location);
            }

            if (body != null) {
                RequestEntity requestEntity = new StringRequestEntity(body.getContent(), body.getContentType(),
                        body.getCharset());

                EntityEnclosingMethod entityEnclosingMethod = (EntityEnclosingMethod) httpMethod;

                entityEnclosingMethod.setRequestEntity(requestEntity);
            } else if (method.equals(Http.Method.POST)) {
                PostMethod postMethod = (PostMethod) httpMethod;

                if (!hasRequestHeader(postMethod, HttpHeaders.CONTENT_TYPE)) {

                    HttpClientParams httpClientParams = httpClient.getParams();

                    httpClientParams.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, StringPool.UTF8);
                }

                processPostMethod(postMethod, fileParts, parts);
            }
        } else if (method.equals(Http.Method.DELETE)) {
            httpMethod = new DeleteMethod(location);
        } else if (method.equals(Http.Method.HEAD)) {
            httpMethod = new HeadMethod(location);
        } else {
            httpMethod = new GetMethod(location);
        }

        if (headers != null) {
            for (Map.Entry<String, String> header : headers.entrySet()) {
                httpMethod.addRequestHeader(header.getKey(), header.getValue());
            }
        }

        if ((method.equals(Http.Method.POST) || method.equals(Http.Method.PUT)) && ((body != null)
                || ((fileParts != null) && !fileParts.isEmpty()) || ((parts != null) && !parts.isEmpty()))) {
        } else if (!hasRequestHeader(httpMethod, HttpHeaders.CONTENT_TYPE)) {
            httpMethod.addRequestHeader(HttpHeaders.CONTENT_TYPE,
                    ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED_UTF8);
        }

        if (!hasRequestHeader(httpMethod, HttpHeaders.USER_AGENT)) {
            httpMethod.addRequestHeader(HttpHeaders.USER_AGENT, _DEFAULT_USER_AGENT);
        }

        httpState = new HttpState();

        if (ArrayUtil.isNotEmpty(cookies)) {
            org.apache.commons.httpclient.Cookie[] commonsCookies = toCommonsCookies(cookies);

            httpState.addCookies(commonsCookies);

            HttpMethodParams httpMethodParams = httpMethod.getParams();

            httpMethodParams.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        }

        if (auth != null) {
            httpMethod.setDoAuthentication(true);

            httpState.setCredentials(new AuthScope(auth.getHost(), auth.getPort(), auth.getRealm()),
                    new UsernamePasswordCredentials(auth.getUsername(), auth.getPassword()));
        }

        proxifyState(httpState, hostConfiguration);

        int responseCode = httpClient.executeMethod(hostConfiguration, httpMethod, httpState);

        response.setResponseCode(responseCode);

        Header locationHeader = httpMethod.getResponseHeader("location");

        if ((locationHeader != null) && !locationHeader.equals(location)) {
            String redirect = locationHeader.getValue();

            if (followRedirects) {
                return URLtoByteArray(redirect, Http.Method.GET, headers, cookies, auth, body, fileParts, parts,
                        response, followRedirects, progressId, portletRequest);
            } else {
                response.setRedirect(redirect);
            }
        }

        InputStream inputStream = httpMethod.getResponseBodyAsStream();

        if (inputStream != null) {
            int contentLength = 0;

            Header contentLengthHeader = httpMethod.getResponseHeader(HttpHeaders.CONTENT_LENGTH);

            if (contentLengthHeader != null) {
                contentLength = GetterUtil.getInteger(contentLengthHeader.getValue());

                response.setContentLength(contentLength);
            }

            Header contentType = httpMethod.getResponseHeader(HttpHeaders.CONTENT_TYPE);

            if (contentType != null) {
                response.setContentType(contentType.getValue());
            }

            if (Validator.isNotNull(progressId) && (portletRequest != null)) {

                ProgressInputStream progressInputStream = new ProgressInputStream(portletRequest, inputStream,
                        contentLength, progressId);

                UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream(
                        contentLength);

                try {
                    progressInputStream.readAll(unsyncByteArrayOutputStream);
                } finally {
                    progressInputStream.clearProgress();
                }

                bytes = unsyncByteArrayOutputStream.unsafeGetByteArray();

                unsyncByteArrayOutputStream.close();
            } else {
                bytes = FileUtil.getBytes(inputStream);
            }
        }

        for (Header header : httpMethod.getResponseHeaders()) {
            response.addHeader(header.getName(), header.getValue());
        }

        return bytes;
    } finally {
        try {
            if (httpState != null) {
                _cookies.set(toServletCookies(httpState.getCookies()));
            }
        } catch (Exception e) {
            _log.error(e, e);
        }

        try {
            if (httpMethod != null) {
                httpMethod.releaseConnection();
            }
        } catch (Exception e) {
            _log.error(e, e);
        }
    }
}

From source file:com.vportal.portlet.vcmsviewcontent.action.RSSAction.java

License:Open Source License

protected byte[] getRSS(HttpServletRequest request) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");
    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    String categoryId = ParamUtil.getString(request, "categoryId", "0");
    String portletSelectId = ParamUtil.getString(request, "portletSelectId", "0");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.DEFAULT_TYPE);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.DEFAULT_VERSION);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);

    String feedURL = themeDisplay.getURLPortal() + themeDisplay.getPathMain() + "/vcmsviewcontent/view?";

    String entryURL = feedURL;//from w  ww . j a  va  2 s. c  o m

    String rss = StringPool.BLANK;

    if (layout != null) {
        groupId = layout.getGroupId();
        PortletURL rssURL = PortletURLFactoryUtil.create(request, portletSelectId, plid,
                PortletRequest.RENDER_PHASE);
        rssURL.setParameter("struts_action", "/vcmsviewcontent/view");
        rssURL.setParameter("categoryId", categoryId);
        rssURL.setParameter("cat_parent", categoryId);
        feedURL = rssURL.toString();

        entryURL = feedURL;

        rss = VcmsCategoryServiceUtil.getCategoriesByRSS(categoryId, 5, type, version, displayStyle, entryURL,
                entryURL, 5, themeDisplay);
    }
    return rss.getBytes(StringPool.UTF8);
}

From source file:gov.nih.nci.cagrid.portal.util.DBLoader.java

License:Open Source License

private void _loadDerby(Connection con, String fileName) throws Exception {

    StringBuilder sb = new StringBuilder();

    BufferedReader br = new BufferedReader(new StringReader(_fileUtil.read(fileName)));

    String line = null;//from w w w  .jav  a 2s . com

    while ((line = br.readLine()) != null) {
        if (!line.startsWith("--")) {
            sb.append(line);

            if (line.endsWith(";")) {
                String sql = sb.toString();

                sql = StringUtil.replace(sql, new String[] { "\\'", "\\\"", "\\\\", "\\n", "\\r" },
                        new String[] { "''", "\"", "\\", "\n", "\r" });

                sql = sql.substring(0, sql.length() - 1);

                sb = new StringBuilder();

                if (sql.startsWith("commit")) {
                    continue;
                }

                ij.runScript(con, new ByteArrayInputStream(sql.getBytes(StringPool.UTF8)), StringPool.UTF8,
                        new ByteArrayOutputStream(), StringPool.UTF8);
            }
        }
    }

    br.close();
}