Example usage for com.liferay.portal.kernel.parsers.bbcode BBCodeTranslatorUtil getHTML

List of usage examples for com.liferay.portal.kernel.parsers.bbcode BBCodeTranslatorUtil getHTML

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.parsers.bbcode BBCodeTranslatorUtil getHTML.

Prototype

public static String getHTML(String bbcode) 

Source Link

Usage

From source file:com.gleo.groupphoto.web.portlet.action.ViewUserDetailsActionMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) {

    long userId = ParamUtil.getLong(renderRequest, "userId");
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String organizationsHTML = StringPool.BLANK;
    Contact contact = null;//  w ww. j  a va2  s. c om
    List<Organization> organizations = null;
    User user = null;
    Company company = null;
    Locale locale = themeDisplay.getLocale();

    String birthday = null;
    String jobTitle = null;
    String gender = null;
    String comments = null;

    // Get User
    if (userId > 0) {

        try {
            user = UserLocalServiceUtil.getUser(userId);
            company = CompanyLocalServiceUtil.getCompany(user.getCompanyId());

        } catch (PortalException e) {
            LOGGER.error(e);
        }

        if (user != null) {
            // Get Contact
            try {
                contact = user.getContact();

            } catch (PortalException e) {
                LOGGER.error(e);
            }

            // Get Organizations
            organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());
            StringBundler organizationsHTMLBundler = new StringBundler(organizations.size() * 2);

            if (!organizations.isEmpty()) {
                organizationsHTMLBundler.append(organizations.get(0).getName());
            }

            for (int i = 1; i < organizations.size(); i++) {
                organizationsHTMLBundler.append(", ");
                organizationsHTMLBundler.append(organizations.get(i).getName());
            }
            organizationsHTML = organizationsHTMLBundler.toString();

            // Fields
            setFields(renderRequest, contact, user, company, locale, birthday, gender, jobTitle);

            // Contact
            String className = Contact.class.getName();
            long classPK = contact.getContactId();

            List<Address> personalAddresses = Collections.emptyList();
            List<Address> organizationAddresses = new ArrayList<Address>();
            List<EmailAddress> emailAddresses = Collections.emptyList();
            List<Website> websites = Collections.emptyList();
            List<Phone> personalPhones = Collections.emptyList();
            List<Phone> organizationPhones = new ArrayList<Phone>();

            if (classPK > 0) {
                try {
                    personalAddresses = AddressServiceUtil.getAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    emailAddresses = EmailAddressServiceUtil.getEmailAddresses(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

                try {
                    websites = WebsiteServiceUtil.getWebsites(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }
                try {
                    personalPhones = PhoneServiceUtil.getPhones(className, classPK);
                } catch (PortalException pe) {
                    LOGGER.error(pe);
                }

            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationAddresses.addAll(AddressServiceUtil.getAddresses(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            for (int i = 0; i < organizations.size(); i++) {
                try {
                    organizationPhones.addAll(PhoneServiceUtil.getPhones(Organization.class.getName(),
                            organizations.get(i).getOrganizationId()));
                } catch (Exception e) {
                }
            }

            // Comments
            comments = user.getComments();

            LOGGER.info("comments" + comments);
            if (comments != null && !comments.trim().equals(StringPool.BLANK)) {
                comments = StringUtil.replace(BBCodeTranslatorUtil.getHTML(user.getComments()),
                        ThemeConstants.TOKEN_THEME_IMAGES_PATH + EMOTICONS,
                        themeDisplay.getPathThemeImages() + EMOTICONS);
            }

            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("personalAddresses", personalAddresses);
            renderRequest.setAttribute("emailAddresses", emailAddresses);
            renderRequest.setAttribute("organizationAddresses", organizationAddresses);
            renderRequest.setAttribute("websites", websites);
            renderRequest.setAttribute("personalPhones", personalPhones);
            renderRequest.setAttribute("organizationPhones", organizationPhones);

        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("userId =" + userId);
        LOGGER.debug("birthday =" + birthday);
        LOGGER.debug("gender =" + gender);
        LOGGER.debug("jobTitle =" + jobTitle);
        LOGGER.debug("comments =" + comments);
    }

    renderRequest.setAttribute("organizations", organizations);
    renderRequest.setAttribute("organizationsHTML", organizationsHTML);
    renderRequest.setAttribute("user2", user);
    renderRequest.setAttribute("contact", contact);
    renderRequest.setAttribute("languageUtil", LanguageUtil.getLanguage());
    renderRequest.setAttribute("locale", locale);
    renderRequest.setAttribute("comments", comments);
    renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml());

    return "/userdetails/jsp/user_details.jsp";
}

From source file:com.liferay.mentions.hook.service.impl.MentionsMessageServiceImpl.java

License:Open Source License

@Override
public MBMessage updateStatus(long userId, long messageId, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    MBMessage message = MBMessageLocalServiceUtil.getMessage(messageId);

    int oldStatus = message.getStatus();

    message = super.updateStatus(userId, messageId, status, serviceContext, workflowContext);

    if ((status != WorkflowConstants.STATUS_APPROVED) || (oldStatus == WorkflowConstants.STATUS_APPROVED)
            || (oldStatus == WorkflowConstants.STATUS_IN_TRASH)) {

        return message;
    }//from   w w  w  .  j av  a 2s  .  c  om

    long siteGroupId = PortalUtil.getSiteGroupId(message.getGroupId());

    if (!MentionsUtil.isMentionsEnabled(siteGroupId)) {
        return message;
    }

    MentionsNotifier mentionsNotifier = new MentionsNotifier();

    String content = message.getBody();

    if (message.isFormatBBCode()) {
        content = BBCodeTranslatorUtil.getHTML(content);
    }

    content = HtmlUtil.extractText(content);

    String subject = ContentUtil.get(PortletPropsValues.COMMENT_MENTION_EMAIL_SUBJECT);
    String body = ContentUtil.get(PortletPropsValues.COMMENT_MENTION_EMAIL_BODY);

    if (!message.isDiscussion()) {
        subject = ContentUtil.get(PortletPropsValues.ASSET_ENTRY_MENTION_EMAIL_SUBJECT);
        body = ContentUtil.get(PortletPropsValues.ASSET_ENTRY_MENTION_EMAIL_BODY);
    }

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    if (Validator.isNull(contentURL)) {
        serviceContext.setAttribute("contentURL", workflowContext.get("url"));
    }

    mentionsNotifier.notify(message.getUserId(), message.getGroupId(), content, message.getModelClassName(),
            message.getMessageId(), subject, body, serviceContext);

    return message;
}

From source file:com.liferay.mentions.internal.service.MentionsMessageServiceWrapper.java

License:Open Source License

@Override
public MBMessage updateStatus(long userId, long messageId, int status, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    MBMessage message = _mbMessageLocalService.getMessage(messageId);

    int oldStatus = message.getStatus();

    message = super.updateStatus(userId, messageId, status, serviceContext, workflowContext);

    if ((status != WorkflowConstants.STATUS_APPROVED) || (oldStatus == WorkflowConstants.STATUS_IN_TRASH)) {

        return message;
    }/*from  w  ww  .ja  v  a2s  . c o m*/

    long siteGroupId = _portal.getSiteGroupId(message.getGroupId());

    if (!MentionsUtil.isMentionsEnabled(siteGroupId)) {
        return message;
    }

    String content = message.getBody();

    if (message.isFormatBBCode()) {
        content = BBCodeTranslatorUtil.getHTML(content);
    }

    String title = message.getSubject();

    if (message.isDiscussion()) {
        title = StringUtil.shorten(HtmlUtil.extractText(content), 100);
    }

    MentionsGroupServiceConfiguration mentionsGroupServiceConfiguration = _configurationProvider
            .getCompanyConfiguration(MentionsGroupServiceConfiguration.class, message.getCompanyId());

    LocalizedValuesMap subjectLocalizedValuesMap = mentionsGroupServiceConfiguration
            .commentMentionEmailSubject();
    LocalizedValuesMap bodyLocalizedValuesMap = mentionsGroupServiceConfiguration.commentMentionEmailBody();

    if (!message.isDiscussion()) {
        subjectLocalizedValuesMap = mentionsGroupServiceConfiguration.assetEntryMentionEmailSubject();
        bodyLocalizedValuesMap = mentionsGroupServiceConfiguration.assetEntryMentionEmailBody();
    }

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    if (Validator.isNull(contentURL)) {
        serviceContext.setAttribute("contentURL", workflowContext.get("url"));
    }

    _mentionsNotifier.notify(userId, message.getGroupId(), title, content, message.getModelClassName(),
            message.getMessageId(), subjectLocalizedValuesMap, bodyLocalizedValuesMap, serviceContext);

    return message;
}

From source file:com.liferay.message.boards.internal.search.MBMessageIndexer.java

License:Open Source License

protected String processContent(MBMessage message) {
    String content = message.getBody();

    try {/*from w  ww. j  a va  2  s .c  o  m*/
        if (message.isFormatBBCode()) {
            content = BBCodeTranslatorUtil.getHTML(content);
        }
    } catch (Exception e) {
        _log.error(StringBundler.concat("Unable to parse message ", String.valueOf(message.getMessageId()),
                ": ", e.getMessage()), e);
    }

    content = HtmlUtil.extractText(content);

    return content;
}

From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, MBMessage message, String messageURL,
        ServiceContext serviceContext) throws PortalException {

    if (!message.isApproved() || Validator.isNull(messageURL)) {
        return;/*from  ww w  . j  av  a  2s .c o m*/
    }

    if (message.isDiscussion()) {
        try {
            notifyDiscussionSubscribers(userId, message, serviceContext);
        } catch (Exception e) {
            _log.error(e, e);
        }

        return;
    }

    MBGroupServiceSettings mbGroupServiceSettings = MBGroupServiceSettings.getInstance(message.getGroupId());

    if (serviceContext.isCommandAdd() && mbGroupServiceSettings.isEmailMessageAddedEnabled()) {
    } else if (serviceContext.isCommandUpdate() && mbGroupServiceSettings.isEmailMessageUpdatedEnabled()) {
    } else {
        return;
    }

    Company company = _companyLocalService.getCompany(message.getCompanyId());

    User user = _userLocalService.getUser(userId);

    String emailAddress = user.getEmailAddress();
    String fullName = user.getFullName();

    if (message.isAnonymous()) {
        emailAddress = StringPool.BLANK;
        fullName = serviceContext.translate("anonymous");
    }

    MBCategory category = message.getCategory();

    List<Long> categoryIds = new ArrayList<>();

    categoryIds.add(message.getCategoryId());

    if (message.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

        categoryIds.addAll(category.getAncestorCategoryIds());
    }

    String entryTitle = message.getSubject();

    String fromName = mbGroupServiceSettings.getEmailFromName();
    String fromAddress = mbGroupServiceSettings.getEmailFromAddress();

    String replyToAddress = StringPool.BLANK;

    if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
        replyToAddress = MBUtil.getReplyToAddress(message.getCategoryId(), message.getMessageId(),
                company.getMx(), fromAddress);
    }

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageUpdatedSubject();
        bodyLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageAddedSubject();
        bodyLocalizedValuesMap = mbGroupServiceSettings.getEmailMessageAddedBody();
    }

    boolean htmlFormat = mbGroupServiceSettings.isEmailHtmlFormat();

    String messageBody = message.getBody();

    if (htmlFormat && message.isFormatBBCode()) {
        try {
            messageBody = BBCodeTranslatorUtil.getHTML(messageBody);

            HttpServletRequest request = serviceContext.getRequest();

            if (request != null) {
                ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

                messageBody = MBUtil.replaceMessageBodyPaths(themeDisplay, messageBody);
            }
        } catch (Exception e) {
            _log.error(StringBundler.concat("Unable to parse message ", String.valueOf(message.getMessageId()),
                    ": ", e.getMessage()));
        }
    }

    String inReplyTo = null;
    String messageSubject = message.getSubject();
    String messageSubjectPrefix = StringPool.BLANK;

    if (message.getParentMessageId() != MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {

        MBMessage parentMessage = _mbMessageLocalService.getMessage(message.getParentMessageId());

        Date modifiedDate = parentMessage.getModifiedDate();

        inReplyTo = _portal.getMailId(company.getMx(), MBUtil.MESSAGE_POP_PORTLET_PREFIX,
                message.getCategoryId(), parentMessage.getMessageId(), modifiedDate.getTime());

        if (messageSubject.startsWith(MBMessageConstants.MESSAGE_SUBJECT_PREFIX_RE)) {

            messageSubjectPrefix = MBMessageConstants.MESSAGE_SUBJECT_PREFIX_RE;

            messageSubject = messageSubject.substring(messageSubjectPrefix.length());
        }
    }

    SubscriptionSender subscriptionSender = getSubscriptionSender(userId, category, message, messageURL,
            entryTitle, htmlFormat, messageBody, messageSubject, messageSubjectPrefix, inReplyTo, fromName,
            fromAddress, replyToAddress, emailAddress, fullName, subjectLocalizedValuesMap,
            bodyLocalizedValuesMap, serviceContext);

    subscriptionSender.addPersistedSubscribers(MBCategory.class.getName(), message.getGroupId());

    for (long categoryId : categoryIds) {
        if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
            subscriptionSender.addPersistedSubscribers(MBCategory.class.getName(), categoryId);
        }
    }

    subscriptionSender.addPersistedSubscribers(MBThread.class.getName(), message.getThreadId());

    subscriptionSender.flushNotificationsAsync();

    if (!MailingListThreadLocal.isSourceMailingList()) {
        for (long categoryId : categoryIds) {
            MBSubscriptionSender sourceMailingListSubscriptionSender = getSubscriptionSender(userId, category,
                    message, messageURL, entryTitle, htmlFormat, messageBody, messageSubject,
                    messageSubjectPrefix, inReplyTo, fromName, fromAddress, replyToAddress, emailAddress,
                    fullName, subjectLocalizedValuesMap, bodyLocalizedValuesMap, serviceContext);

            sourceMailingListSubscriptionSender.setBulk(false);

            sourceMailingListSubscriptionSender.addMailingListSubscriber(message.getGroupId(), categoryId);

            sourceMailingListSubscriptionSender.flushNotificationsAsync();
        }
    }
}

From source file:com.liferay.message.boards.web.internal.asset.MBMessageAssetRenderer.java

License:Open Source License

@Override
public String getSearchSummary(Locale locale) {
    if (_message.isFormatBBCode()) {
        return HtmlUtil.extractText(BBCodeTranslatorUtil.getHTML(_message.getBody()));
    }//w w w .  ja  va2s . c om

    return getSummary(null, null);
}

From source file:com.liferay.portlet.messageboards.model.impl.MBMessageImpl.java

License:Open Source License

public String getBody(boolean translate) {
    String body = null;/*from  w  w w .ja v a2s  .  co m*/

    if (translate) {
        body = BBCodeTranslatorUtil.getHTML(getBody());
    } else {
        body = getBody();
    }

    return body;
}

From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(MBMessage message, ServiceContext serviceContext)
        throws PortalException, SystemException {

    String layoutFullURL = serviceContext.getLayoutFullURL();

    if (!message.isApproved() || Validator.isNull(layoutFullURL)) {
        return;//from w  w  w  .j  a va2  s. c o  m
    }

    if (message.isDiscussion()) {
        try {
            notifyDiscussionSubscribers(message, serviceContext);
        } catch (Exception e) {
            _log.error(e, e);
        }

        return;
    }

    PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext);

    if (preferences == null) {
        long ownerId = message.getGroupId();
        int ownerType = PortletKeys.PREFS_OWNER_TYPE_GROUP;
        long plid = PortletKeys.PREFS_PLID_SHARED;
        String portletId = PortletKeys.MESSAGE_BOARDS;
        String defaultPreferences = null;

        preferences = portletPreferencesLocalService.getPreferences(message.getCompanyId(), ownerId, ownerType,
                plid, portletId, defaultPreferences);
    }

    boolean update = GetterUtil.getBoolean((String) serviceContext.getAttribute("update"));

    if (!update && MBUtil.getEmailMessageAddedEnabled(preferences)) {
    } else if (update && MBUtil.getEmailMessageUpdatedEnabled(preferences)) {
    } else {
        return;
    }

    Company company = companyPersistence.findByPrimaryKey(message.getCompanyId());

    Group group = groupPersistence.findByPrimaryKey(message.getGroupId());

    String emailAddress = PortalUtil.getUserEmailAddress(message.getUserId());
    String fullName = PortalUtil.getUserName(message.getUserId(), message.getUserName());

    if (message.isAnonymous()) {
        emailAddress = StringPool.BLANK;
        fullName = serviceContext.translate("anonymous");
    }

    MBCategory category = message.getCategory();

    String categoryName = category.getName();

    if (category.getCategoryId() == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {

        categoryName = serviceContext.translate("message-boards-home");

        categoryName += " - " + group.getDescriptiveName();
    }

    List<Long> categoryIds = new ArrayList<Long>();

    categoryIds.add(message.getCategoryId());

    if ((message.getCategoryId() != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID)
            && (message.getCategoryId() != MBCategoryConstants.DISCUSSION_CATEGORY_ID)) {

        categoryIds.addAll(category.getAncestorCategoryIds());
    }

    String messageURL = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "message_boards/view_message/"
            + message.getMessageId();

    String fromName = MBUtil.getEmailFromName(preferences, message.getCompanyId());
    String fromAddress = MBUtil.getEmailFromAddress(preferences, message.getCompanyId());

    String mailingListAddress = StringPool.BLANK;

    if (PropsValues.POP_SERVER_NOTIFICATIONS_ENABLED) {
        mailingListAddress = MBUtil.getMailingListAddress(message.getGroupId(), message.getCategoryId(),
                message.getMessageId(), company.getMx(), fromAddress);
    }

    String subjectPrefix = null;
    String body = null;
    String signature = null;

    if (update) {
        subjectPrefix = MBUtil.getEmailMessageUpdatedSubjectPrefix(preferences);
        body = MBUtil.getEmailMessageUpdatedBody(preferences);
        signature = MBUtil.getEmailMessageUpdatedSignature(preferences);
    } else {
        subjectPrefix = MBUtil.getEmailMessageAddedSubjectPrefix(preferences);
        body = MBUtil.getEmailMessageAddedBody(preferences);
        signature = MBUtil.getEmailMessageAddedSignature(preferences);
    }

    String subject = message.getSubject();

    if (!subjectPrefix.contains("[$MESSAGE_SUBJECT$]")) {
        subject = subjectPrefix.trim() + " " + subject.trim();
    }

    if (Validator.isNotNull(signature)) {
        body += "\n--\n" + signature;
    }

    String messageBody = message.getBody();

    boolean htmlFormat = MBUtil.getEmailHtmlFormat(preferences);

    if (htmlFormat) {
        try {
            messageBody = BBCodeTranslatorUtil.getHTML(messageBody);
        } catch (Exception e) {
            _log.error("Could not parse message " + message.getMessageId() + " " + e.getMessage());
        }
    }

    String inReplyTo = null;

    if (message.getParentMessageId() != MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID) {

        inReplyTo = PortalUtil.getMailId(company.getMx(), MBUtil.MESSAGE_POP_PORTLET_PREFIX,
                message.getCategoryId(), message.getParentMessageId());
    }

    SubscriptionSender subscriptionSenderPrototype = new MBSubscriptionSender();

    subscriptionSenderPrototype.setBody(body);
    subscriptionSenderPrototype.setBulk(true);
    subscriptionSenderPrototype.setCompanyId(message.getCompanyId());
    subscriptionSenderPrototype.setContextAttribute("[$MESSAGE_BODY$]", messageBody, false);
    subscriptionSenderPrototype.setContextAttributes("[$CATEGORY_NAME$]", categoryName,
            "[$MAILING_LIST_ADDRESS$]", mailingListAddress, "[$MESSAGE_ID$]", message.getMessageId(),
            "[$MESSAGE_SUBJECT$]", message.getSubject(), "[$MESSAGE_URL$]", messageURL,
            "[$MESSAGE_USER_ADDRESS$]", emailAddress, "[$MESSAGE_USER_NAME$]", fullName);
    subscriptionSenderPrototype.setFrom(fromAddress, fromName);
    subscriptionSenderPrototype.setHtmlFormat(htmlFormat);
    subscriptionSenderPrototype.setInReplyTo(inReplyTo);
    subscriptionSenderPrototype.setMailId(MBUtil.MESSAGE_POP_PORTLET_PREFIX, message.getCategoryId(),
            message.getMessageId());
    subscriptionSenderPrototype.setPortletId(PortletKeys.MESSAGE_BOARDS);
    subscriptionSenderPrototype.setReplyToAddress(mailingListAddress);
    subscriptionSenderPrototype.setScopeGroupId(message.getGroupId());
    subscriptionSenderPrototype.setServiceContext(serviceContext);
    subscriptionSenderPrototype.setSubject(message.getSubject());
    subscriptionSenderPrototype.setUserId(message.getUserId());

    SubscriptionSender subscriptionSender = (SubscriptionSender) SerializableUtil
            .clone(subscriptionSenderPrototype);

    for (long categoryId : categoryIds) {
        if (categoryId == MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
            categoryId = message.getGroupId();
        }

        subscriptionSender.addPersistedSubscribers(MBCategory.class.getName(), categoryId);
    }

    subscriptionSender.addPersistedSubscribers(MBThread.class.getName(), message.getThreadId());

    subscriptionSender.flushNotificationsAsync();

    if (!MailingListThreadLocal.isSourceMailingList()) {
        for (long categoryId : categoryIds) {
            MBSubscriptionSender sourceMailingListSubscriptionSender = (MBSubscriptionSender) SerializableUtil
                    .clone(subscriptionSenderPrototype);

            sourceMailingListSubscriptionSender.setBulk(false);

            sourceMailingListSubscriptionSender.addMailingListSubscriber(message.getGroupId(), categoryId);

            sourceMailingListSubscriptionSender.flushNotificationsAsync();
        }
    }
}

From source file:com.liferay.portlet.messageboards.service.impl.MBMessageServiceImpl.java

License:Open Source License

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.setFeedType(RSSUtil.getFeedType(type, version));
    syndFeed.setTitle(name);//from   w  w w. j  av  a  2 s . c om
    syndFeed.setLink(feedURL);
    syndFeed.setDescription(description);

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

    syndFeed.setEntries(syndEntries);

    Iterator<MBMessage> itr = messages.iterator();

    while (itr.hasNext()) {
        MBMessage message = itr.next();

        String author = HtmlUtil.escape(PortalUtil.getUserName(message.getUserId(), message.getUserName()));

        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 {
            value = BBCodeTranslatorUtil.getHTML(message.getBody());

            value = StringUtil.replace(value, new String[] { "@theme_images_path@", "href=\"/", "src=\"/" },
                    new String[] { themeDisplay.getURLPortal() + themeDisplay.getPathThemeImages(),
                            "href=\"" + themeDisplay.getURLPortal() + "/",
                            "src=\"" + themeDisplay.getURLPortal() + "/" });
        }

        SyndEntry syndEntry = new SyndEntryImpl();

        if (!message.isAnonymous()) {
            syndEntry.setAuthor(author);
        }

        syndEntry.setTitle(message.getSubject());
        syndEntry.setLink(entryURL + "&messageId=" + message.getMessageId());
        syndEntry.setUri(syndEntry.getLink());
        syndEntry.setPublishedDate(message.getCreateDate());
        syndEntry.setUpdatedDate(message.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);
    }
}

From source file:com.liferay.portlet.messageboards.util.MBIndexer.java

License:Open Source License

protected String processContent(MBMessage message) {
    String content = message.getBody();

    try {/*from  ww  w  .  j  av a  2  s. c o m*/
        content = BBCodeTranslatorUtil.getHTML(content);
    } catch (Exception e) {
        _log.error("Could not parse message " + message.getMessageId() + ": " + e.getMessage());
    }

    content = HtmlUtil.extractText(content);

    return content;
}