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.document.library.web.internal.portlet.action.CompareVersionsMVCRenderCommand.java

License:Open Source License

protected void compareVersions(RenderRequest renderRequest) throws Exception {

    long sourceFileVersionId = ParamUtil.getLong(renderRequest, "sourceFileVersionId");
    long targetFileVersionId = ParamUtil.getLong(renderRequest, "targetFileVersionId");

    FileVersion sourceFileVersion = _dlAppService.getFileVersion(sourceFileVersionId);

    InputStream sourceIs = sourceFileVersion.getContentStream(false);

    String sourceExtension = sourceFileVersion.getExtension();

    if (sourceExtension.equals("css") || sourceExtension.equals("htm") || sourceExtension.equals("html")
            || sourceExtension.equals("js") || sourceExtension.equals("txt") || sourceExtension.equals("xml")) {

        String sourceContent = HtmlUtil.escape(StringUtil.read(sourceIs));

        sourceIs = new UnsyncByteArrayInputStream(sourceContent.getBytes(StringPool.UTF8));
    }//from   w w w .ja v  a 2s . c  o m

    FileVersion targetFileVersion = _dlAppLocalService.getFileVersion(targetFileVersionId);

    InputStream targetIs = targetFileVersion.getContentStream(false);

    String targetExtension = targetFileVersion.getExtension();

    if (targetExtension.equals("css") || targetExtension.equals("htm") || targetExtension.equals("html")
            || targetExtension.equals("js") || targetExtension.equals("txt") || targetExtension.equals("xml")) {

        String targetContent = HtmlUtil.escape(StringUtil.read(targetIs));

        targetIs = new UnsyncByteArrayInputStream(targetContent.getBytes(StringPool.UTF8));
    }

    if (DocumentConversionUtil.isEnabled()) {
        if (DocumentConversionUtil.isConvertBeforeCompare(sourceExtension)) {

            String sourceTempFileId = DLUtil.getTempFileId(sourceFileVersion.getFileEntryId(),
                    sourceFileVersion.getVersion());

            sourceIs = new FileInputStream(
                    DocumentConversionUtil.convert(sourceTempFileId, sourceIs, sourceExtension, "txt"));
        }

        if (DocumentConversionUtil.isConvertBeforeCompare(targetExtension)) {

            String targetTempFileId = DLUtil.getTempFileId(targetFileVersion.getFileEntryId(),
                    targetFileVersion.getVersion());

            targetIs = new FileInputStream(
                    DocumentConversionUtil.convert(targetTempFileId, targetIs, targetExtension, "txt"));
        }
    }

    List<DiffResult>[] diffResults = DiffUtil.diff(new InputStreamReader(sourceIs),
            new InputStreamReader(targetIs));

    renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);

    renderRequest.setAttribute(WebKeys.SOURCE_NAME,
            sourceFileVersion.getTitle() + StringPool.SPACE + sourceFileVersion.getVersion());
    renderRequest.setAttribute(WebKeys.TARGET_NAME,
            targetFileVersion.getTitle() + StringPool.SPACE + targetFileVersion.getVersion());
}

From source file:com.liferay.frontend.css.rtl.servlet.internal.RTLServlet.java

License:Open Source License

protected URL getResourceURL(HttpServletRequest request) throws IOException {

    String path = URLDecoder.decode(RequestDispatcherUtil.getEffectivePath(request), StringPool.UTF8);

    URL url = _servletContextHelper.getResource(path);

    if (url == null) {
        return null;
    }//from  ww  w.j  a v  a 2  s.c  o m

    String languageId = request.getParameter("languageId");

    if ((languageId == null) || !PortalUtil.isRightToLeft(request)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Skip because specified language " + languageId + " is not right to left");
        }

        return url;
    }

    String rtlPath = FileUtil.appendSuffix(path, "_rtl");

    URL rtlURL = _servletContextHelper.getResource(rtlPath);

    if (rtlURL != null) {
        return rtlURL;
    }

    File dataFile = _bundle.getDataFile(rtlPath);

    if (dataFile.exists() && (dataFile.lastModified() > url.openConnection().getLastModified())) {

        URI uri = dataFile.toURI();

        return uri.toURL();
    }

    CSSRTLConverter cssRTLConverter = new CSSRTLConverter(false);

    String rtl = cssRTLConverter.process(StringUtil.read(url.openStream()));

    InputStream inputStream = new ByteArrayInputStream(rtl.getBytes(StringPool.UTF8));

    OutputStream outputStream = null;

    try {
        dataFile.getParentFile().mkdirs();

        dataFile.createNewFile();

        outputStream = new FileOutputStream(dataFile);

        StreamUtil.transfer(inputStream, outputStream, false);
    } catch (IOException ioe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to cache RTL CSS", ioe);
        }
    } finally {
        if (outputStream != null) {
            outputStream.close();
        }
    }

    inputStream.reset();

    URI uri = dataFile.toURI();

    return uri.toURL();
}

