Example usage for com.liferay.portal.kernel.service ServiceContext getPathMain

List of usage examples for com.liferay.portal.kernel.service ServiceContext getPathMain

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContext getPathMain.

Prototype

public String getPathMain() 

Source Link

Document

Returns the main context path of the portal, concatenated with /c.

Usage

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

License:Open Source License

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

    if (!PropsValues.BLOGS_PING_GOOGLE_ENABLED || !entry.isApproved()) {
        return;/* ww w  . j  av  a  2 s.  com*/
    }

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

    if (Validator.isNull(portletId)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Not pinging Google because there is no blogs portlet " + "provider");
        }

        return;
    }

    String layoutFullURL = PortalUtil.getLayoutFullURL(serviceContext.getScopeGroupId(), portletId);

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

    if (layoutFullURL.contains("://localhost")) {
        if (_log.isDebugEnabled()) {
            _log.debug("Not pinging Google because of localhost URL " + layoutFullURL);
        }

        return;
    }

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

    StringBundler sb = new StringBundler(6);

    String name = group.getDescriptiveName();
    String url = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs";
    String changesURL = serviceContext.getPathMain() + "/blogs/rss";

    sb.append("http://blogsearch.google.com/ping?name=");
    sb.append(HttpUtil.encodeURL(name));
    sb.append("&url=");
    sb.append(HttpUtil.encodeURL(url));
    sb.append("&changesURL=");
    sb.append(HttpUtil.encodeURL(changesURL));

    String location = sb.toString();

    if (_log.isInfoEnabled()) {
        _log.info("Pinging Google at " + location);
    }

    try {
        String response = HttpUtil.URLtoString(sb.toString());

        if (_log.isInfoEnabled()) {
            _log.info("Google ping response: " + response);
        }
    } catch (IOException ioe) {
        _log.error("Unable to ping Google at " + location, ioe);
    }
}

From source file:com.liferay.document.library.web.internal.social.DLFileEntryActivityInterpreter.java

License:Open Source License

protected String getFolderLink(FileEntry fileEntry, ServiceContext serviceContext) {

    StringBundler sb = new StringBundler(6);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/document_library/find_folder?groupId=");
    sb.append(fileEntry.getRepositoryId());
    sb.append("&folderId=");
    sb.append(fileEntry.getFolderId());/*from  ww  w  .  j  a v  a 2s .com*/

    return sb.toString();
}

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

License:Open Source License

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

    int oldStatus = page.getStatus();

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

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

    // Subscriptions

    if (status == WorkflowConstants.STATUS_APPROVED) {
        if (NotificationThreadLocal.isEnabled()
                && (!page.isMinorEdit() || wikiGroupServiceOverriddenConfiguration.pageMinorEditSendEmail())) {

            notifySubscribers(userId, page, (String) workflowContext.get(WorkflowConstants.CONTEXT_URL),
                    serviceContext);// w  w  w .  j a  v  a2  s . c  o m
        }
    }

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

        return page;
    }

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

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

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

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

    String portalURL = serviceContext.getPortalURL();

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

    attachmentURLPrefix = portalURL + attachmentURLPrefix;

    String pageContent = _wikiEngineRenderer.convert(page, null, null, attachmentURLPrefix);

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

    _mentionsNotifier.notify(page.getUserId(), page.getGroupId(), page.getTitle(), pageContent,
            WikiPage.class.getName(), page.getPageId(),
            mentionsGroupServiceConfiguration.assetEntryMentionEmailSubject(),
            mentionsGroupServiceConfiguration.assetEntryMentionEmailBody(), serviceContext);

    return page;
}

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   w w  w. jav 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.message.boards.web.internal.social.MBMessageActivityInterpreter.java

License:Open Source License

@Override
protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception {

    MBMessage message = _mbMessageLocalService.getMessage(activity.getClassPK());

    if (message.getCategoryId() <= 0) {
        return StringPool.BLANK;
    }/*w ww. j  a v  a  2 s  .com*/

    StringBundler sb = new StringBundler(4);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/message_boards/find_category?mbCategoryId=");
    sb.append(message.getCategoryId());

    String categoryLink = sb.toString();

    categoryLink = addNoSuchEntryRedirect(categoryLink, MBCategory.class.getName(), message.getCategoryId(),
            serviceContext);

    return wrapLink(categoryLink, "go-to-category", serviceContext);
}

