@Override
  public String getSearchSummary(Locale locale) {
    if (_message.isFormatBBCode()) {
      return HtmlUtil.extractText(BBCodeTranslatorUtil.getHTML(_message.getBody()));
    }

    return getSummary(null, null);
  }
  protected String extractContent(JournalArticle article, String languageId) {
    String content = article.getContentByLocale(languageId);

    if (Validator.isNotNull(article.getStructureId())) {
      content = extractDynamicContent(content);
    } else {
      content = extractStaticContent(content);
    }

    content = HtmlUtil.extractText(content);

    return content;
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    KBArticle kbArticle = (KBArticle) obj;

    Document document = getBaseModelDocument(PORTLET_ID, kbArticle);

    document.addText(Field.CONTENT, HtmlUtil.extractText(kbArticle.getContent()));
    document.addText(Field.DESCRIPTION, kbArticle.getDescription());
    document.addText(Field.TITLE, kbArticle.getTitle());

    document.addKeyword("titleKeyword", kbArticle.getTitle(), true);

    return document;
  }
Example #4
0
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    BlogsEntry entry = (BlogsEntry) obj;

    Document document = getBaseModelDocument(CLASS_NAME, entry);

    document.addText(Field.CONTENT, HtmlUtil.extractText(entry.getContent()));
    document.addText(Field.SUBTITLE, entry.getSubtitle());
    document.addText(Field.DESCRIPTION, entry.getDescription());
    document.addDate(Field.MODIFIED_DATE, entry.getModifiedDate());
    document.addText(Field.TITLE, entry.getTitle());

    return document;
  }
  protected String getDDMContentSummary(
      Document document,
      Locale snippetLocale,
      PortletRequest portletRequest,
      PortletResponse portletResponse) {

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
      return content;
    }

    try {
      String articleId = document.get(Field.ARTICLE_ID);
      long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
      double version = GetterUtil.getDouble(document.get(Field.VERSION));
      PortletRequestModel portletRequestModel =
          new PortletRequestModel(portletRequest, portletResponse);
      ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      JournalArticleDisplay articleDisplay =
          _journalContent.getDisplay(
              groupId,
              articleId,
              version,
              null,
              Constants.VIEW,
              LocaleUtil.toLanguageId(snippetLocale),
              1,
              portletRequestModel,
              themeDisplay);

      content = articleDisplay.getDescription();

      content = HtmlUtil.replaceNewLine(content);

      if (Validator.isNull(content)) {
        content = HtmlUtil.extractText(articleDisplay.getContent());
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }
    }

    return content;
  }
  @Override
  protected Document doGetDocument(Object obj) throws Exception {
    Message message = (Message) obj;

    Document document = getBaseModelDocument(PORTLET_ID, message);

    ExpandoBridge expandoBridge = message.getExpandoBridge();

    document.addText(Field.CONTENT, HtmlUtil.extractText(message.getBody()));
    document.addKeyword(Field.FOLDER_ID, message.getFolderId());
    document.addText(Field.TITLE, message.getSubject());

    document.addKeyword("accountId", message.getAccountId());
    document.addKeyword("remoteMessageId", message.getRemoteMessageId());

    ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

    return document;
  }
  protected String exportToRSS(
      ResourceRequest resourceRequest,
      ResourceResponse resourceResponse,
      String title,
      String description,
      String format,
      double version,
      String displayStyle,
      List<SocialActivity> socialActivities,
      ServiceContext serviceContext)
      throws Exception {

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

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(GetterUtil.getString(description, title));

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

    syndFeed.setEntries(syndEntries);

    for (SocialActivity socialActivity : socialActivities) {
      SocialActivityFeedEntry socialActivityFeedEntry =
          _socialActivityInterpreterLocalService.interpret(
              StringPool.BLANK, socialActivity, serviceContext);

      if (socialActivityFeedEntry == null) {
        continue;
      }

      SyndEntry syndEntry = new SyndEntryImpl();

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else {
        value = socialActivityFeedEntry.getBody();
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      if (Validator.isNotNull(socialActivityFeedEntry.getLink())) {
        syndEntry.setLink(socialActivityFeedEntry.getLink());
      }

      syndEntry.setPublishedDate(new Date(socialActivity.getCreateDate()));
      syndEntry.setTitle(HtmlUtil.extractText(socialActivityFeedEntry.getTitle()));
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

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

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

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) resourceResponse;

    ResourceURL rssURL = liferayPortletResponse.createResourceURL();

    rssURL.setParameter("feedTitle", title);
    rssURL.setResourceID("rss");

    selfSyndLink.setHref(rssURL.toString());

    selfSyndLink.setRel("self");

    SyndLink alternateSyndLink = new SyndLinkImpl();

    syndLinks.add(alternateSyndLink);

    alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay));
    alternateSyndLink.setRel("alternate");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(title);
    syndFeed.setUri(rssURL.toString());

    return RSSUtil.export(syndFeed);
  }
  protected String exportToRSS(
      String name,
      String description,
      String type,
      double version,
      String displayStyle,
      String feedURL,
      String entryURL,
      List<MBMessage> messages,
      ThemeDisplay themeDisplay)
      throws SystemException {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(description);

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

    syndFeed.setEntries(syndEntries);

    for (MBMessage message : messages) {
      SyndEntry syndEntry = new SyndEntryImpl();

      if (!message.isAnonymous()) {
        String author = PortalUtil.getUserName(message);

        syndEntry.setAuthor(author);
      }

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
        value =
            StringUtil.shorten(
                HtmlUtil.extractText(message.getBody()),
                PropsValues.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH,
                StringPool.BLANK);
      } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else if (message.isFormatBBCode()) {
        value = BBCodeTranslatorUtil.getHTML(message.getBody());

        value = MBUtil.replaceMessageBodyPaths(themeDisplay, value);
      } else {
        value = message.getBody();
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      syndEntry.setLink(entryURL + "&messageId=" + message.getMessageId());
      syndEntry.setPublishedDate(message.getCreateDate());
      syndEntry.setTitle(message.getSubject());
      syndEntry.setUpdatedDate(message.getModifiedDate());
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

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

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

    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);
    }
  }
