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.util.JS.java

License:Open Source License

public static String decodeURIComponent(String s) {

    // Get rid of all unicode

    s = s.replaceAll("%u[0-9a-fA-F]{4}", StringPool.BLANK);

    // Adjust for JavaScript specific annoyances

    s = StringUtil.replace(s, "+", "%2B");
    s = StringUtil.replace(s, "%20", "+");

    // Decode URL

    try {//ww  w  .j a va2s. c o m
        s = URLDecoder.decode(s, StringPool.UTF8);
    } catch (Exception e) {
    }

    return s;
}

From source file:com.liferay.util.log4j.Log4JUtil.java

License:Open Source License

private static String _getURLContent(URL url) {
    Map<String, String> variables = new HashMap<String, String>();

    variables.put("liferay.home", _getLiferayHome());

    String urlContent = null;/* w w  w . ja  va2  s.c o m*/

    InputStream inputStream = null;

    try {
        inputStream = url.openStream();

        byte[] bytes = _getBytes(inputStream);

        urlContent = new String(bytes, StringPool.UTF8);
    } catch (Exception e) {
        e.printStackTrace();

        return null;
    } finally {
        StreamUtil.cleanUp(inputStream);
    }

    for (Map.Entry<String, String> variable : variables.entrySet()) {
        urlContent = urlContent.replaceAll("@" + variable.getKey() + "@", variable.getValue());
    }

    if (ServerDetector.getServerId() != null) {
        return urlContent;
    }

    int x = urlContent.indexOf("<appender name=\"FILE\"");

    int y = urlContent.indexOf("</appender>", x);

    if (y != -1) {
        y = urlContent.indexOf("<", y + 1);
    }

    if ((x != -1) && (y != -1)) {
        urlContent = urlContent.substring(0, x) + urlContent.substring(y);
    }

    urlContent = StringUtil.replace(urlContent, "<appender-ref ref=\"FILE\" />", StringPool.BLANK);

    return urlContent;
}

From source file:com.liferay.util.RSSUtil.java

License:Open Source License

public static String export(SyndFeed feed) throws FeedException {
    RSSThreadLocal.setExportRSS(true);/*from w ww  . j  av a 2s  .co  m*/

    feed.setEncoding(StringPool.UTF8);

    SyndFeedOutput output = new SyndFeedOutput();

    try {
        return output.outputString(feed);
    } catch (IllegalDataException ide) {

        // LEP-4450

        _regexpStrip(feed);

        return output.outputString(feed);
    }
}

From source file:com.liferay.util.xml.XMLFormatter.java

License:Open Source License

public static String toString(Node node, String indent, boolean expandEmptyElements, boolean trimText)
        throws IOException {

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    OutputFormat outputFormat = OutputFormat.createPrettyPrint();

    outputFormat.setExpandEmptyElements(expandEmptyElements);
    outputFormat.setIndent(indent);/*from   ww w  .  ja  va  2  s. com*/
    outputFormat.setLineSeparator(StringPool.NEW_LINE);
    outputFormat.setTrimText(trimText);

    XMLWriter xmlWriter = new XMLWriter(unsyncByteArrayOutputStream, outputFormat);

    xmlWriter.write(node);

    String content = unsyncByteArrayOutputStream.toString(StringPool.UTF8);

    // LEP-4257

    //content = StringUtil.replace(content, "\n\n\n", "\n\n");

    if (content.endsWith("\n\n")) {
        content = content.substring(0, content.length() - 2);
    }

    if (content.endsWith("\n")) {
        content = content.substring(0, content.length() - 1);
    }

    while (content.indexOf(" \n") != -1) {
        content = StringUtil.replace(content, " \n", "\n");
    }

    if (content.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")) {
        content = StringUtil.replaceFirst(content, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
                "<?xml version=\"1.0\"?>");
    }

    return content;
}

From source file:com.liferay.whoami.servlet.WhoAmIAuthenticationServlet.java

License:Open Source License

