Example usage for com.liferay.portal.kernel.language LanguageUtil get

List of usage examples for com.liferay.portal.kernel.language LanguageUtil get

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.language LanguageUtil get.

Prototype

public static String get(ResourceBundle resourceBundle, String key) 

Source Link

Usage

From source file:com.liferay.journal.content.web.internal.portlet.configuration.icon.EditJournalArticlePortletConfigurationIcon.java

License:Open Source License

@Override
public String getMessage(PortletRequest portletRequest) {
    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", getLocale(portletRequest),
            getClass());//from  w  w  w  .j a v a  2  s . co  m

    return LanguageUtil.get(resourceBundle, "edit-web-content");
}

From source file:com.liferay.journal.item.selector.web.internal.JournalItemSelectorView.java

License:Open Source License

@Override
public String getTitle(Locale locale) {
    return LanguageUtil.get(locale, "web-content-images");
}

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

License:Open Source License

/**
 * Copies the web content article matching the group, article ID, and
 * version. This method creates a new article, extracting all the values
 * from the old one and updating its article ID.
 *
 * @param  userId the primary key of the web content article's creator/owner
 * @param  groupId the primary key of the web content article's group
 * @param  oldArticleId the primary key of the old web content article
 * @param  newArticleId the primary key of the new web content article
 * @param  autoArticleId whether to auto-generate the web content article ID
 * @param  version the web content article's version
 * @return the new web content article// www.  ja  v  a  2  s. c  o m
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle copyArticle(long userId, long groupId, String oldArticleId, String newArticleId,
        boolean autoArticleId, double version) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    oldArticleId = StringUtil.toUpperCase(StringUtil.trim(oldArticleId));
    newArticleId = StringUtil.toUpperCase(StringUtil.trim(newArticleId));

    JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(groupId, oldArticleId, version);

    if (autoArticleId) {
        newArticleId = String.valueOf(counterLocalService.increment());
    } else {
        validate(newArticleId);

        if (journalArticlePersistence.countByG_A(groupId, newArticleId) > 0) {

            StringBundler sb = new StringBundler(5);

            sb.append("{groupId=");
            sb.append(groupId);
            sb.append(", articleId=");
            sb.append(newArticleId);
            sb.append("}");

            throw new DuplicateArticleIdException(sb.toString());
        }
    }

    long id = counterLocalService.increment();

    long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, newArticleId);

    JournalArticle newArticle = journalArticlePersistence.create(id);

    newArticle.setResourcePrimKey(resourcePrimKey);
    newArticle.setGroupId(groupId);
    newArticle.setCompanyId(user.getCompanyId());
    newArticle.setUserId(user.getUserId());
    newArticle.setUserName(user.getFullName());
    newArticle.setFolderId(oldArticle.getFolderId());
    newArticle.setTreePath(oldArticle.getTreePath());
    newArticle.setArticleId(newArticleId);
    newArticle.setVersion(JournalArticleConstants.VERSION_DEFAULT);
    newArticle.setUrlTitle(getUniqueUrlTitle(id, groupId, newArticleId, oldArticle.getTitleCurrentValue()));

    try {
        copyArticleImages(oldArticle, newArticle);
    } catch (Exception e) {
        newArticle.setContent(oldArticle.getContent());
    }

    newArticle.setDDMStructureKey(oldArticle.getDDMStructureKey());
    newArticle.setDDMTemplateKey(oldArticle.getDDMTemplateKey());
    newArticle.setDefaultLanguageId(oldArticle.getDefaultLanguageId());
    newArticle.setLayoutUuid(oldArticle.getLayoutUuid());
    newArticle.setDisplayDate(oldArticle.getDisplayDate());
    newArticle.setExpirationDate(oldArticle.getExpirationDate());
    newArticle.setReviewDate(oldArticle.getReviewDate());
    newArticle.setIndexable(oldArticle.isIndexable());
    newArticle.setSmallImage(oldArticle.isSmallImage());
    newArticle.setSmallImageId(counterLocalService.increment());
    newArticle.setSmallImageURL(oldArticle.getSmallImageURL());

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil
            .getWorkflowHandler(JournalArticle.class.getName());

    WorkflowDefinitionLink workflowDefinitionLink = workflowHandler
            .getWorkflowDefinitionLink(oldArticle.getCompanyId(), oldArticle.getGroupId(), oldArticle.getId());

    if (oldArticle.isPending() || (workflowDefinitionLink != null)) {
        newArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        newArticle.setStatus(oldArticle.getStatus());
    }

    ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), newArticle.getExpandoBridge());

    journalArticlePersistence.update(newArticle);

    // Article localization

    String urlTitle = JournalUtil.getUrlTitle(id, oldArticle.getUrlTitle());

    int uniqueUrlTitleCount = _getUniqueUrlTitleCount(groupId, newArticleId, urlTitle);

    Map<Locale, String> newTitleMap = oldArticle.getTitleMap();

    for (Locale locale : newTitleMap.keySet()) {
        StringBundler sb = new StringBundler(5);

        sb.append(newTitleMap.get(locale));
        sb.append(StringPool.SPACE);
        sb.append(LanguageUtil.get(locale, "duplicate"));
        sb.append(StringPool.SPACE);
        sb.append(uniqueUrlTitleCount);

        newTitleMap.put(locale, sb.toString());
    }

    _addArticleLocalizedFields(newArticle.getCompanyId(), newArticle.getId(), newTitleMap,
            oldArticle.getDescriptionMap());

    // Resources

    addArticleResources(newArticle, true, true);

    // Small image

    if (oldArticle.isSmallImage()) {
        Image image = imageLocalService.fetchImage(oldArticle.getSmallImageId());

        if (image != null) {
            byte[] smallImageBytes = image.getTextObj();

            imageLocalService.updateImage(newArticle.getSmallImageId(), smallImageBytes);
        }
    }

    // Asset

    long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());
    String[] assetTagNames = assetTagLocalService.getTagNames(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    AssetEntry oldAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(oldAssetEntry.getEntryId(), false);

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    updateAsset(userId, newArticle, assetCategoryIds, assetTagNames, assetLinkEntryIds,
            oldAssetEntry.getPriority());

    // Dynamic data mapping

    updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true);

    return newArticle;
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

public static Map<String, String> getEmailDefinitionTerms(PortletRequest portletRequest,
        String emailFromAddress, String emailFromName, String emailType) {

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

    String fromAddress = HtmlUtil.escape(emailFromAddress);
    String fromName = HtmlUtil.escape(emailFromName);
    String toAddress = LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient");
    String toName = LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient");

    if (emailType.equals("requested")) {
        toName = fromName;//w w w  . j  a  v a  2s.  c o m
        toAddress = fromAddress;

        fromName = LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-sender");
        fromAddress = LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-sender");
    }

    Map<String, String> definitionTerms = new LinkedHashMap<>();

    definitionTerms.put("[$ARTICLE_CONTENT]", LanguageUtil.get(themeDisplay.getLocale(), "the-web-content"));
    definitionTerms.put("[$ARTICLE_DIFFS$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-web-content-compared-with-the-previous-version-web-" + "content"));
    definitionTerms.put("[$ARTICLE_ID$]", LanguageUtil.get(themeDisplay.getLocale(), "the-web-content-id"));
    definitionTerms.put("[$ARTICLE_TITLE$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-web-content-title"));
    definitionTerms.put("[$ARTICLE_URL$]", LanguageUtil.get(themeDisplay.getLocale(), "the-web-content-url"));
    definitionTerms.put("[$ARTICLE_VERSION$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-web-content-version"));
    definitionTerms.put("[$FROM_ADDRESS$]", fromAddress);
    definitionTerms.put("[$FROM_NAME$]", fromName);

    Company company = themeDisplay.getCompany();

    definitionTerms.put("[$PORTAL_URL$]", company.getVirtualHostname());

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    definitionTerms.put("[$PORTLET_NAME$]", HtmlUtil.escape(portletDisplay.getTitle()));

    definitionTerms.put("[$TO_ADDRESS$]", toAddress);
    definitionTerms.put("[$TO_NAME$]", toName);

    return definitionTerms;
}

From source file:com.liferay.journal.web.asset.JournalArticleAssetRendererFactory.java

License:Open Source License

@Override
public String getSubtypeTitle(Locale locale) {
    return LanguageUtil.get(locale, "structures");
}

From source file:com.liferay.journal.web.dynamic.data.mapping.util.JournalDDMDisplay.java

License:Open Source License

public String getConfirmSelectStructureMessage(Locale locale) {
    return LanguageUtil.get(getResourceBundle(locale), "selecting-a-new-structure-deletes-all-unsaved-content");
}

From source file:com.liferay.journal.web.dynamic.data.mapping.util.JournalDDMDisplay.java

License:Open Source License

public String getConfirmSelectTemplateMessage(Locale locale) {
    return LanguageUtil.get(getResourceBundle(locale), "selecting-a-new-template-deletes-all-unsaved-content");
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String getDDMStructureName() throws PortalException {
    if (_ddmStructureName != null) {
        return _ddmStructureName;
    }//from ww w. j a v  a  2s.c om

    _ddmStructureName = LanguageUtil.get(_request, "basic-web-content");

    if (Validator.isNull(getDDMStructureKey())) {
        return _ddmStructureName;
    }

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);

    if (ddmStructure != null) {
        _ddmStructureName = ddmStructure.getName(themeDisplay.getLocale());
    }

    return _ddmStructureName;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String getFoldersJSON() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = _getFoldersJSONArray(themeDisplay.getScopeGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("children", jsonArray);
    jsonObject.put("icon", "folder");
    jsonObject.put("id", JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    jsonObject.put("name", LanguageUtil.get(themeDisplay.getLocale(), "home"));

    return jsonObject.toString();
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String getLayoutBreadcrumb(Layout layout) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Locale locale = themeDisplay.getLocale();

    List<Layout> ancestors = layout.getAncestors();

    StringBundler sb = new StringBundler(4 * ancestors.size() + 5);

    if (layout.isPrivateLayout()) {
        sb.append(LanguageUtil.get(_request, "private-pages"));
    } else {/*from   w ww  .  ja  v a2  s.c o m*/
        sb.append(LanguageUtil.get(_request, "public-pages"));
    }

    sb.append(StringPool.SPACE);
    sb.append(StringPool.GREATER_THAN);
    sb.append(StringPool.SPACE);

    Collections.reverse(ancestors);

    for (Layout ancestor : ancestors) {
        sb.append(HtmlUtil.escape(ancestor.getName(locale)));
        sb.append(StringPool.SPACE);
        sb.append(StringPool.GREATER_THAN);
        sb.append(StringPool.SPACE);
    }

    sb.append(HtmlUtil.escape(layout.getName(locale)));

    return sb.toString();
}