protected String getLoginURL(String key, ThemeDisplay themeDisplay) throws Exception {

    Group group = groupLocalService.getGroup(themeDisplay.getCompanyId(), GroupConstants.GUEST);

    long plid = PortalUtil.getPlidFromPortletId(group.getGroupId(), PortletKeys.LOGIN);

    Layout layout = layoutLocalService.getLayout(plid);

    return PortalUtil.getLayoutFullURL(layout, themeDisplay, false) + "?key=" + key;
  }
  public static String getAssetURLViewInContext(
      ThemeDisplay themeDisplay, String className, long classPK)
      throws PortalException, SystemException {

    if (className.equals(BlogsEntry.class.getName())) {
      return PortalUtil.getLayoutFullURL(classPK, PortletKeys.BLOGS);
    }

    if (className.equals(Layout.class.getName())) {
      return PortalUtil.getLayoutFullURL(LayoutLocalServiceUtil.getLayout(classPK), themeDisplay);
    }

    if (className.equals(MBCategory.class.getName())) {
      return PortalUtil.getLayoutFullURL(classPK, PortletKeys.MESSAGE_BOARDS);
    }

    if (className.equals(WikiNode.class.getName())) {
      long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), PortletKeys.WIKI);

      if (plid == 0) {
        return null;
      }

      StringBundler sb = new StringBundler(5);

      Layout layout = LayoutLocalServiceUtil.getLayout(plid);

      String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

      sb.append(layoutFullURL);

      sb.append(Portal.FRIENDLY_URL_SEPARATOR);
      sb.append("wiki/");
      sb.append(classPK);
      sb.append("/all_pages");

      return sb.toString();
    }

    return null;
  }
  protected String getThreadURL(User user, long threadId, ThemeDisplay themeDisplay)
      throws Exception {

    Group group = user.getGroup();

    long plid =
        PortalUtil.getPlidFromPortletId(group.getGroupId(), true, PortletKeys.PRIVATE_MESSAGING);

    Layout layout = LayoutLocalServiceUtil.getLayout(plid);

    String privateMessageURL = PortalUtil.getLayoutFullURL(layout, themeDisplay, false);

    return privateMessageURL + "/-/private_messaging/thread/" + threadId;
  }
  private String _getRelativeURL(Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay, false);

    String canonicalURL = PortalUtil.getCanonicalURL(layoutFullURL, themeDisplay, layout, true);

    String portalURL = themeDisplay.getPortalURL();

    if (canonicalURL.startsWith(portalURL)) {
      return canonicalURL.substring(portalURL.length());
    }

    return canonicalURL;
  }