protected void getUser(HttpServletRequest request, HttpServletResponse response) throws Exception {

    ProtectedServletRequest protectedServletRequest = (ProtectedServletRequest) request;

    long userId = GetterUtil.getLong(protectedServletRequest.getRemoteUser());

    User user = UserLocalServiceUtil.getUser(userId);

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put("uuid", user.getUserUuid());
    responseJSONObject.put("fullName", user.getFullName());
    responseJSONObject.put("emailAddress", user.getEmailAddress());
    responseJSONObject.put("avatarURL", StringPool.BLANK);

    String responseJSON = responseJSONObject.toString();

    response.setContentType(ContentTypes.APPLICATION_JSON);

    ServletOutputStream servletOutputStream = response.getOutputStream();

    servletOutputStream.write(responseJSON.getBytes(StringPool.UTF8));
}

From source file:com.liferay.wiki.web.internal.portlet.action.ExportPageMVCActionCommand.java

License:Open Source License

protected void getFile(long nodeId, String title, double version, String targetExtension,
        PortletURL viewPageURL, PortletURL editPageURL, ThemeDisplay themeDisplay, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    WikiPage page = _wikiPageService.getPage(nodeId, title, version);

    String content = page.getContent();

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(themeDisplay.getPathMain(),
            themeDisplay.getPlid(), nodeId, title);

    try {//ww w . j a va2  s . c  o m
        content = _wikiEngineRenderer.convert(page, viewPageURL, editPageURL, attachmentURLPrefix);
    } catch (Exception e) {
        _log.error(
                "Error formatting the wiki page " + page.getPageId() + " with the format " + page.getFormat(),
                e);
    }

    StringBundler sb = new StringBundler(17);

    sb.append("<!DOCTYPE html>");

    sb.append("<html>");

    sb.append("<head>");
    sb.append("<meta content=\"");
    sb.append(ContentTypes.TEXT_HTML_UTF8);
    sb.append("\" http-equiv=\"content-type\" />");
    sb.append("<base href=\"");
    sb.append(themeDisplay.getPortalURL());
    sb.append("\" />");
    sb.append("</head>");

    sb.append("<body>");

    sb.append("<h1>");
    sb.append(title);
    sb.append("</h1>");
    sb.append(content);

    sb.append("</body>");
    sb.append("</html>");

    InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8));

    String sourceExtension = "html";

    String fileName = title.concat(StringPool.PERIOD).concat(sourceExtension);

    if (Validator.isNotNull(targetExtension)) {
        String id = page.getUuid();

        File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension);

        if (convertedFile != null) {
            fileName = title.concat(StringPool.PERIOD).concat(targetExtension);

            is = new FileInputStream(convertedFile);
        }
    }

    String contentType = MimeTypesUtil.getContentType(fileName);

    ServletResponseUtil.sendFile(request, response, fileName, is, contentType);
}

From source file:com.liferay.wiki.web.internal.portlet.action.RSSAction.java

License:Open Source License

@Override
protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long nodeId = ParamUtil.getLong(request, "nodeId");
    String title = ParamUtil.getString(request, "title");
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.FORMAT_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_DEFAULT);

    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay.getScopeGroupId(), WikiPortletKeys.WIKI);

    StringBundler sb = new StringBundler(4);

    sb.append(layoutFullURL);//w  w w  . ja va  2  s .  c o  m
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("wiki/");
    sb.append(nodeId);

    String feedURL = sb.toString();

    String entryURL = feedURL + StringPool.SLASH + title;

    Locale locale = themeDisplay.getLocale();

    String rss = StringPool.BLANK;

    if (nodeId > 0) {
        String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(themeDisplay.getPathMain(),
                themeDisplay.getPlid(), nodeId, title);

        if (Validator.isNotNull(title)) {
            rss = _wikiPageService.getPagesRSS(nodeId, title, max, type, version, displayStyle, feedURL,
                    entryURL, attachmentURLPrefix, locale);
        } else {
            rss = _wikiPageService.getNodePagesRSS(nodeId, max, type, version, displayStyle, feedURL, entryURL,
                    attachmentURLPrefix);
        }
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.wsrp.bind.V2MarkupServiceImpl.java

License:Open Source License

protected String getPortletId(PortletContext portletContext, NavigationalContext navigationalContext)
        throws Exception {

    String portletId = getPortletId(portletContext);

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

        if (Validator.isNotNull(opaqueValue)) {
            opaqueValue = new String(Base64.decode(Base64.fromURLSafe(opaqueValue)), StringPool.UTF8);
        }// w  w  w. j a v a  2s . c o m

        Map<String, String[]> parameterMap = HttpUtil.parameterMapFromString(opaqueValue);

        if (parameterMap.containsKey(_STRUTS_ACTION_PORTLET_CONFIGURATION)) {

            portletId = PortletKeys.PORTLET_CONFIGURATION;
        }
    }

    return portletId;
}