From source file:com.liferay.message.boards.web.internal.social.MBThreadActivityInterpreter.java

License:Open Source License

@Override
protected String getBody(SocialActivity activity, ServiceContext serviceContext) throws Exception {

    MBMessage message = getMessage(activity);

    if (message.getCategoryId() <= 0) {
        return StringPool.BLANK;
    }//  www.  j av a 2s. co  m

    StringBundler sb = new StringBundler(4);

    sb.append(serviceContext.getPortalURL());
    sb.append(serviceContext.getPathMain());
    sb.append("/message_boards/find_category?mbCategoryId=");
    sb.append(message.getCategoryId());

    String categoryLink = sb.toString();

    categoryLink = addNoSuchEntryRedirect(categoryLink, MBCategory.class.getName(), message.getCategoryId(),
            serviceContext);

    return wrapLink(categoryLink, "go-to-category", serviceContext);
}

From source file:com.liferay.social.activity.customizer.interpreter.CustomWikiActivityInterpreter.java

License:Open Source License

protected String getAttachmentTitle(SocialActivity activity, WikiPageResource pageResource,
        ServiceContext serviceContext) throws Exception {

    int activityType = activity.getType();

    if ((activityType == SocialActivityConstants.TYPE_ADD_ATTACHMENT)
            || (activityType == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH)
            || (activityType == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH)) {

        String link = null;/*from   ww  w.  j ava 2  s  .c  om*/

        FileEntry fileEntry = null;

        try {
            long fileEntryId = GetterUtil.getLong(activity.getExtraDataValue("fileEntryId"));

            fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);
        } catch (NoSuchModelException nsme) {

            // LPS-52675

            if (_log.isDebugEnabled()) {
                _log.debug(nsme, nsme);
            }
        }

        String fileEntryTitle = activity.getExtraDataValue("fileEntryTitle");

        if ((fileEntry != null) && !fileEntry.isInTrash()) {
            StringBundler sb = new StringBundler(9);

            sb.append(serviceContext.getPathMain());
            sb.append("/wiki/get_page_attachment?p_l_id=");
            sb.append(serviceContext.getPlid());
            sb.append("&nodeId=");
            sb.append(pageResource.getNodeId());
            sb.append("&title=");
            sb.append(URLCodec.encodeURL(pageResource.getTitle()));
            sb.append("&fileName=");
            sb.append(fileEntryTitle);

            link = sb.toString();
        }

        return wrapLink(link, fileEntryTitle);
    }

    return StringPool.BLANK;
}

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 www .ja va  2s  .c  o 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();
}

From source file:com.liferay.wiki.web.internal.social.WikiActivityInterpreter.java

License:Open Source License

protected String getAttachmentTitle(SocialActivity activity, WikiPageResource pageResource,
        ServiceContext serviceContext) throws Exception {

    int activityType = activity.getType();

    if ((activityType == SocialActivityConstants.TYPE_ADD_ATTACHMENT)
            || (activityType == SocialActivityConstants.TYPE_MOVE_ATTACHMENT_TO_TRASH)
            || (activityType == SocialActivityConstants.TYPE_RESTORE_ATTACHMENT_FROM_TRASH)) {

        String link = null;//from  w ww .  j av  a2  s. c  om

        FileEntry fileEntry = null;

        try {
            long fileEntryId = GetterUtil.getLong(activity.getExtraDataValue("fileEntryId"));

            fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);
        } catch (NoSuchModelException nsme) {
        }

        String fileEntryTitle = activity.getExtraDataValue("fileEntryTitle");

        if ((fileEntry != null) && !fileEntry.isInTrash()) {
            StringBundler sb = new StringBundler(9);

            sb.append(serviceContext.getPathMain());
            sb.append("/wiki/get_page_attachment?p_l_id=");
            sb.append(serviceContext.getPlid());
            sb.append("&nodeId=");
            sb.append(pageResource.getNodeId());
            sb.append("&title=");
            sb.append(HttpUtil.encodeURL(pageResource.getTitle()));
            sb.append("&fileName=");
            sb.append(fileEntryTitle);

            link = sb.toString();
        }

        return wrapLink(link, fileEntryTitle);
    }

    return StringPool.BLANK;
}