Example usage for com.liferay.portal.kernel.theme ThemeDisplay getURLPortal

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getURLPortal

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getURLPortal.

Prototype

public String getURLPortal() 

Source Link

Usage

From source file:com.liferay.blogs.service.impl.BlogsEntryServiceImpl.java

License:Open Source License

protected String exportToRSS(String name, String description, String type, double version, String displayStyle,
        String feedURL, String entryURL, List<BlogsEntry> blogsEntries, ThemeDisplay themeDisplay) {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(description);

    List<SyndEntry> syndEntries = new ArrayList<>();

    syndFeed.setEntries(syndEntries);/* w  w  w.  ja va  2  s  . c o m*/

    for (BlogsEntry entry : blogsEntries) {
        SyndEntry syndEntry = new SyndEntryImpl();

        String author = PortalUtil.getUserName(entry);

        syndEntry.setAuthor(author);

        SyndContent syndContent = new SyndContentImpl();

        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

        String value = null;

        if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
            String summary = entry.getDescription();

            if (Validator.isNull(summary)) {
                summary = entry.getContent();
            }

            value = StringUtil.shorten(HtmlUtil.extractText(summary), PropsValues.BLOGS_RSS_ABSTRACT_LENGTH,
                    StringPool.BLANK);
        } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
            value = StringPool.BLANK;
        } else {
            value = StringUtil.replace(entry.getContent(), new String[] { "href=\"/", "src=\"/" },
                    new String[] { "href=\"" + themeDisplay.getURLPortal() + "/",
                            "src=\"" + themeDisplay.getURLPortal() + "/" });
        }

        syndContent.setValue(value);

        syndEntry.setDescription(syndContent);

        StringBundler sb = new StringBundler(4);

        sb.append(entryURL);

        if (!entryURL.endsWith(StringPool.QUESTION)) {
            sb.append(StringPool.AMPERSAND);
        }

        sb.append("entryId=");
        sb.append(entry.getEntryId());

        String link = sb.toString();

        syndEntry.setLink(link);

        syndEntry.setPublishedDate(entry.getDisplayDate());
        syndEntry.setTitle(entry.getTitle());
        syndEntry.setUpdatedDate(entry.getModifiedDate());
        syndEntry.setUri(link);

        syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));

    List<SyndLink> syndLinks = new ArrayList<>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    selfSyndLink.setHref(feedURL);
    selfSyndLink.setRel("self");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);

    try {
        return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
        throw new SystemException(fe);
    }
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId, ThemeDisplay themeDisplay)
        throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateUser();
    } else {/*w w w .j  a  v  a2  s .c o  m*/
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplay.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplay.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplay.getCDNHost());
    tokens.put("company_id", String.valueOf(themeDisplay.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplay.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplay.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplay.getPathMain());
    tokens.put("portal_ctx", themeDisplay.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplay.getURLPortal()));
    tokens.put("root_path", themeDisplay.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplay.getScopeGroupId()));
    tokens.put("site_group_id", String.valueOf(themeDisplay.getSiteGroupId()));
    tokens.put("theme_image_path", themeDisplay.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplay.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplay.getPathFriendlyURLPublic());
}

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

License:Open Source License

protected String processContent(JournalFeed feed, JournalArticle article, String languageId,
        ThemeDisplay themeDisplay, SyndEntry syndEntry, SyndContent syndContent) throws Exception {

    String content = article.getDescription(languageId);

    String contentField = feed.getContentField();

    if (contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)) {
        String ddmRendererTemplateKey = article.getDDMTemplateKey();

        if (Validator.isNotNull(feed.getDDMRendererTemplateKey())) {
            ddmRendererTemplateKey = feed.getDDMRendererTemplateKey();
        }/* w w w  . j  av a  2 s . c  o m*/

        JournalArticleDisplay articleDisplay = _journalContent.getDisplay(feed.getGroupId(),
                article.getArticleId(), ddmRendererTemplateKey, null, languageId, 1, new PortletRequestModel() {

                    @Override
                    public String toXML() {
                        return _XML_REQUUEST;
                    }

                }, themeDisplay);

        if (articleDisplay != null) {
            content = articleDisplay.getContent();
        }
    } else if (!contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)) {

        Document document = SAXReaderUtil.read(article.getContentByLocale(languageId));

        contentField = HtmlUtil.escapeXPathAttribute(contentField);

        XPath xPathSelector = SAXReaderUtil.createXPath("//dynamic-element[@name=" + contentField + "]");

        List<Node> results = xPathSelector.selectNodes(document);

        if (results.isEmpty()) {
            return content;
        }

        Element element = (Element) results.get(0);

        String elType = element.attributeValue("type");

        if (elType.equals("document_library")) {
            String url = element.elementText("dynamic-content");

            url = processURL(feed, url, themeDisplay, syndEntry);
        } else if (elType.equals("image") || elType.equals("image_gallery")) {
            String url = element.elementText("dynamic-content");

            url = processURL(feed, url, themeDisplay, syndEntry);

            content = content + "<br /><br /><img alt='' src='" + themeDisplay.getURLPortal() + url + "' />";
        } else if (elType.equals("text_box")) {
            syndContent.setType("text");

            content = element.elementText("dynamic-content");
        } else {
            content = element.elementText("dynamic-content");
        }
    }

    return content;
}

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

License:Open Source License

protected String processURL(JournalFeed feed, String url, ThemeDisplay themeDisplay, SyndEntry syndEntry) {

    url = StringUtil.replace(url, new String[] { "@group_id@", "@image_path@", "@main_path@" }, new String[] {
            String.valueOf(feed.getGroupId()), themeDisplay.getPathImage(), themeDisplay.getPathMain() });

    List<SyndEnclosure> syndEnclosures = getDLEnclosures(themeDisplay.getURLPortal(), url);

    syndEnclosures.addAll(getIGEnclosures(themeDisplay.getURLPortal(), url));

    syndEntry.setEnclosures(syndEnclosures);

    List<SyndLink> syndLinks = getDLLinks(themeDisplay.getURLPortal(), url);

    syndLinks.addAll(getIGLinks(themeDisplay.getURLPortal(), url));

    syndEntry.setLinks(syndLinks);//from  w w  w .j a v  a  2s .  com

    return url;
}