Example usage for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY

List of usage examples for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY

Introduction

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

Prototype

String THEME_DISPLAY

To view the source code for com.liferay.portal.kernel.util WebKeys THEME_DISPLAY.

Click Source Link

Usage

From source file:com.liferay.blogs.internal.trash.BlogsEntryTrashHandler.java

License:Open Source License

@Override
public String getRestoreMessage(PortletRequest portletRequest, long classPK) {

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

    return themeDisplay.translate("blogs");
}

From source file:com.liferay.blogs.portlet.test.PortletLayoutFinderTest.java

License:Open Source License

protected HttpServletRequest getHttpServletRequest() throws Exception {
    HttpServletRequest request = new MockHttpServletRequest();

    ThemeDisplay themeDisplay = getThemeDisplay();

    request.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);

    return request;
}

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

License:Open Source License

protected void pingPingback(BlogsEntry entry, ServiceContext serviceContext) throws PortalException {

    if (!PropsValues.BLOGS_PINGBACK_ENABLED || !entry.isAllowPingbacks() || !entry.isApproved()) {

        return;//from ww  w  . java2  s . co  m
    }

    HttpServletRequest request = serviceContext.getRequest();

    if (request == null) {
        return;
    }

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

    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay);

    if (Validator.isNull(layoutFullURL)) {
        return;
    }

    String sourceUri = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle();

    Source source = new Source(entry.getContent());

    List<StartTag> tags = source.getAllStartTags("a");

    for (StartTag tag : tags) {
        String targetUri = tag.getAttributeValue("href");

        if (Validator.isNotNull(targetUri)) {
            try {
                LinkbackProducerUtil.sendPingback(sourceUri, targetUri);
            } catch (Exception e) {
                _log.error("Error while sending pingback " + targetUri, e);
            }
        }
    }
}

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

License:Open Source License

protected void pingTrackbacks(BlogsEntry entry, String[] trackbacks, boolean pingOldTrackbacks,
        ServiceContext serviceContext) throws PortalException {

    if (!PropsValues.BLOGS_TRACKBACK_ENABLED || !entry.isAllowTrackbacks() || !entry.isApproved()) {

        return;// w  w  w .  j a v a 2 s .  c om
    }

    HttpServletRequest request = serviceContext.getRequest();

    if (request == null) {
        return;
    }

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

    String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay);

    if (Validator.isNull(layoutFullURL)) {
        return;
    }

    Map<String, String> parts = new HashMap<>();

    String excerpt = StringUtil.shorten(HtmlUtil.extractText(entry.getContent()),
            PropsValues.BLOGS_LINKBACK_EXCERPT_LENGTH);
    String url = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle();

    parts.put("title", entry.getTitle());
    parts.put("excerpt", excerpt);
    parts.put("url", url);
    parts.put("blog_name", entry.getUserName());

    Set<String> trackbacksSet = null;

    if (ArrayUtil.isNotEmpty(trackbacks)) {
        trackbacksSet = SetUtil.fromArray(trackbacks);
    } else {
        trackbacksSet = new HashSet<>();
    }

    if (pingOldTrackbacks) {
        trackbacksSet.addAll(SetUtil.fromArray(StringUtil.split(entry.getTrackbacks())));

        entry.setTrackbacks(StringPool.BLANK);

        blogsEntryPersistence.update(entry);
    }

    Set<String> oldTrackbacks = SetUtil.fromArray(StringUtil.split(entry.getTrackbacks()));

    Set<String> validTrackbacks = new HashSet<>();

    for (String trackback : trackbacksSet) {
        if (oldTrackbacks.contains(trackback)) {
            continue;
        }

        try {
            if (LinkbackProducerUtil.sendTrackback(trackback, parts)) {
                validTrackbacks.add(trackback);
            }
        } catch (Exception e) {
            _log.error("Error while sending trackback at " + trackback, e);
        }
    }

    if (!validTrackbacks.isEmpty()) {
        String newTrackbacks = StringUtil.merge(validTrackbacks);

        if (Validator.isNotNull(entry.getTrackbacks())) {
            newTrackbacks += StringPool.COMMA + entry.getTrackbacks();
        }

        entry.setTrackbacks(newTrackbacks);

        blogsEntryPersistence.update(entry);
    }
}

From source file:com.liferay.blogs.util.BlogsUtil.java

