Example usage for com.liferay.portal.kernel.util HtmlUtil replaceNewLine

List of usage examples for com.liferay.portal.kernel.util HtmlUtil replaceNewLine

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util HtmlUtil replaceNewLine.

Prototype

public static String replaceNewLine(String html) 

Source Link

Document

Replaces all new lines or carriage returns with the
HTML tag.

Usage

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

License:Open Source License

protected void notifySubscribers(long userId, BlogsEntry entry, ServiceContext serviceContext,
        Map<String, Serializable> workflowContext) throws PortalException {

    String entryURL = (String) workflowContext.get(WorkflowConstants.CONTEXT_URL);

    if (!entry.isApproved() || Validator.isNull(entryURL)) {
        return;/*from  w  ww.  j av  a  2  s  .co m*/
    }

    BlogsGroupServiceSettings blogsGroupServiceSettings = BlogsGroupServiceSettings
            .getInstance(entry.getGroupId());

    boolean sendEmailEntryUpdated = GetterUtil.getBoolean(serviceContext.getAttribute("sendEmailEntryUpdated"));

    if (serviceContext.isCommandAdd() && blogsGroupServiceSettings.isEmailEntryAddedEnabled()) {
    } else if (sendEmailEntryUpdated && serviceContext.isCommandUpdate()
            && blogsGroupServiceSettings.isEmailEntryUpdatedEnabled()) {
    } else {
        return;
    }

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

    String entryTitle = entry.getTitle();

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

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (serviceContext.isCommandUpdate()) {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedSubject();
        bodyLocalizedValuesMap = blogsGroupServiceSettings.getEmailEntryAddedBody();
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            BlogsPermission.RESOURCE_NAME);

    subscriptionSender.setClassPK(entry.getEntryId());
    subscriptionSender.setClassName(entry.getModelClassName());
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttribute("[$BLOGS_ENTRY_CONTENT$]",
            StringUtil.shorten(HtmlUtil.stripHtml(entry.getContent()), 500), false);
    subscriptionSender.setContextAttributes("[$BLOGS_ENTRY_CREATE_DATE$]",
            Time.getSimpleDate(entry.getCreateDate(), "yyyy/MM/dd"), "[$BLOGS_ENTRY_DESCRIPTION$]",
            entry.getDescription(), "[$BLOGS_ENTRY_SITE_NAME$]",
            group.getDescriptiveName(serviceContext.getLocale()), "[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]",
            entry.getStatusByUserName(), "[$BLOGS_ENTRY_TITLE$]", entryTitle, "[$BLOGS_ENTRY_UPDATE_COMMENT$]",
            HtmlUtil.replaceNewLine(
                    GetterUtil.getString(serviceContext.getAttribute("emailEntryUpdatedComment"))),
            "[$BLOGS_ENTRY_URL$]", entryURL, "[$BLOGS_ENTRY_USER_PORTRAIT_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_PORTRAIT_URL), "[$BLOGS_ENTRY_USER_URL$]",
            workflowContext.get(WorkflowConstants.CONTEXT_USER_URL));
    subscriptionSender.setContextCreatorUserPrefix("BLOGS_ENTRY");
    subscriptionSender.setCreatorUserId(entry.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    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("blogs_entry", entry.getEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(),
            PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);
    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getGroupId());

    subscriptionSender.addPersistedSubscribers(BlogsEntry.class.getName(), entry.getEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.journal.search.JournalArticleIndexer.java

License:Open Source License

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

    String content = StringPool.BLANK;

    if ((portletRequest == null) || (portletResponse == null)) {
        return content;
    }/*from w  ww  .j  av a  2  s.c om*/

    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;
}

From source file:com.liferay.portlet.journal.util.JournalArticleIndexer.java

License:Open Source License

protected String getDDMContentSummary(Document document, Locale snippetLocale) {

    String content = StringPool.BLANK;

    try {//from  w  ww . j  a  va2s .  co  m
        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
        String articleId = document.get("articleId");
        double version = GetterUtil.getDouble(document.get(Field.VERSION));

        JournalArticle article = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId, version);

        if (article == null) {
            return content;
        }

        JournalArticleDisplay articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(article, null,
                Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, null, null);

        content = HtmlUtil.escape(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;
}

From source file:org.kisti.edison.content.service.impl.AdvancedContentLocalServiceImpl.java

License:Open Source License

public List<Map<String, Object>> getAdvancedContentListByGroupId(long groupId, User user, Locale locale,
        ThemeDisplay themeDisplay) throws Exception {

    List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
    Map<String, Object> resultRow = null;

    String updateAuth = "false";
    if (user != null) {
        if (EdisonUserUtil.isPowerUserThan(user)) {
            //  ? - edison ??  
            if (EdisonUserUtil.isRegularRole(user, RoleConstants.ADMINISTRATOR)) {
                updateAuth = "true";
            } else {
                // ?? ??
                if (EdisonUserUtil.isSiteRole(user, groupId, RoleConstants.SITE_ADMINISTRATOR)) {
                    updateAuth = "true";
                }/*from   w  w w. j av a 2 s.co m*/
            }
        }
    }

    List<AdvancedContent> advancedContentList = new ArrayList<AdvancedContent>();
    if (updateAuth.equals("true")) {
        advancedContentList = advancedContentPersistence.findByGroupId(groupId);
    } else if (updateAuth.equals("false")) {
        advancedContentList = advancedContentPersistence.findByGroupIdSeriveLang(groupId, locale.toString());
    }

    for (AdvancedContent aContent : advancedContentList) {
        resultRow = new HashMap<String, Object>();

        resultRow.put("updateAuth", updateAuth);

        long contentSeq = aContent.getContentSeq();
        String folderName = groupId + "_" + contentSeq;
        DLFolder edisonFolder = DLFolderLocalServiceUtil.getFolder(groupId,
                DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT,
                String.valueOf(groupId) + "_EDISON_FILE");
        DLFolder contentFolder = DLFolderLocalServiceUtil.getFolder(groupId, edisonFolder.getFolderId(),
                EdisonFileConstants.CONTENTS_ADVANCED);
        DLFolder dLFolder = DLFolderLocalServiceUtil.getFolder(groupId, contentFolder.getFolderId(),
                folderName);

        List<DLFileEntry> fileList = DLFileEntryLocalServiceUtil.getFileEntries(groupId,
                dLFolder.getFolderId());

        if (fileList == null) {
            resultRow.put("fileUrl", "");
        } else {
            DLFileEntry dLFileEntry = fileList.get(0);

            FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(dLFileEntry.getFileEntryId());
            String url = DLUtil.getPreviewURL(fileEntry, fileEntry.getFileVersion(), themeDisplay, "", false,
                    false);
            resultRow.put("fileUrl", url);
        }

        resultRow.put("serviceLanguage", String.valueOf(aContent.getServiceLanguage()));
        resultRow.put("contentSeq", String.valueOf(aContent.getContentSeq()));
        resultRow.put("groupId", String.valueOf(aContent.getGroupId()));
        resultRow.put("title", String.valueOf(aContent.getTitle()));
        resultRow.put("resume", HtmlUtil.replaceNewLine(String.valueOf(aContent.getResume())));
        resultRow.put("contentFilePath", aContent.getContentFilePath());
        resultRow.put("contentFileNm", aContent.getContentFileNm());

        String contentStartFileNm = "";
        String contentFileNm = aContent.getContentFileNm();
        if (contentFileNm != null) {
            if (contentFileNm.contains("zip") && contentFileNm.split(".zip").length > 0) {
                String preFolderNm = contentFileNm.split(".zip")[0];
                contentStartFileNm = preFolderNm + "/" + aContent.getContentStartFileNm();
            } else {
                contentStartFileNm = contentFileNm;
            }
        }

        resultRow.put("contentStartFileNm", contentStartFileNm);

        returnList.add(resultRow);
    }
    return returnList;
}

From source file:org.kisti.edison.multiboard.service.impl.BoardLocalServiceImpl.java

License:Open Source License

public Map getBoard(long divCd, String customId, long boardSeq, Locale locale) {

    Board brd;/*w  w w  .jav a 2  s. c  o  m*/
    Map map = new HashMap();
    try {

        Object[] brdObject = boardFinder.getBoard(divCd, customId, boardSeq);

        brd = (Board) brdObject[0];

        map.put("boardSeq", String.valueOf(brd.getBoardSeq()));
        map.put("groupId", String.valueOf(brd.getGroupId()));
        map.put("content", HtmlUtil.replaceNewLine(brd.getContent(locale)));
        map.put("groupBoardSeq", String.valueOf(brd.getGroupBoardSeq()));
        map.put("groupBoardTurn", String.valueOf(brd.getGroupBoardTurn()));
        map.put("popupStartDt", CustomUtil.dateToStringFormat(brd.getPopupStartDt(), "yyyy-MM-dd"));
        map.put("popupEndDt", CustomUtil.dateToStringFormat(brd.getPopupEndDt(), "yyyy-MM-dd"));
        map.put("popupYn", String.valueOf(brd.getPopupYn()));
        map.put("siteGroup", CustomUtil.strNull(brd.getSiteGroup()));
        map.put("readCnt", String.valueOf(brd.getReadCnt()));
        map.put("replyDepth", String.valueOf(brd.getReplyDepth()));
        map.put("title", brd.getTitle(locale));
        map.put("writerId", String.valueOf(brd.getWriterId()));
        map.put("writerDate", CustomUtil.dateToStringFormat(brd.getWriterDate(), "yyyy-MM-dd"));
        map.put("writerName", userPersistence.findByPrimaryKey(brd.getWriterId()).getFirstName());
        map.put("replyCount", (Integer) brdObject[2]);
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchUserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return map;
}