From source file:com.liferay.google.apps.connector.GHelperUtil.java

License:Open Source License

public static void submitAdd(GAuthenticator gAuthenticator, String url, Document document)
        throws GoogleAppsException {

    try {/*from   www . ja  v  a  2  s.  co m*/
        String body = document.formattedString();

        if (_log.isInfoEnabled()) {
            _log.info("submitAdd request url " + url);
            _log.info("submitAdd request body " + body);
        }

        Http.Options options = _getOptions(gAuthenticator);

        options.setBody(body, ContentTypes.APPLICATION_ATOM_XML, StringPool.UTF8);
        options.setLocation(url);
        options.setPost(true);

        String response = HttpUtil.URLtoString(options);

        if (_log.isInfoEnabled()) {
            _log.info("submitAdd response " + response);
        }
    } catch (IOException ioe) {
        throw new GoogleAppsException(ioe);
    }
}

From source file:com.liferay.google.apps.connector.GHelperUtil.java

License:Open Source License

public static void submitUpdate(GAuthenticator gAuthenticator, String url, Document document)
        throws GoogleAppsException {

    try {// w w w . ja  v a 2  s .c o m
        String body = document.formattedString();

        if (_log.isInfoEnabled()) {
            _log.info("submitUpdate request url " + url);
            _log.info("submitUpdate request body " + body);
        }

        Http.Options options = _getOptions(gAuthenticator);

        options.setBody(body, ContentTypes.APPLICATION_ATOM_XML, StringPool.UTF8);
        options.setLocation(url);
        options.setPut(true);

        String response = HttpUtil.URLtoString(options);

        if (_log.isInfoEnabled()) {
            _log.info("submitUpdate response " + response);
        }
    } catch (IOException ioe) {
        throw new GoogleAppsException(ioe);
    }
}

From source file:com.liferay.httpservice.internal.servlet.BundleRequestDispatcher.java

License:Open Source License

public BundleRequestDispatcher(String servletMapping, boolean extensionMapping, String requestURI,
        BundleServletContext bundleServletContext, BundleFilterChain bundleFilterChain) {

    _servletMapping = servletMapping;/*from   w  w w .  ja va  2 s .  c  o  m*/
    _extensionMapping = extensionMapping;
    _requestURI = StringUtil.replace(requestURI, StringPool.DOUBLE_SLASH, StringPool.SLASH);
    _bundleServletContext = bundleServletContext;
    _bundleFilterChain = bundleFilterChain;

    if (!_extensionMapping) {
        _servletPath = _servletMapping;
    } else {
        _servletPath = _requestURI;
    }

    if ((_servletPath != null) && _requestURI.startsWith(_servletPath)
            && (_requestURI.length() > _servletPath.length())) {

        _pathInfo = _requestURI.substring(_servletPath.length());

        try {
            _pathInfo = URLDecoder.decode(_pathInfo, StringPool.UTF8);
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException(uee);
        }
    }
}

From source file:com.liferay.httpservice.servlet.ResourceServlet.java

License:Open Source License

protected String getRequestURI(HttpServletRequest request) throws UnsupportedEncodingException {

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

    String contextPath = request.getContextPath();

    if (!contextPath.equals(StringPool.SLASH)) {
        requestURI = requestURI.substring(contextPath.length());
    }/*from w  w  w .  j ava  2s  . c om*/

    return requestURI;
}

From source file:com.liferay.journal.web.util.ExportArticleUtil.java

License:Open Source License