Beispiel #5
0
  protected void visitLayout(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (!PortalUtil.isLayoutSitemapable(layout)
        || !GetterUtil.getBoolean(typeSettingsProperties.getProperty("sitemap-include"), true)) {

      return;
    }

    String layoutFullURL = PortalUtil.getLayoutFullURL(layout, themeDisplay);

    layoutFullURL = PortalUtil.getCanonicalURL(layoutFullURL, themeDisplay, layout);

    addURLElement(
        element,
        layoutFullURL,
        typeSettingsProperties,
        layout.getModifiedDate(),
        layoutFullURL,
        getAlternateURLs(layoutFullURL, themeDisplay, layout));

    Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

    if (availableLocales.length > 1) {
      Locale defaultLocale = LocaleUtil.getSiteDefault();

      for (Locale availableLocale : availableLocales) {
        if (availableLocale.equals(defaultLocale)) {
          continue;
        }

        String alternateURL =
            PortalUtil.getAlternateURL(layoutFullURL, themeDisplay, availableLocale, layout);

        addURLElement(
            element,
            alternateURL,
            typeSettingsProperties,
            layout.getModifiedDate(),
            layoutFullURL,
            getAlternateURLs(layoutFullURL, themeDisplay, layout));
      }
    }
  }
  public void updateKBArticle(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    String portletId = PortalUtil.getPortletId(actionRequest);

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    long resourcePrimKey = ParamUtil.getLong(actionRequest, "resourcePrimKey");

    long parentResourcePrimKey = ParamUtil.getLong(actionRequest, "parentResourcePrimKey");
    String title = ParamUtil.getString(actionRequest, "title");
    String content = ParamUtil.getString(actionRequest, "content");
    String description = ParamUtil.getString(actionRequest, "description");
    String[] sections = actionRequest.getParameterValues("sections");
    String dirName = ParamUtil.getString(actionRequest, "dirName");
    int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction");

    KBArticle kbArticle = null;

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(KBArticle.class.getName(), actionRequest);

    if (cmd.equals(Constants.ADD)) {
      kbArticle =
          KBArticleServiceUtil.addKBArticle(
              portletId,
              parentResourcePrimKey,
              title,
              content,
              description,
              sections,
              dirName,
              serviceContext);
    } else if (cmd.equals(Constants.UPDATE)) {
      kbArticle =
          KBArticleServiceUtil.updateKBArticle(
              resourcePrimKey, title, content, description, sections, dirName, serviceContext);
    }

    if (!cmd.equals(Constants.ADD) && !cmd.equals(Constants.UPDATE)) {
      return;
    }

    if (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT) {
      String namespace = actionResponse.getNamespace();
      String redirect = getRedirect(actionRequest, actionResponse);

      String editURL = PortalUtil.getLayoutFullURL(themeDisplay);

      editURL = HttpUtil.setParameter(editURL, "p_p_id", PortletKeys.KNOWLEDGE_BASE_ADMIN);
      editURL =
          HttpUtil.setParameter(editURL, namespace + "mvcPath", templatePath + "edit_article.jsp");
      editURL = HttpUtil.setParameter(editURL, namespace + "redirect", redirect);
      editURL =
          HttpUtil.setParameter(
              editURL, namespace + "resourcePrimKey", kbArticle.getResourcePrimKey());

      actionRequest.setAttribute(WebKeys.REDIRECT, editURL);
    }
  }
  protected static String exportToRSS(
      PortletRequest portletRequest,
      PortletResponse portletResponse,
      String name,
      String description,
      String format,
      double version,
      String displayStyle,
      String linkBehavior,
      List<AssetEntry> assetEntries)
      throws Exception {

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

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(GetterUtil.getString(description, name));

    List<SyndEntry> syndEntries = new ArrayList<>();

    syndFeed.setEntries(syndEntries);

    for (AssetEntry assetEntry : assetEntries) {
      SyndEntry syndEntry = new SyndEntryImpl();

      String author = PortalUtil.getUserName(assetEntry);

      syndEntry.setAuthor(author);

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      String languageId = LanguageUtil.getLanguageId(portletRequest);

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else {
        value = assetEntry.getSummary(languageId, true);
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      String link = getEntryURL(portletRequest, portletResponse, linkBehavior, assetEntry);

      syndEntry.setLink(link);

      syndEntry.setPublishedDate(assetEntry.getPublishDate());
      syndEntry.setTitle(assetEntry.getTitle(languageId, true));
      syndEntry.setUpdatedDate(assetEntry.getModifiedDate());
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(RSSUtil.getFeedType(format, version));

    List<SyndLink> syndLinks = new ArrayList<>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    String feedURL = getFeedURL(portletRequest);

    selfSyndLink.setHref(feedURL);

    selfSyndLink.setRel("self");

    SyndLink alternateSyndLink = new SyndLinkImpl();

    syndLinks.add(alternateSyndLink);

    alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay));
    alternateSyndLink.setRel("alternate");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);

    return RSSUtil.export(syndFeed);
  }
  protected byte[] getRSS(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    long plid = ParamUtil.getLong(request, "p_l_id");
    long companyId = ParamUtil.getLong(request, "companyId");
    long groupId = ParamUtil.getLong(request, "groupId");
    long organizationId = ParamUtil.getLong(request, "organizationId");
    int status = WorkflowConstants.STATUS_APPROVED;
    int max = ParamUtil.getInteger(request, "max", SearchContainer.DEFAULT_DELTA);
    String type = ParamUtil.getString(request, "type", RSSUtil.TYPE_DEFAULT);
    double version = ParamUtil.getDouble(request, "version", RSSUtil.VERSION_DEFAULT);
    String displayStyle =
        ParamUtil.getString(request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);

    String feedURL =
        themeDisplay.getPortalURL() + themeDisplay.getPathMain() + "/blogs/find_entry?";

    String entryURL = feedURL;

    String rss = StringPool.BLANK;

    if (companyId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          BlogsEntryServiceUtil.getCompanyEntriesRSS(
              companyId, status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (groupId > 0) {
      feedURL += "p_l_id=" + plid;

      entryURL = feedURL;

      rss =
          BlogsEntryServiceUtil.getGroupEntriesRSS(
              groupId, status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay);
    } else if (organizationId > 0) {
      feedURL = StringPool.BLANK;

      rss =
          BlogsEntryServiceUtil.getOrganizationEntriesRSS(
              organizationId,
              status,
              max,
              type,
              version,
              displayStyle,
              feedURL,
              entryURL,
              themeDisplay);
    } else if (layout != null) {
      groupId = themeDisplay.getScopeGroupId();

      feedURL =
          PortalUtil.getLayoutFullURL(themeDisplay) + Portal.FRIENDLY_URL_SEPARATOR + "blogs/rss";

      entryURL = feedURL;

      rss =
          BlogsEntryServiceUtil.getGroupEntriesRSS(
              groupId, status, max, type, version, displayStyle, feedURL, entryURL, themeDisplay);
    }

    return rss.getBytes(StringPool.UTF8);
  }
  public void deliver(String from, String recipient, Message message)
      throws MessageListenerException {

    try {
      StopWatch stopWatch = null;

      if (_log.isDebugEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();

        _log.debug("Deliver message from " + from + " to " + recipient);
      }

      String messageId = getMessageId(recipient, message);

      Company company = getCompany(messageId);

      if (_log.isDebugEnabled()) {
        _log.debug("Message id " + messageId);
      }

      long groupId = 0;
      long categoryId = getCategoryId(messageId);

      try {
        MBCategory category = MBCategoryLocalServiceUtil.getCategory(categoryId);

        groupId = category.getGroupId();
      } catch (NoSuchCategoryException nsce) {
        groupId = categoryId;
        categoryId = MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID;
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Group id " + groupId);
        _log.debug("Category id " + categoryId);
      }

      User user = UserLocalServiceUtil.getUserByEmailAddress(company.getCompanyId(), from);

      long parentMessageId = getParentMessageId(recipient, message);

      if (_log.isDebugEnabled()) {
        _log.debug("Parent message id " + parentMessageId);
      }

      MBMessage parentMessage = null;

      try {
        if (parentMessageId > 0) {
          parentMessage = MBMessageLocalServiceUtil.getMessage(parentMessageId);
        }
      } catch (NoSuchMessageException nsme) {

        // If the parent message does not exist we ignore it and post
        // the message as a new thread.

      }

      if (_log.isDebugEnabled()) {
        _log.debug("Parent message " + parentMessage);
      }

      String subject = MBUtil.getSubjectWithoutMessageId(message);

      MBMailMessage collector = new MBMailMessage();

      MBUtil.collectPartContent(message, collector);

      PermissionCheckerUtil.setThreadValues(user);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddGroupPermissions(true);
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setLayoutFullURL(
          PortalUtil.getLayoutFullURL(groupId, PortletKeys.MESSAGE_BOARDS));
      serviceContext.setScopeGroupId(groupId);

      if (parentMessage == null) {
        MBMessageServiceUtil.addMessage(
            groupId,
            categoryId,
            subject,
            collector.getBody(),
            MBMessageConstants.DEFAULT_FORMAT,
            collector.getFiles(),
            false,
            0.0,
            true,
            serviceContext);
      } else {
        MBMessageServiceUtil.addMessage(
            groupId,
            categoryId,
            parentMessage.getThreadId(),
            parentMessage.getMessageId(),
            subject,
            collector.getBody(),
            MBMessageConstants.DEFAULT_FORMAT,
            collector.getFiles(),
            false,
            0.0,
            true,
            serviceContext);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Delivering message takes " + stopWatch.getTime() + " ms");
      }
    } catch (PrincipalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug("Prevented unauthorized post from " + from);
      }

      throw new MessageListenerException(pe);
    } catch (Exception e) {
      _log.error(e, e);

      throw new MessageListenerException(e);
    } finally {
      PermissionCheckerUtil.setThreadValues(null);
    }
  }