License:Open Source License

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

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

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

    definitionTerms.put("[$BLOGS_ENTRY_CONTENT$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-content"));
    definitionTerms.put("[$BLOGS_ENTRY_CREATE_DATE$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-date-the-blog-entry-was-created"));
    definitionTerms.put("[$BLOGS_ENTRY_DESCRIPTION$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-description"));
    definitionTerms.put("[$BLOGS_ENTRY_SITE_NAME$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-name-of-the-site-where-the-blog-entry-was-created"));
    definitionTerms.put("[$BLOGS_ENTRY_STATUS_BY_USER_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-updated-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_TITLE$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-title"));
    definitionTerms.put("[$BLOGS_ENTRY_UPDATE_COMMENT$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-comment-of-the-user-who-updated-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-email-address-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_PORTRAIT_URL$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-portrait-url-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_URL$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-public-site-url-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_URL$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-blog-entry-url"));
    definitionTerms.put("[$COMPANY_ID$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-id-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_MX$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-mx-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-name-associated-with-the-blog"));
    definitionTerms.put("[$FROM_ADDRESS$]", HtmlUtil.escape(emailFromAddress));
    definitionTerms.put("[$FROM_NAME$]", HtmlUtil.escape(emailFromName));

    Company company = themeDisplay.getCompany();

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

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

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

    definitionTerms.put("[$SITE_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-site-name-associated-with-the-blog"));
    definitionTerms.put("[$TO_ADDRESS$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-address-of-the-email-recipient"));
    definitionTerms.put("[$TO_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-name-of-the-email-recipient"));
    definitionTerms.put("[$UNSUBSCRIBE_URL$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-url-to-unsubscribe-the-user"));

    return definitionTerms;
}

From source file:com.liferay.blogs.util.BlogsUtil.java

License:Open Source License

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

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

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

    definitionTerms.put("[$BLOGS_ENTRY_USER_ADDRESS$]", LanguageUtil.get(themeDisplay.getLocale(),
            "the-email-address-of-the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$BLOGS_ENTRY_USER_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-user-who-added-the-blog-entry"));
    definitionTerms.put("[$COMPANY_ID$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-id-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_MX$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-mx-associated-with-the-blog"));
    definitionTerms.put("[$COMPANY_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-company-name-associated-with-the-blog"));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

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

    definitionTerms.put("[$SITE_NAME$]",
            LanguageUtil.get(themeDisplay.getLocale(), "the-site-name-associated-with-the-blog"));

    return definitionTerms;
}

From source file:com.liferay.blogs.web.internal.display.context.BlogsPortletInstanceSettingsHelper.java

License:Open Source License

public long getDisplayStyleGroupId() {
    if (_displayStyleGroupId != 0) {
        return _displayStyleGroupId;
    }/*from   w  w w .j  a  va2 s. c o  m*/

    _displayStyleGroupId = _blogsPortletInstanceConfiguration.displayStyleGroupId();

    if (_displayStyleGroupId <= 0) {
        ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

        _displayStyleGroupId = themeDisplay.getScopeGroupId();
    }

    return _displayStyleGroupId;
}

From source file:com.liferay.blogs.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static void getEntry(PortletRequest portletRequest) throws Exception {

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

    long entryId = ParamUtil.getLong(portletRequest, "entryId");

    String urlTitle = ParamUtil.getString(portletRequest, "urlTitle");

    BlogsEntry entry = null;//from  w  w w .  ja  va 2s. c  om

    if (entryId > 0) {
        entry = BlogsEntryServiceUtil.getEntry(entryId);
    } else if (Validator.isNotNull(urlTitle) && SessionErrors.isEmpty(portletRequest)) {

        try {
            entry = BlogsEntryServiceUtil.getEntry(themeDisplay.getScopeGroupId(), urlTitle);
        } catch (NoSuchEntryException nsee) {
            if (urlTitle.indexOf(CharPool.UNDERLINE) != -1) {

                // Check another URL title for backwards compatibility. See
                // LEP-5733.

                urlTitle = StringUtil.replace(urlTitle, CharPool.UNDERLINE, CharPool.DASH);

                entry = BlogsEntryServiceUtil.getEntry(themeDisplay.getScopeGroupId(), urlTitle);
            } else {
                throw nsee;
            }
        }
    }

    if ((entry != null) && entry.isInTrash()) {
        throw new NoSuchEntryException("{entryId=" + entryId + "}");
    }

    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);

    request.setAttribute(WebKeys.BLOGS_ENTRY, entry);
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

protected void subscribe(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    _blogsEntryService.subscribe(themeDisplay.getScopeGroupId());
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

protected void unsubscribe(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    _blogsEntryService.unsubscribe(themeDisplay.getScopeGroupId());
}