public void sendFile(String targetExtension, PortletRequest portletRequest, PortletResponse portletResponse)
        throws IOException {

    if (Validator.isNull(targetExtension)) {
        return;//from ww w. j  av  a  2 s  . c o  m
    }

    long groupId = ParamUtil.getLong(portletRequest, "groupId");
    String articleId = ParamUtil.getString(portletRequest, "articleId");

    String languageId = LanguageUtil.getLanguageId(portletRequest);
    PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    HttpServletRequest request = _portal.getHttpServletRequest(portletRequest);
    HttpServletResponse response = _portal.getHttpServletResponse(portletResponse);

    JournalArticleDisplay articleDisplay = _journalContent.getDisplay(groupId, articleId, null, "export",
            languageId, 1, portletRequestModel, themeDisplay);

    int pages = articleDisplay.getNumberOfPages();

    StringBundler sb = new StringBundler(pages + 12);

    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(articleDisplay.getContent());

    for (int i = 2; i <= pages; i++) {
        articleDisplay = _journalContent.getDisplay(groupId, articleId, "export", languageId, i, themeDisplay);

        sb.append(articleDisplay.getContent());
    }

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

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

    String title = articleDisplay.getTitle();
    String sourceExtension = "html";

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

    String contentType = ContentTypes.TEXT_HTML;

    String id = DLUtil.getTempFileId(articleDisplay.getId(), String.valueOf(articleDisplay.getVersion()),
            languageId);

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

    if (convertedFile != null) {
        targetExtension = StringUtil.toLowerCase(targetExtension);

        fileName = title.concat(StringPool.PERIOD).concat(targetExtension);

        contentType = MimeTypesUtil.getContentType(fileName);

        is = new FileInputStream(convertedFile);
    }

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

From source file:com.liferay.journal.web.util.JournalRSSUtil.java

License:Open Source License

public byte[] getRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

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

    JournalFeed feed = null;/*from   w w w.  j  a  v a2  s  .  com*/

    long id = ParamUtil.getLong(resourceRequest, "id");

    if (id > 0) {
        try {
            feed = _journalFeedLocalService.getFeed(id);
        } catch (NoSuchFeedException nsfe) {

            // Backward compatibility with old URLs

            feed = _journalFeedLocalService.getFeed(themeDisplay.getScopeGroupId(), String.valueOf(id));
        }
    } else {
        long groupId = ParamUtil.getLong(resourceRequest, "groupId");
        String feedId = ParamUtil.getString(resourceRequest, "feedId");

        feed = _journalFeedLocalService.getFeed(groupId, feedId);
    }

    String languageId = LanguageUtil.getLanguageId(resourceRequest);

    long plid = _portal.getPlidFromFriendlyURL(themeDisplay.getCompanyId(), feed.getTargetLayoutFriendlyUrl());

    Layout layout = null;

    if (plid > 0) {
        layout = _layoutLocalService.fetchLayout(plid);
    }

    if (layout == null) {
        layout = themeDisplay.getLayout();
    }

    String rss = exportToRSS(resourceRequest, resourceResponse, feed, languageId, layout, themeDisplay);

    return rss.getBytes(StringPool.UTF8);
}

From source file:com.liferay.knowledgebase.portlet.BaseKBPortlet.java

License:Open Source License

public void serveKBArticleRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    if (!PortalUtil.isRSSFeedsEnabled()) {
        PortalUtil.sendRSSFeedsDisabledError(resourceRequest, resourceResponse);

        return;/*  www. j av a 2s.  co m*/
    }

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

    long resourcePrimKey = ParamUtil.getLong(resourceRequest, "resourcePrimKey");

    int rssDelta = ParamUtil.getInteger(resourceRequest, "rssDelta");
    String rssDisplayStyle = ParamUtil.getString(resourceRequest, "rssDisplayStyle");
    String rssFormat = ParamUtil.getString(resourceRequest, "rssFormat");

    String rss = KBArticleServiceUtil.getKBArticleRSS(resourcePrimKey, WorkflowConstants.STATUS_APPROVED,
            rssDelta, rssDisplayStyle, rssFormat, themeDisplay);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, null, rss.getBytes(StringPool.UTF8),
            ContentTypes.TEXT_XML_UTF8);
}

From source file:com.liferay.mail.util.PasswordUtil.java

License:Open Source License

public static String decrypt(String encryptedPassword) {
    String unencryptedPassword = null;

    try {//  w  w  w . j  av a 2s.co  m
        if (Validator.isNull(encryptedPassword)) {
            return StringPool.BLANK;
        }

        byte[] bytes = Base64.decode(encryptedPassword);

        unencryptedPassword = new String(bytes, StringPool.UTF8);
    } catch (UnsupportedEncodingException uee) {
        _log.error("Unable to decrypt the password", uee);
    }

    return unencryptedPassword;
}