Example #9
0
  protected void compareVersions(RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

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

    long nodeId = ParamUtil.getLong(renderRequest, "nodeId");

    String title = ParamUtil.getString(renderRequest, "title");

    double sourceVersion = ParamUtil.getDouble(renderRequest, "sourceVersion");
    double targetVersion = ParamUtil.getDouble(renderRequest, "targetVersion");
    String type = ParamUtil.getString(renderRequest, "type", "escape");

    WikiPage sourcePage = WikiPageServiceUtil.getPage(nodeId, title, sourceVersion);
    WikiPage targetPage = WikiPageServiceUtil.getPage(nodeId, title, targetVersion);

    if (type.equals("html")) {
      WikiNode sourceNode = sourcePage.getNode();

      PortletURL viewPageURL = renderResponse.createRenderURL();

      viewPageURL.setParameter("struts_action", "/wiki/view");
      viewPageURL.setParameter("nodeName", sourceNode.getName());

      PortletURL editPageURL = renderResponse.createRenderURL();

      editPageURL.setParameter("struts_action", "/wiki/edit_page");
      editPageURL.setParameter("nodeId", String.valueOf(nodeId));
      editPageURL.setParameter("title", title);

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

      String htmlDiffResult =
          WikiUtil.diffHtml(sourcePage, targetPage, viewPageURL, editPageURL, attachmentURLPrefix);

      renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult);
    } else {
      String sourceContent = sourcePage.getContent();
      String targetContent = targetPage.getContent();

      sourceContent = WikiUtil.processContent(sourceContent);
      targetContent = WikiUtil.processContent(targetContent);

      if (type.equals("strip")) {
        sourceContent = HtmlUtil.extractText(sourceContent);
        targetContent = HtmlUtil.extractText(targetContent);
      } else {
        sourceContent = HtmlUtil.escape(sourceContent);
        targetContent = HtmlUtil.escape(targetContent);
      }

      List<DiffResult>[] diffResults =
          DiffUtil.diff(
              new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent));

      renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
    }

    renderRequest.setAttribute(WebKeys.WIKI_NODE_ID, nodeId);
    renderRequest.setAttribute(WebKeys.TITLE, title);
    renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion);
  }
Example #10
0
 /** @deprecated As of 6.2.0 */
 protected String cleanContent(String content) {
   return StringUtil.shorten(HtmlUtil.extractText(content), 200);
 }
 @Override
 public String getSearchSummary(Locale locale) {
   return HtmlUtil.extractText(_workflowableComment.getTranslatedBody(StringPool.BLANK));
 }
  protected String exportToRSS(
      long companyId,
      String name,
      String description,
      String type,
      double version,
      String displayStyle,
      String feedURL,
      String entryURL,
      List<WikiPage> pages,
      boolean diff,
      Locale locale)
      throws SystemException {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));
    syndFeed.setTitle(name);
    syndFeed.setLink(feedURL);
    syndFeed.setDescription(description);

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

    syndFeed.setEntries(syndEntries);

    WikiPage latestPage = null;

    StringBundler link = new StringBundler(7);

    for (WikiPage page : pages) {
      String author = HtmlUtil.escape(PortalUtil.getUserName(page.getUserId(), page.getUserName()));

      String title = page.getTitle() + StringPool.SPACE + page.getVersion();

      if (page.isMinorEdit()) {
        title +=
            StringPool.SPACE
                + StringPool.OPEN_PARENTHESIS
                + LanguageUtil.get(locale, "minor-edit")
                + StringPool.CLOSE_PARENTHESIS;
      }

      link.setIndex(0);

      link.append(entryURL);
      link.append(StringPool.AMPERSAND);
      link.append(HttpUtil.encodeURL(page.getTitle()));

      SyndEntry syndEntry = new SyndEntryImpl();

      syndEntry.setAuthor(author);
      syndEntry.setTitle(title);
      syndEntry.setPublishedDate(page.getCreateDate());
      syndEntry.setUpdatedDate(page.getModifiedDate());

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      if (diff) {
        if (latestPage != null) {
          link.append(StringPool.QUESTION);
          link.append(PortalUtil.getPortletNamespace(PortletKeys.WIKI));
          link.append("version=");
          link.append(page.getVersion());

          String value = getPageDiff(companyId, latestPage, page, locale);

          syndContent.setValue(value);

          syndEntry.setDescription(syndContent);

          syndEntries.add(syndEntry);
        }
      } else {
        String value = null;

        if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
          value =
              StringUtil.shorten(
                  HtmlUtil.extractText(page.getContent()),
                  PropsValues.WIKI_RSS_ABSTRACT_LENGTH,
                  StringPool.BLANK);
        } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
          value = StringPool.BLANK;
        } else {
          value = page.getContent();
        }

        syndContent.setValue(value);

        syndEntry.setDescription(syndContent);

        syndEntries.add(syndEntry);
      }

      syndEntry.setLink(link.toString());
      syndEntry.setUri(syndEntry.getLink());

      latestPage = page;
    }

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