Example usage for com.liferay.portal.kernel.diff DiffHtmlUtil replaceStyles

List of usage examples for com.liferay.portal.kernel.diff DiffHtmlUtil replaceStyles

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.diff DiffHtmlUtil replaceStyles.

Prototype

public static String replaceStyles(String html) 

Source Link

Usage

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, JournalArticle article, String action,
        ServiceContext serviceContext) throws PortalException {

    String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(),
            PortletProvider.Action.EDIT);

    String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null);

    if (!article.isApproved() || Validator.isNull(articleURL)) {
        return;// w w w  .ja  va2  s  .com
    }

    JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration(
            article.getGroupId());

    String articleTitle = article.getTitle(serviceContext.getLanguageId());

    articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(),
            article.getArticleId());

    if (action.equals("add") && journalGroupServiceConfiguration.emailArticleAddedEnabled()) {
    } else if (action.equals("move_to")
            && journalGroupServiceConfiguration.emailArticleMovedToFolderEnabled()) {
    } else if (action.equals("move_from")
            && journalGroupServiceConfiguration.emailArticleMovedFromFolderEnabled()) {
    } else if (action.equals("update") && journalGroupServiceConfiguration.emailArticleUpdatedEnabled()) {
    } else {
        return;
    }

    String fromName = journalGroupServiceConfiguration.emailFromName();
    String fromAddress = journalGroupServiceConfiguration.emailFromAddress();

    Map<Locale, String> localizedSubjectMap = null;
    Map<Locale, String> localizedBodyMap = null;

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (action.equals("add")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleAddedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleAddedBody());
    } else if (action.equals("move_to")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_TO_FOLDER;
    } else if (action.equals("move_from")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderSubject());
        localizedBodyMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderBody());

        notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_FROM_FOLDER;
    } else if (action.equals("update")) {
        localizedSubjectMap = LocalizationUtil
                .getMap(journalGroupServiceConfiguration.emailArticleUpdatedSubject());
        localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleUpdatedBody());

        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    String articleContent = StringPool.BLANK;
    String articleDiffs = StringPool.BLANK;

    JournalArticle previousApprovedArticle = getPreviousApprovedArticle(article);

    try {
        PortletRequestModel portletRequestModel = new PortletRequestModel(
                serviceContext.getLiferayPortletRequest(), serviceContext.getLiferayPortletResponse());

        JournalArticleDisplay articleDisplay = getArticleDisplay(article, null, Constants.VIEW,
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), 1, portletRequestModel,
                serviceContext.getThemeDisplay());

        articleContent = articleDisplay.getContent();

        articleDiffs = JournalUtil.diffHtml(article.getGroupId(), article.getArticleId(),
                previousApprovedArticle.getVersion(), article.getVersion(),
                LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), portletRequestModel,
                serviceContext.getThemeDisplay());
    } catch (Exception e) {
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            JournalPermission.RESOURCE_NAME);

    subscriptionSender.setClassName(article.getModelClassName());
    subscriptionSender.setClassPK(article.getId());
    subscriptionSender.setCompanyId(article.getCompanyId());
    subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", articleContent, false);
    subscriptionSender.setContextAttribute("[$ARTICLE_DIFFS$]", DiffHtmlUtil.replaceStyles(articleDiffs),
            false);

    JournalFolder folder = article.getFolder();

    subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]",
            articleTitle, "[$ARTICLE_URL$]", articleURL, "[$ARTICLE_VERSION$]", article.getVersion(),
            "[$FOLDER_NAME$]", folder.getName());

    subscriptionSender.setContextCreatorUserPrefix("ARTICLE");
    subscriptionSender.setCreatorUserId(article.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(articleTitle);
    subscriptionSender.setEntryURL(articleURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(localizedBodyMap);
    subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap);
    subscriptionSender.setMailId("journal_article", article.getId());
    subscriptionSender.setNotificationType(notificationType);
    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(article.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), article.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), ancestorFolderId);
        }
    }

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(article.getGroupId(),
            classNameLocalService.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true);

    subscriptionSender.addPersistedSubscribers(DDMStructure.class.getName(), ddmStructure.getStructureId());

    subscriptionSender.addPersistedSubscribers(JournalArticle.class.getName(), article.getResourcePrimKey());

    subscriptionSender.flushNotificationsAsync();
}

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

License:Open Source License

protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext)
        throws PortalException {

    if (!page.isApproved() || Validator.isNull(pageURL)) {
        return;//from   ww w .j  a  v a  2  s  .co m
    }

    WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = _configurationProvider
            .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

    boolean update = false;

    if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) {
        update = true;
    }

    if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) {
    } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) {
    } else {
        return;
    }

    String portalURL = serviceContext.getPortalURL();

    WikiPage previousVersionPage = getPreviousVersionPage(page);

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(),
            serviceContext.getPlid(), page.getNodeId(), page.getTitle());

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageDiffs = StringPool.BLANK;

    try {
        pageDiffs = _wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix);
    } catch (Exception e) {
    }

    String pageContent = null;

    if (Objects.equals(page.getFormat(), "creole")) {
        pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);
    } else {
        pageContent = page.getContent();
        pageContent = WikiUtil.processContent(pageContent);
    }

    String pageTitle = page.getTitle();

    String fromName = wikiGroupServiceOverriddenConfiguration.emailFromName();
    String fromAddress = wikiGroupServiceOverriddenConfiguration.emailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (update) {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody();
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setClassName(page.getModelClassName());
    subscriptionSender.setClassPK(page.getPageId());
    subscriptionSender.setCompanyId(page.getCompanyId());
    subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false);
    subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false);

    WikiNode node = page.getNode();

    subscriptionSender.setContextAttributes("[$DIFFS_URL$]",
            getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(),
            "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]",
            page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL);

    subscriptionSender.setContextCreatorUserPrefix("PAGE");
    subscriptionSender.setCreatorUserId(page.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(pageTitle);
    subscriptionSender.setEntryURL(pageURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (update) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(WikiPortletKeys.WIKI);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(page.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(User.class.getName(), userId);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

protected void notifySubscribers(long userId, WikiPage page, String pageURL, ServiceContext serviceContext)
        throws PortalException {

    if (!page.isApproved() || Validator.isNull(pageURL)) {
        return;//from w ww.  j  a v a  2  s  . co m
    }

    WikiGroupServiceOverriddenConfiguration wikiGroupServiceOverriddenConfiguration = configurationProvider
            .getConfiguration(WikiGroupServiceOverriddenConfiguration.class,
                    new GroupServiceSettingsLocator(page.getGroupId(), WikiConstants.SERVICE_NAME));

    boolean update = false;

    if (page.getVersion() > WikiPageConstants.VERSION_DEFAULT) {
        update = true;
    }

    if (!update && wikiGroupServiceOverriddenConfiguration.emailPageAddedEnabled()) {
    } else if (update && wikiGroupServiceOverriddenConfiguration.emailPageUpdatedEnabled()) {
    } else {
        return;
    }

    String portalURL = serviceContext.getPortalURL();

    WikiPage previousVersionPage = getPreviousVersionPage(page);

    String attachmentURLPrefix = WikiUtil.getAttachmentURLPrefix(serviceContext.getPathMain(),
            serviceContext.getPlid(), page.getNodeId(), page.getTitle());

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageDiffs = StringPool.BLANK;

    try {
        pageDiffs = wikiEngineRenderer.diffHtml(previousVersionPage, page, null, null, attachmentURLPrefix);
    } catch (Exception e) {
    }

    String pageContent = null;

    if (Objects.equals(page.getFormat(), "creole")) {
        pageContent = wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);
    } else {
        pageContent = page.getContent();
        pageContent = WikiUtil.processContent(pageContent);
    }

    String pageTitle = page.getTitle();

    String fromName = wikiGroupServiceOverriddenConfiguration.emailFromName();
    String fromAddress = wikiGroupServiceOverriddenConfiguration.emailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (update) {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageUpdatedBody();
    } else {
        subjectLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedSubject();
        bodyLocalizedValuesMap = wikiGroupServiceOverriddenConfiguration.emailPageAddedBody();
    }

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setClassName(page.getModelClassName());
    subscriptionSender.setClassPK(page.getPageId());
    subscriptionSender.setCompanyId(page.getCompanyId());
    subscriptionSender.setContextAttribute("[$PAGE_CONTENT$]", pageContent, false);
    subscriptionSender.setContextAttribute("[$PAGE_DIFFS$]", DiffHtmlUtil.replaceStyles(pageDiffs), false);

    WikiNode node = page.getNode();

    subscriptionSender.setContextAttributes("[$DIFFS_URL$]",
            getDiffsURL(page, previousVersionPage, serviceContext), "[$NODE_NAME$]", node.getName(),
            "[$PAGE_DATE_UPDATE$]", page.getModifiedDate(), "[$PAGE_ID$]", page.getPageId(), "[$PAGE_SUMMARY$]",
            page.getSummary(), "[$PAGE_TITLE$]", pageTitle, "[$PAGE_URL$]", pageURL);

    subscriptionSender.setContextCreatorUserPrefix("PAGE");
    subscriptionSender.setCreatorUserId(page.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(pageTitle);
    subscriptionSender.setEntryURL(pageURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    if (bodyLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    }

    if (subjectLocalizedValuesMap != null) {
        subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    }

    subscriptionSender.setMailId("wiki_page", page.getNodeId(), page.getPageId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (update) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    subscriptionSender.setPortletId(WikiPortletKeys.WIKI);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(page.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(WikiNode.class.getName(), page.getNodeId());

    subscriptionSender.addPersistedSubscribers(WikiPage.class.getName(), page.getResourcePrimKey());

    subscriptionSender.flushNotificationsAsync();
}