From source file:com.liferay.wsrp.bind.V2MarkupServiceImpl.java

License:Open Source License

protected String getURL(String lifecycle, String resourceID, MimeRequest mimeRequest,
        PortletContext portletContext, WSRPProducer wsrpProducer) throws Exception {

    StringBundler sb = new StringBundler();

    String[] locales = mimeRequest.getLocales();

    if (locales.length > 0) {
        sb.append(getWidgetPath(locales[0]));
    } else {/*  w w w. j  a  v a  2 s.  com*/
        sb.append(getWidgetPath());
    }

    sb.append(StringPool.QUESTION);

    String propertiesAuthenticatonTokenSharedSecret = Encryptor
            .digest(PropsUtil.get(PropsKeys.AUTH_TOKEN_SHARED_SECRET));

    sb.append("p_auth_secret=");
    sb.append(HttpUtil.encodeURL(propertiesAuthenticatonTokenSharedSecret));

    Layout layout = getLayout(portletContext, wsrpProducer);

    sb.append("&p_l_id=");
    sb.append(layout.getPlid());

    NavigationalContext navigationalContext = mimeRequest.getNavigationalContext();

    String portletId = getPortletId(portletContext, navigationalContext);

    sb.append("&p_p_id=");
    sb.append(HttpUtil.encodeURL(portletId));

    sb.append("&p_p_lifecycle=");
    sb.append(lifecycle);

    String windowState = getWindowState(mimeRequest);

    sb.append("&p_p_state=");
    sb.append(HttpUtil.encodeURL(windowState));

    String portletMode = getPortletMode(mimeRequest);

    sb.append("&p_p_mode=");
    sb.append(HttpUtil.encodeURL(portletMode));

    if (lifecycle.equals("2") && Validator.isNotNull(resourceID)) {
        sb.append("&p_p_resource_id=");
        sb.append(resourceID);
    }

    sb.append("&p_p_isolated=1");

    String opaqueValue = null;

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

    if (Validator.isNotNull(opaqueValue)) {
        sb.append(StringPool.AMPERSAND);

        opaqueValue = new String(Base64.decode(Base64.fromURLSafe(opaqueValue)), StringPool.UTF8);

        sb.append(opaqueValue);
    }

    if (lifecycle.equals("0")) {
        MessageElement[] formParameters = ExtensionHelperUtil.getMessageElements(mimeRequest.getExtensions());

        if (formParameters != null) {
            String namespace = PortalUtil.getPortletNamespace(portletId);

            for (MessageElement formParameter : formParameters) {
                sb.append(StringPool.AMPERSAND);

                String name = namespace.concat(ExtensionHelperUtil.getNameAttribute(formParameter));

                sb.append(name);
                sb.append(StringPool.EQUAL);
                sb.append(HttpUtil.encodeURL(formParameter.getValue()));
            }
        }
    }

    if (windowState.equals(LiferayWindowState.EXCLUSIVE.toString())) {
        sb.append("&ensureContentLength=1");
    }

    sb.append("&wsrp=1");

    if (_log.isInfoEnabled()) {
        _log.info("URL " + sb.toString());
    }

    return sb.toString();
}

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

License:Open Source License

protected String getCharSet(String contentType) {
    if (Validator.isNotNull(contentType)) {
        int x = contentType.lastIndexOf("charset=");

        if (x >= 0) {
            return contentType.substring(x + 8).trim();
        }/*from  w w  w.java2s  . c  o m*/
    }

    return StringPool.UTF8;
}