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.portlet.layoutsadmin.util.SitemapImpl.java

License:Open Source License

public String getSitemap(long groupId, boolean privateLayout, ThemeDisplay themeDisplay)
        throws PortalException, SystemException {

    Document document = SAXReaderUtil.createDocument();

    document.setXMLEncoding(StringPool.UTF8);

    Element rootElement = document.addElement("urlset", "http://www.google.com/schemas/sitemap/0.84");

    List<Layout> layouts = LayoutLocalServiceUtil.getLayouts(groupId, privateLayout,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    visitLayouts(rootElement, layouts, themeDisplay);

    return document.asXML();
}

From source file:com.liferay.portlet.messageboards.action.RSSAction.java

License:Open Source License

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

    String plid = ParamUtil.getString(request, "p_l_id");
    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long userId = ParamUtil.getLong(request, "userId");
    long categoryId = ParamUtil.getLong(request, "mbCategoryId");
    long threadId = ParamUtil.getLong(request, "threadId");
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.TYPE_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);

    String entryURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
            + "/message_boards/find_message?p_l_id=" + plid;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
        String feedURL = StringPool.BLANK;

        rss = MBMessageServiceUtil.getCompanyMessagesRSS(companyId, WorkflowConstants.STATUS_APPROVED, max,
                type, version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
        String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                + "/message_boards/find_recent_posts?p_l_id=" + plid;

        if (userId > 0) {
            rss = MBMessageServiceUtil.getGroupMessagesRSS(groupId, userId, WorkflowConstants.STATUS_APPROVED,
                    max, type, version, displayStyle, feedURL, entryURL, themeDisplay);
        } else {/* w  ww  .  j av a  2  s . c  o m*/
            rss = MBMessageServiceUtil.getGroupMessagesRSS(groupId, WorkflowConstants.STATUS_APPROVED, max,
                    type, version, displayStyle, feedURL, entryURL, themeDisplay);
        }
    } else if (categoryId > 0) {
        String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                + "/message_boards/find_category?p_l_id=" + plid + "&mbCategoryId=" + categoryId;

        rss = MBMessageServiceUtil.getCategoryMessagesRSS(groupId, categoryId,
                WorkflowConstants.STATUS_APPROVED, max, type, version, displayStyle, feedURL, entryURL,
                themeDisplay);
    } else if (threadId > 0) {
        String feedURL = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
                + "/message_boards/find_thread?p_l_id=" + plid + "&threadId=" + threadId;

        rss = MBMessageServiceUtil.getThreadMessagesRSS(threadId, WorkflowConstants.STATUS_APPROVED, max, type,
                version, displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.portlet.PortletBagFactory.java

License:Open Source License

protected void initResourceBundle(Map<String, ResourceBundle> resourceBundles, Portlet portlet, Locale locale) {

    try {//from w w w . j  a v  a  2  s . c  o  m
        InputStream inputStream = getResourceBundleInputStream(portlet.getResourceBundle(), locale);

        if (inputStream != null) {
            ResourceBundle parentResourceBundle = null;

            if (locale != null) {
                parentResourceBundle = resourceBundles.get(null);
            }

            ResourceBundle resourceBundle = new LiferayResourceBundle(parentResourceBundle, inputStream,
                    StringPool.UTF8);

            String languageId = null;

            if (locale != null) {
                languageId = LocaleUtil.toLanguageId(locale);
            }

            resourceBundles.put(languageId, resourceBundle);
        }
    } catch (Exception e) {
        _log.warn(e.getMessage());
    }
}

From source file:com.liferay.portlet.softwarecatalog.service.impl.SCProductEntryLocalServiceImpl.java

License:Open Source License

public String getRepositoryXML(long groupId, String version, String baseImageURL, Date oldestDate,
        int maxNumOfVersions, Properties repoSettings) throws SystemException {

    Document doc = SAXReaderUtil.createDocument();

    doc.setXMLEncoding(StringPool.UTF8);

    Element root = doc.addElement("plugin-repository");

    Element settingsEl = root.addElement("settings");

    populateSettingsElement(settingsEl, repoSettings);

    List<SCProductEntry> productEntries = scProductEntryPersistence.findByGroupId(groupId);

    for (SCProductEntry productEntry : productEntries) {
        if (Validator.isNull(productEntry.getRepoGroupId())
                || Validator.isNull(productEntry.getRepoArtifactId())) {

            continue;
        }//from w w w  .  ja  v  a  2s  .  co  m

        List<SCProductVersion> productVersions = scProductVersionPersistence
                .findByProductEntryId(productEntry.getProductEntryId());

        for (int i = 0; i < productVersions.size(); i++) {
            SCProductVersion productVersion = productVersions.get(i);

            if ((maxNumOfVersions > 0) && (maxNumOfVersions < (i + 1))) {
                break;
            }

            if (!productVersion.isRepoStoreArtifact()) {
                continue;
            }

            if ((oldestDate != null) && (oldestDate.after(productVersion.getModifiedDate()))) {

                continue;
            }

            if (Validator.isNotNull(version)
                    && !isVersionSupported(version, productVersion.getFrameworkVersions())) {

                continue;
            }

            Element el = root.addElement("plugin-package");

            populatePluginPackageElement(el, productEntry, productVersion, baseImageURL);
        }
    }

    return doc.asXML();
}

From source file:com.liferay.portlet.translator.model.Translation.java

License:Open Source License

public void setFromText(String fromText) {
    try {//from   www . j  ava2 s  .c o  m
        _fromText = new String(fromText.getBytes(), StringPool.UTF8);
    } catch (UnsupportedEncodingException uee) {
    }
}

From source file:com.liferay.portlet.translator.model.Translation.java

License:Open Source License

public void setToText(String toText) {
    try {//from   ww w  .  ja v a  2 s  .  c o  m
        _toText = new String(toText.getBytes(), StringPool.UTF8);
    } catch (UnsupportedEncodingException uee) {
    }
}

From source file:com.liferay.portlet.wiki.action.ExportPageAction.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 = WikiPageServiceUtil.getPage(nodeId, title, version);

    String content = page.getContent();

    String attachmentURLPrefix = themeDisplay.getPathMain() + "/wiki/get_page_attachment?" + "p_l_id="
            + themeDisplay.getPlid() + "&nodeId=" + nodeId + "&title=" + HttpUtil.encodeURL(title)
            + "&fileName=";

    try {/*  w  ww  .  j a v a 2s  . co m*/
        content = WikiUtil.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.portlet.wiki.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 companyId = ParamUtil.getLong(request, "companyId");
    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.TYPE_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle = ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);

    PortletURL feedURL = new PortletURLImpl(request, PortletKeys.WIKI, layout.getPlid(),
            PortletRequest.RENDER_PHASE);

    feedURL.setParameter("nodeId", String.valueOf(nodeId));

    PortletURL entryURL = new PortletURLImpl(request, PortletKeys.WIKI, layout.getPlid(),
            PortletRequest.RENDER_PHASE);

    entryURL.setParameter("nodeId", String.valueOf(nodeId));
    entryURL.setParameter("title", title);

    Locale locale = themeDisplay.getLocale();

    String rss = StringPool.BLANK;

    if ((nodeId > 0) && (Validator.isNotNull(title))) {
        rss = WikiPageServiceUtil.getPagesRSS(companyId, nodeId, title, max, type, version, displayStyle,
                feedURL.toString(), entryURL.toString(), locale);
    } else if (nodeId > 0) {
        rss = WikiPageServiceUtil.getNodePagesRSS(nodeId, max, type, version, displayStyle, feedURL.toString(),
                entryURL.toString());/* w ww  .  j  a  va  2 s. c  o  m*/
    }

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.rtl.servlet.filters.ComboServletFilter.java

License:Open Source License

protected byte[] getResourceContent(HttpServletRequest request, HttpServletResponse response, URL resourceURL,
        String resourcePath, String minifierType) throws IOException {

    String fileContentKey = resourcePath.concat(StringPool.QUESTION).concat(minifierType);

    FileContentBag fileContentBag = _fileContentBagPortalCache.get(fileContentKey);

    if ((fileContentBag != null) && !PropsValues.COMBO_CHECK_TIMESTAMP) {
        return fileContentBag._fileContent;
    }//from  w  w w  .j  a v a 2s .  co m

    URLConnection urlConnection = null;

    if (resourceURL != null) {
        urlConnection = resourceURL.openConnection();
    }

    if ((fileContentBag != null) && PropsValues.COMBO_CHECK_TIMESTAMP) {
        long elapsedTime = System.currentTimeMillis() - fileContentBag._lastModified;

        if ((urlConnection != null) && (elapsedTime <= PropsValues.COMBO_CHECK_TIMESTAMP_INTERVAL)
                && (urlConnection.getLastModified() == fileContentBag._lastModified)) {

            return fileContentBag._fileContent;
        }

        _fileContentBagPortalCache.remove(fileContentKey);
    }

    if (resourceURL == null) {
        fileContentBag = _EMPTY_FILE_CONTENT_BAG;
    } else {
        String stringFileContent = StringUtil.read(urlConnection.getInputStream());

        if (!StringUtil.endsWith(resourcePath, _CSS_MINIFIED_SUFFIX)
                && !StringUtil.endsWith(resourcePath, _JAVASCRIPT_MINIFIED_SUFFIX)) {

            if (minifierType.equals("css")) {
                try {
                    stringFileContent = DynamicCSSUtil.parseSass(_servletContext, request, resourcePath,
                            stringFileContent);
                } catch (Exception e) {
                    _log.error("Unable to parse SASS on CSS " + resourceURL.getPath(), e);

                    if (_log.isDebugEnabled()) {
                        _log.debug(stringFileContent);
                    }

                    response.setHeader(HttpHeaders.CACHE_CONTROL, HttpHeaders.CACHE_CONTROL_NO_CACHE_VALUE);
                }

                String baseURL = StringPool.BLANK;

                int index = resourcePath.lastIndexOf(CharPool.SLASH);

                if (index != -1) {
                    baseURL = resourcePath.substring(0, index + 1);
                }

                stringFileContent = AggregateUtil.updateRelativeURLs(stringFileContent, baseURL);

                stringFileContent = MinifierUtil.minifyCss(stringFileContent);
            } else if (minifierType.equals("js")) {
                stringFileContent = MinifierUtil.minifyJavaScript(stringFileContent);
            }
        }

        fileContentBag = new FileContentBag(stringFileContent.getBytes(StringPool.UTF8),
                urlConnection.getLastModified());
    }

    if (PropsValues.COMBO_CHECK_TIMESTAMP) {
        int timeToLive = (int) (PropsValues.COMBO_CHECK_TIMESTAMP_INTERVAL / Time.SECOND);

        _fileContentBagPortalCache.put(fileContentKey, fileContentBag, timeToLive);
    }

    return fileContentBag._fileContent;
}

From source file:com.liferay.rtl.servlet.filters.dynamiccss.DynamicCSSUtil.java

License:Open Source License

private static Theme _getTheme(HttpServletRequest request) throws Exception {

    long companyId = PortalUtil.getCompanyId(request);

    String themeId = ParamUtil.getString(request, "themeId");

    if (Validator.isNotNull(themeId)) {
        try {//w ww  . j  av  a 2 s  .  c om
            Theme theme = ThemeLocalServiceUtil.getTheme(companyId, themeId, false);

            return theme;
        } catch (Exception e) {
            _log.error(e, e);
        }
    }

    String requestURI = URLDecoder.decode(request.getRequestURI(), StringPool.UTF8);

    Matcher portalThemeMatcher = _portalThemePattern.matcher(requestURI);

    if (portalThemeMatcher.find()) {
        String themePathId = portalThemeMatcher.group(1);

        themePathId = StringUtil.replace(themePathId, StringPool.UNDERLINE, StringPool.BLANK);

        themeId = PortalUtil.getJsSafePortletId(themePathId);
    } else {
        Matcher pluginThemeMatcher = _pluginThemePattern.matcher(requestURI);

        if (pluginThemeMatcher.find()) {
            String themePathId = pluginThemeMatcher.group(1);

            themePathId = StringUtil.replace(themePathId, StringPool.UNDERLINE, StringPool.BLANK);

            StringBundler sb = new StringBundler(4);

            sb.append(themePathId);
            sb.append(PortletConstants.WAR_SEPARATOR);
            sb.append(themePathId);
            sb.append("theme");

            themePathId = sb.toString();

            themeId = PortalUtil.getJsSafePortletId(themePathId);
        }
    }

    if (Validator.isNull(themeId)) {
        return null;
    }

    try {
        Theme theme = ThemeLocalServiceUtil.getTheme(companyId, themeId, false);

        return theme;
    } catch (Exception e) {
        _log.error(e, e);
    }

    return null;
}