Example usage for com.liferay.portal.util PropsValues BLOGS_RSS_ABSTRACT_LENGTH

List of usage examples for com.liferay.portal.util PropsValues BLOGS_RSS_ABSTRACT_LENGTH

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues BLOGS_RSS_ABSTRACT_LENGTH.

Prototype

int BLOGS_RSS_ABSTRACT_LENGTH

To view the source code for com.liferay.portal.util PropsValues BLOGS_RSS_ABSTRACT_LENGTH.

Click 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);//from ww  w . j av a2s. 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.portlet.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)
        throws SystemException {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
    syndFeed.setTitle(name);//from  www  .  j  a v a  2s .  c om
    syndFeed.setLink(feedURL);
    syndFeed.setDescription(description);

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

    syndFeed.setEntries(syndEntries);

    for (BlogsEntry entry : blogsEntries) {
        String author = HtmlUtil.escape(PortalUtil.getUserName(entry.getUserId(), entry.getUserName()));

        StringBundler link = new StringBundler(4);

        if (entryURL.endsWith("/blogs/rss")) {
            link.append(entryURL.substring(0, entryURL.length() - 3));
            link.append(entry.getUrlTitle());
        } else {
            link.append(entryURL);

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

            link.append("entryId=");
            link.append(entry.getEntryId());
        }

        String value = null;

        if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
            value = StringUtil.shorten(HtmlUtil.extractText(entry.getDescription()),
                    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() + "/" });
        }

        SyndEntry syndEntry = new SyndEntryImpl();

        syndEntry.setAuthor(author);
        syndEntry.setTitle(entry.getTitle());
        syndEntry.setLink(link.toString());
        syndEntry.setUri(syndEntry.getLink());
        syndEntry.setPublishedDate(entry.getCreateDate());
        syndEntry.setUpdatedDate(entry.getModifiedDate());

        SyndContent syndContent = new SyndContentImpl();

        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
        syndContent.setValue(value);

        syndEntry.setDescription(syndContent);

        syndEntries.add(syndEntry);
    }

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