protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!CalEventPermission.contains(permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {

      return null;
    }

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
      groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    CalEvent event = CalEventLocalServiceUtil.getEvent(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/calendar/find_event?redirect="
            + themeDisplay.getURLCurrent()
            + "&eventId="
            + activity.getClassPK();

    // Title

    String titlePattern = null;

    if (activityType == CalendarActivityKeys.ADD_EVENT) {
      titlePattern = "activity-calendar-add-event";
    } else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
      titlePattern = "activity-calendar-update-event";
    }

    if (Validator.isNotNull(groupName)) {
      titlePattern += "-in";
    }

    String eventTitle = wrapLink(link, HtmlUtil.escape(cleanContent(event.getTitle())));

    Object[] titleArguments = new Object[] {groupName, creatorUserName, eventTitle};

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    String body = StringPool.BLANK;

    return new SocialActivityFeedEntry(link, title, body);
  }
Beispiel #2
0
  public static String getRSSURL(
      long plid, long categoryId, long threadId, long userId, ThemeDisplay themeDisplay) {

    StringBundler sb = new StringBundler(10);

    sb.append(themeDisplay.getPortalURL());
    sb.append(themeDisplay.getPathMain());
    sb.append("/message_boards/rss?p_l_id=");
    sb.append(plid);

    if (categoryId > 0) {
      sb.append("&mbCategoryId=");
      sb.append(categoryId);
    } else {
      sb.append("&groupId=");
      sb.append(themeDisplay.getScopeGroupId());
    }

    if (threadId > 0) {
      sb.append("&threadId=");
      sb.append(threadId);
    }

    if (userId > 0) {
      sb.append("&userId=");
      sb.append(userId);
    }

    return sb.toString();
  }
  private LiferayPortletURL createLiferayPortletURL(
      PortletRequest request, String toPage, String portletId) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    //		String portletId = (String) request.getAttribute(WebKeys.PORTLET_ID);
    LiferayPortletURL renderURL = null;
    String localHost = themeDisplay.getPortalURL();
    List<Layout> layouts = null;
    try {
      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);

      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(toPage) > 0) {

          renderURL =
              PortletURLFactoryUtil.create(
                  request, portletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          renderURL.setWindowState(WindowState.NORMAL);
          renderURL.setPortletMode(PortletMode.VIEW);

          break;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return renderURL;
  }
Beispiel #4
0
  protected String getAssetPublisherURL(PortletRequest portletRequest) throws Exception {

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

    Layout layout = themeDisplay.getLayout();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    StringBundler sb = new StringBundler(7);

    String layoutFriendlyURL =
        GetterUtil.getString(PortalUtil.getLayoutFriendlyURL(layout, themeDisplay));

    if (!layoutFriendlyURL.startsWith(Http.HTTP_WITH_SLASH)
        && !layoutFriendlyURL.startsWith(Http.HTTPS_WITH_SLASH)) {

      sb.append(themeDisplay.getPortalURL());
    }

    sb.append(layoutFriendlyURL);
    sb.append(Portal.FRIENDLY_URL_SEPARATOR);
    sb.append("asset_publisher/");
    sb.append(portletDisplay.getInstanceId());
    sb.append(StringPool.SLASH);

    return sb.toString();
  }
  @Override
  public String getPortletFileEntryURL(
      ThemeDisplay themeDisplay, FileEntry fileEntry, String queryString, boolean absoluteURL) {

    StringBundler sb = new StringBundler(10);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(WebServerServlet.PATH_PORTLET_FILE_ENTRY);
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getGroupId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH) && !queryString.contains("status=")) {

          if (Validator.isNotNull(queryString)) {
            queryString += StringPool.AMPERSAND;
          }

          queryString += "status=" + WorkflowConstants.STATUS_IN_TRASH;
        }
      }
    }

    if (Validator.isNotNull(queryString)) {
      sb.append(StringPool.QUESTION);
      sb.append(queryString);
    }

    String portletFileEntryURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(portletFileEntryURL, themeDisplay.getSessionId());
    }

    return portletFileEntryURL;
  }
  // TODO: allow for dynamic user url building classes to be injected
  private void addUsers(Element element, Group suppliedGroup, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    // get all users
    List<User> users = UserLocalServiceUtil.getGroupUsers(suppliedGroup.getGroupId());

    // we're only displaying users with blogs for now
    for (User u : users) {
      Group usersOwnGroup =
          GroupLocalServiceUtil.getUserGroup(suppliedGroup.getCompanyId(), u.getUserId());

      int count = BlogsEntryLocalServiceUtil.getGroupEntriesCount(usersOwnGroup.getGroupId());
      List<BlogsEntry> entries =
          BlogsEntryLocalServiceUtil.getGroupEntries(usersOwnGroup.getGroupId(), 0, count);

      // only add if the user has blogs
      if (entries != null && entries.size() > 0) {

        // index the user, as well
        StringBuffer baseUrl = new StringBuffer(themeDisplay.getPortalURL());

        // TODO figure out where web comes from
        baseUrl.append("/web");
        baseUrl.append(usersOwnGroup.getFriendlyURL());

        Element userUrlElement = element.addElement("url");

        userUrlElement.addElement("loc").addText(encodeXML(baseUrl.toString()));
        userUrlElement.addElement("changefreq").addText("daily");
      }
    }
  }
Beispiel #7
0
  protected String getEntryURLViewInContext(
      PortletRequest portletRequest, PortletResponse portletResponse, AssetEntry assetEntry)
      throws Exception {

    AssetRendererFactory assetRendererFactory =
        AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
            assetEntry.getClassName());

    AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK());

    String viewInContextURL =
        assetRenderer.getURLViewInContext(
            (LiferayPortletRequest) portletRequest, (LiferayPortletResponse) portletResponse, null);

    if (Validator.isNotNull(viewInContextURL)
        && !viewInContextURL.startsWith(Http.HTTP_WITH_SLASH)
        && !viewInContextURL.startsWith(Http.HTTPS_WITH_SLASH)) {

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

      viewInContextURL = themeDisplay.getPortalURL() + viewInContextURL;
    }

    return viewInContextURL;
  }
  @Override
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!WikiPagePermission.contains(permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {

      return null;
    }

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
      groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.getPageResource(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/wiki/find_page?pageResourcePrimKey="
            + activity.getClassPK();

    // Title

    String titlePattern = null;

    if (activityType == WikiActivityKeys.ADD_PAGE) {
      titlePattern = "activity-wiki-add-page";
    } else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
      titlePattern = "activity-wiki-update-page";
    }

    if (Validator.isNotNull(groupName)) {
      titlePattern += "-in";
    }

    String pageTitle = wrapLink(link, HtmlUtil.escape(cleanContent(pageResource.getTitle())));

    Object[] titleArguments = new Object[] {groupName, creatorUserName, pageTitle};

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    String body = StringPool.BLANK;

    return new SocialActivityFeedEntry(link, title, body);
  }
  @Override
  public void serveResource(
      StrutsPortletAction originalStrutsPortletAction,
      PortletConfig portletConfig,
      ResourceRequest resourceRequest,
      ResourceResponse resourceResponse) {

    long entryId = ParamUtil.getLong(resourceRequest, "entryId");
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    BlogsEntry entry;
    try {
      entry = BlogsEntryServiceUtil.getEntry(entryId);
      StringBundler sb = new StringBundler();

      sb.append("<html>");

      sb.append("<head>");
      sb.append("<meta content=\"");
      sb.append(ContentTypes.TEXT_HTML_UTF8);
      sb.append("\" http-equiv=\"content-type\" />");
      sb.append("<base href=\"");
      sb.append(themeDisplay.getPortalURL());
      sb.append("\" />");
      sb.append("</head>");

      sb.append("<body>");
      sb.append(entry.getContent());
      sb.append("</body>");
      sb.append("</html>");

      InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8));
      File destinationFile = null;

      destinationFile = DocumentConversionUtil.convert(entry.getEntryId() + "", is, "html", "pdf");
      OutputStream out = resourceResponse.getPortletOutputStream();
      InputStream in = new FileInputStream(destinationFile);
      HttpServletResponse httpRes = PortalUtil.getHttpServletResponse(resourceResponse);
      HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(resourceRequest);
      String contentType = MimeTypesUtil.getContentType(destinationFile);
      ServletResponseUtil.sendFile(httpReq, httpRes, destinationFile.getName(), in, contentType);
      out.close();

    } catch (PortalException e) {
      System.out.println("PortalException : " + getClass().getName() + "\n" + e);
      // e.printStackTrace();
    } catch (SystemException e) {
      System.out.println("SystemException : " + getClass().getName() + "\n" + e);
      // e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
      System.out.println("UnsupportedEncodingException : " + getClass().getName() + "\n" + e);
      // e.printStackTrace();
    } catch (Exception e) {
      System.out.println("Exception : " + getClass().getName() + "\n" + e);
      // e.printStackTrace();
    }
  }
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);
    String receiverUserName = getUserName(activity.getReceiverUserId(), themeDisplay);

    User receiverUser = UserLocalServiceUtil.getUserById(activity.getReceiverUserId());

    if (!SocialRelationLocalServiceUtil.hasRelation(
            themeDisplay.getUserId(),
            activity.getReceiverUserId(),
            SocialRelationConstants.TYPE_BI_FRIEND)
        && (themeDisplay.getUserId() != activity.getReceiverUserId())) {

      return null;
    }

    int activityType = activity.getType();

    // Link

    WallEntry wallEntry = WallEntryLocalServiceUtil.getWallEntry(activity.getClassPK());

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathFriendlyURLPublic()
            + StringPool.SLASH
            + HtmlUtil.escapeURL(receiverUser.getScreenName())
            + "/profile/-/wall/"
            + activity.getClassPK();

    // Title

    String title = StringPool.BLANK;

    if (activityType == WallActivityKeys.ADD_ENTRY) {
      title =
          themeDisplay.translate(
              "activity-social-networking-wall-add-entry",
              new Object[] {creatorUserName, receiverUserName});
    }

    // Body

    StringBuilder sb = new StringBuilder();

    sb.append("<a href=\"");
    sb.append(link);
    sb.append("\">");
    sb.append(HtmlUtil.escape(cleanContent(wallEntry.getComments())));
    sb.append("</a>");

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }
  /**
   * Upload CSV or XML file.
   *
   * @param csvXmlFile the file
   * @return the url
   * @throws Exception
   */
  public static String uploadToDocmentLibrary(UploadedFile file) throws Exception {
    LiferayFacesContext lfc = LiferayFacesContext.getInstance();
    ThemeDisplay themeDisplay = lfc.getThemeDisplay();

    // upload file to local liferay storage
    DLFileEntry fileEntry =
        FileUtils.uploadFileToFolder(file, PropsUtil.get("image.folder.id"), themeDisplay);

    return themeDisplay.getPortalURL()
        + "/c/document_library/get_file?uuid="
        + fileEntry.getUuid()
        + "&groupId="
        + themeDisplay.getScopeGroupId();
  }
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

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

    return themeDisplay.getPortalURL()
        + themeDisplay.getPathMain()
        + "/blogs/find_entry?noSuchEntryRedirect="
        + HttpUtil.encodeURL(noSuchEntryRedirect)
        + "&entryId="
        + _entry.getEntryId();
  }
  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;
  }
  @Override
  protected String getURL(
      ThemeDisplay themeDisplay, long groupId, Document result, PortletURL portletURL) {

    long resourcePrimKey = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));
    int status = WorkflowConstants.STATUS_APPROVED;

    WindowState windowState = portletURL.getWindowState();

    return KnowledgeBaseUtil.getKBArticleURL(
        themeDisplay.getPlid(),
        resourcePrimKey,
        status,
        themeDisplay.getPortalURL(),
        windowState.equals(LiferayWindowState.MAXIMIZED));
  }
  @Override
  public void include(HttpServletRequest request, HttpServletResponse response, String key)
      throws IOException {

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

    PrintWriter printWriter = response.getWriter();

    StringBundler sb = new StringBundler(5);

    sb.append("<link href=\"");
    sb.append(themeDisplay.getPortalURL());
    sb.append(themeDisplay.getPathContext());
    sb.append("/o/comliferaymentionsweb/css/mentions.css");
    sb.append("\" rel=\"stylesheet\" type = \"text/css\" />");

    printWriter.println(sb.toString());
  }
Beispiel #16
0
  /** @deprecated As of 6.2.0, replaced by {@link #getGroupName(long, ServiceContext)} */
  protected String getGroupName(long groupId, ThemeDisplay themeDisplay) {
    try {
      if (groupId <= 0) {
        return StringPool.BLANK;
      }

      Group group = GroupLocalServiceUtil.getGroup(groupId);

      String groupName = group.getDescriptiveName();

      if (group.getGroupId() == themeDisplay.getScopeGroupId()) {
        return HtmlUtil.escape(groupName);
      }

      String groupDisplayURL =
          themeDisplay.getPortalURL()
              + themeDisplay.getPathMain()
              + "/my_sites/view?groupId="
              + group.getGroupId();

      if (group.hasPublicLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=0";
      } else if (group.hasPrivateLayouts()) {
        groupDisplayURL = groupDisplayURL + "&privateLayout=1";
      } else {
        return HtmlUtil.escape(groupName);
      }

      groupName =
          "<a class=\"group\" href=\""
              + groupDisplayURL
              + "\">"
              + HtmlUtil.escape(groupName)
              + "</a>";

      return groupName;
    } catch (Exception e) {
      return StringPool.BLANK;
    }
  }
  /**
   * Returns the user's display URL based on the theme display.
   *
   * <p>The logic for the display URL to return is as follows:
   *
   * <ol>
   *   <li>If the user is the guest user, return an empty string.
   *   <li>Else, if a friendly URL is available for the user's profile, return that friendly URL.
   *   <li>Else, if <code>privateLayout</code> is <code>true</code>, return the URL of the user's
   *       default intranet site home page.
   *   <li>Otherwise, return the URL of the user's default extranet site home page.
   * </ol>
   *
   * @param themeDisplay the theme display
   * @param privateLayout whether to use the URL of the user's default intranet (versus extranet)
   *     site home page, if no friendly URL is available for the user's profile
   * @return the user's display URL
   * @throws PortalException if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public String getDisplayURL(ThemeDisplay themeDisplay, boolean privateLayout)
      throws PortalException, SystemException {

    if (isDefaultUser()) {
      return StringPool.BLANK;
    }

    String portalURL = themeDisplay.getPortalURL();

    String profileFriendlyURL = getProfileFriendlyURL();

    if (Validator.isNotNull(profileFriendlyURL)) {
      return PortalUtil.addPreservedParameters(
          themeDisplay, portalURL.concat(PortalUtil.getPathContext()).concat(profileFriendlyURL));
    }

    Group group = getGroup();

    int publicLayoutsPageCount = group.getPublicLayoutsPageCount();

    if (publicLayoutsPageCount > 0) {
      StringBundler sb = new StringBundler(5);

      sb.append(portalURL);
      sb.append(themeDisplay.getPathMain());
      sb.append("/my_sites/view?groupId=");
      sb.append(group.getGroupId());

      if (privateLayout) {
        sb.append("&privateLayout=1");
      } else {
        sb.append("&privateLayout=0");
      }

      return PortalUtil.addPreservedParameters(themeDisplay, sb.toString());
    }

    return StringPool.BLANK;
  }
  public static String getPreviewURL(
      FileEntry fileEntry,
      FileVersion fileVersion,
      ThemeDisplay themeDisplay,
      String queryString,
      boolean appendToken) {

    StringBundler sb = new StringBundler(13);

    sb.append(themeDisplay.getPortalURL());
    sb.append(themeDisplay.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileEntry.getTitle()), true));
    sb.append("?version=");
    sb.append(fileVersion.getVersion());

    if (appendToken) {
      sb.append("&t=");

      Date modifiedDate = fileVersion.getModifiedDate();

      sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    String previewURL = sb.toString();

    if (themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
  }
  protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
      throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(activity.getClassPK());

    if (!DLFileEntryPermission.contains(permissionChecker, fileEntry, ActionKeys.VIEW)) {

      return null;
    }

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
      groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    String link =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/get_file?groupId="
            + fileEntry.getGroupId()
            + "&folderId="
            + fileEntry.getFolderId()
            + "&name="
            + fileEntry.getName();

    // Title

    String titlePattern = null;

    if (activityType == DLActivityKeys.ADD_FILE_ENTRY) {
      titlePattern = "activity-document-library-add-file";
    } else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) {
      titlePattern = "activity-document-library-update-file";
    }

    if (Validator.isNotNull(groupName)) {
      titlePattern += "-in";
    }

    String fileTitle = wrapLink(link, HtmlUtil.escape(cleanContent(fileEntry.getTitle())));

    Object[] titleArguments = new Object[] {groupName, creatorUserName, fileTitle};

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    StringBundler sb = new StringBundler(3);

    String fileEntryLink =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/find_file_entry?fileEntryId="
            + fileEntry.getFileEntryId();

    sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay));
    sb.append(StringPool.SPACE);

    String folderLink =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathMain()
            + "/document_library/find_folder?groupId="
            + fileEntry.getGroupId()
            + "&folderId="
            + fileEntry.getFolderId();

    sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay));

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
  }
  public static void sendFile(PortletRequest portletRequest, PortletResponse portletResponse)
      throws IOException {

    long groupId = ParamUtil.getLong(portletRequest, "groupId");
    String articleId = ParamUtil.getString(portletRequest, "articleId");

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

    PortletPreferences portletPreferences = portletRequest.getPreferences();

    String[] allowedExtensions = StringUtil.split(portletPreferences.getValue("extensions", null));

    String languageId = LanguageUtil.getLanguageId(portletRequest);
    PortletRequestModel portletRequestModel =
        new PortletRequestModel(portletRequest, portletResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse);

    JournalArticleDisplay articleDisplay =
        JournalContentUtil.getDisplay(
            groupId, articleId, null, "export", languageId, 1, portletRequestModel, themeDisplay);

    int pages = articleDisplay.getNumberOfPages();

    StringBundler sb = new StringBundler(pages + 12);

    sb.append("<html>");

    sb.append("<head>");
    sb.append("<meta content=\"");
    sb.append(ContentTypes.TEXT_HTML_UTF8);
    sb.append("\" http-equiv=\"content-type\" />");
    sb.append("<base href=\"");
    sb.append(themeDisplay.getPortalURL());
    sb.append("\" />");
    sb.append("</head>");

    sb.append("<body>");

    sb.append(articleDisplay.getContent());

    for (int i = 2; i <= pages; i++) {
      articleDisplay =
          JournalContentUtil.getDisplay(groupId, articleId, "export", languageId, i, themeDisplay);

      sb.append(articleDisplay.getContent());
    }

    sb.append("</body>");
    sb.append("</html>");

    InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8));

    String title = articleDisplay.getTitle();
    String sourceExtension = "html";

    String fileName = title.concat(StringPool.PERIOD).concat(sourceExtension);

    String contentType = MimeTypesUtil.getContentType(fileName);

    if (Validator.isNull(targetExtension)
        || !ArrayUtil.contains(allowedExtensions, targetExtension)) {

      ServletResponseUtil.sendFile(request, response, fileName, is, contentType);

      return;
    }

    String id =
        DLUtil.getTempFileId(
            articleDisplay.getId(), String.valueOf(articleDisplay.getVersion()), languageId);

    File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension);

    if (convertedFile != null) {
      fileName = title.concat(StringPool.PERIOD).concat(targetExtension);

      is = new FileInputStream(convertedFile);
    }

    ServletResponseUtil.sendFile(request, response, fileName, is, contentType);
  }
  protected void sendEmail(long mbMessageId, ThemeDisplay themeDisplay) throws Exception {

    MBMessage mbMessage = MBMessageLocalServiceUtil.getMBMessage(mbMessageId);

    User sender = UserLocalServiceUtil.getUser(mbMessage.getUserId());

    Company company = CompanyLocalServiceUtil.getCompany(sender.getCompanyId());

    InternetAddress from = new InternetAddress(company.getEmailAddress());

    String subject =
        StringUtil.read(
            PrivateMessagingPortlet.class.getResourceAsStream(
                "dependencies/notification_message_subject.tmpl"));

    subject =
        StringUtil.replace(
            subject,
            new String[] {"[$COMPANY_NAME$]", "[$FROM_NAME$]"},
            new String[] {company.getName(), sender.getFullName()});

    String body =
        StringUtil.read(
            PrivateMessagingPortlet.class.getResourceAsStream(
                "dependencies/notification_message_body.tmpl"));

    long portraitId = sender.getPortraitId();
    String tokenId = WebServerServletTokenUtil.getToken(sender.getPortraitId());
    String portraitURL =
        themeDisplay.getPortalURL()
            + themeDisplay.getPathImage()
            + "/user_"
            + (sender.isFemale() ? "female" : "male")
            + "_portrait?img_id="
            + portraitId
            + "&t="
            + tokenId;

    body =
        StringUtil.replace(
            body,
            new String[] {
              "[$BODY$]", "[$COMPANY_NAME$]", "[$FROM_AVATAR$]",
              "[$FROM_NAME$]", "[$FROM_PROFILE_URL$]", "[$SUBJECT$]"
            },
            new String[] {
              mbMessage.getBody(),
              company.getName(),
              portraitURL,
              sender.getFullName(),
              sender.getDisplayURL(themeDisplay),
              mbMessage.getSubject()
            });

    List<UserThread> userThreads =
        UserThreadLocalServiceUtil.getMBThreadUserThreads(mbMessage.getThreadId());

    for (UserThread userThread : userThreads) {
      if ((userThread.getUserId() == mbMessage.getUserId())
          && UserNotificationManagerUtil.isDeliver(
              userThread.getUserId(),
              PortletKeys.PRIVATE_MESSAGING,
              PrivateMessagingConstants.NEW_MESSAGE,
              0,
              UserNotificationDeliveryConstants.TYPE_EMAIL)) {

        continue;
      }

      User recipient = UserLocalServiceUtil.getUser(userThread.getUserId());

      String threadURL = getThreadURL(recipient, mbMessage.getThreadId(), themeDisplay);

      if (Validator.isNull(threadURL)) {
        continue;
      }

      InternetAddress to = new InternetAddress(recipient.getEmailAddress());

      Format dateFormatDateTime =
          FastDateFormatFactoryUtil.getDateTime(
              FastDateFormatConstants.LONG,
              FastDateFormatConstants.SHORT,
              recipient.getLocale(),
              recipient.getTimeZone());

      String userThreadBody =
          StringUtil.replace(
              body,
              new String[] {"[$SENT_DATE$]", "[$THREAD_URL$]"},
              new String[] {dateFormatDateTime.format(mbMessage.getCreateDate()), threadURL});

      MailMessage mailMessage = new MailMessage(from, to, subject, userThreadBody, true);

      MailServiceUtil.sendEmail(mailMessage);
    }
  }
Beispiel #22
0
  @Override
  public String getPreviewURL(
      FileEntry fileEntry,
      FileVersion fileVersion,
      ThemeDisplay themeDisplay,
      String queryString,
      boolean appendVersion,
      boolean absoluteURL) {

    StringBundler sb = new StringBundler(17);

    if (themeDisplay != null) {
      if (absoluteURL) {
        sb.append(themeDisplay.getPortalURL());
      }
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);

    String title = fileEntry.getTitle();

    if (fileEntry.isInTrash()) {
      title = TrashUtil.getOriginalTitle(fileEntry.getTitle());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(title)));

    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getUuid());

    if (appendVersion) {
      sb.append("?version=");
      sb.append(fileVersion.getVersion());
    }

    if (ImageProcessorUtil.isImageSupported(fileVersion)) {
      if (appendVersion) {
        sb.append("&t=");
      } else {
        sb.append("?t=");
      }

      Date modifiedDate = fileVersion.getModifiedDate();

      sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    if (themeDisplay != null) {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      if (portletDisplay != null) {
        String portletId = portletDisplay.getId();

        if (portletId.equals(PortletKeys.TRASH)) {
          sb.append("&status=");
          sb.append(WorkflowConstants.STATUS_IN_TRASH);
        }
      }
    }

    String previewURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
      return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
  }
Beispiel #23
0
  /**
   * Submit.
   *
   * @return the string
   */
  public void submit() {
    // Query q = new Query();
    // q.setSearchterm(query);

    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
    Layout layout = themeDisplay.getLayout();
    String currentPage = layout.getFriendlyURL();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object responseObject = facesContext.getExternalContext().getResponse();
    if (responseObject != null && responseObject instanceof ActionResponse) {
      ActionResponse actionResponse = (ActionResponse) responseObject;
      // actionResponse.setEvent(new
      // QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"),
      // q);

      if (query != null && !query.isEmpty()) {
        log.info("searching for '{}'", query);
        // String escapedQuery = StringEscapeUtils.escapeHtml(query);
        String escapedQuery = StringUtils.escapeColonString(query);
        // msg 8:5.2014 actionResponse.setRenderParameter("searchterm",
        // query);
        escapedQuery = StringUtils.removeBlankStrings(query);
        log.info("escapedQuery:" + escapedQuery);
        actionResponse.setRenderParameter("searchterm", escapedQuery);
      } else {
        actionResponse.removePublicRenderParameter("searchterm");
      }

      actionResponse.removePublicRenderParameter("searchcategory");
    }

    // if (currentPage.equals("/home")) {
    String location = themeDisplay.getPortalURL();
    if (layout.isPublicLayout()) {
      location += themeDisplay.getPathFriendlyURLPublic();
    }

    try {
      location +=
          layout.hasScopeGroup()
              ? layout.getScopeGroup().getFriendlyURL()
              : layout.getGroup().getFriendlyURL();
      if (currentPage.equals("/home")) {
        location += "/suchen";
      } else {
        location += layout.getFriendlyURL();
      }
    } catch (PortalException e) {
      log.error("add group to url", e);
    } catch (SystemException e) {
      log.error("add group to url", e);
    }

    try {
      facesContext.getExternalContext().redirect(location);
    } catch (IOException e) {
      log.error("redirect to result page", e);
    }
    // }

  }
  private String getAssetViewURL(
      PortletRequest request, PortletResponse response, AssetEntry assetEntry, String keywords) {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
      PortletURL returnURL =
          PortletURLFactoryUtil.create(
              request,
              (String) request.getAttribute(WebKeys.PORTLET_ID),
              themeDisplay.getLayout().getPlid(),
              PortletRequest.RENDER_PHASE);
      returnURL.setWindowState(WindowState.NORMAL);
      returnURL.setPortletMode(PortletMode.VIEW);
      returnURL.setParameter("action", "ricercaLibera");
      returnURL.setParameter("cercaPerKeyword", keywords);

      PortletURL viewURL = null;

      String localHost = themeDisplay.getPortalURL();
      List<Layout> layouts = null;

      layouts = LayoutLocalServiceUtil.getLayouts(themeDisplay.getLayout().getGroupId(), false);
      for (Layout layout : layouts) {

        String nodeNameRemoved =
            PortalUtil.getLayoutFriendlyURL(layout, themeDisplay).replace(localHost, "");

        // Viene ricercato l'URL esatto per la pagina successiva
        if (nodeNameRemoved.indexOf(paginaDettaglioContenuto) > 0) {

          viewURL =
              PortletURLFactoryUtil.create(
                  request, assetPublisherPortletId, layout.getPlid(), PortletRequest.RENDER_PHASE);
          viewURL.setWindowState(WindowState.NORMAL);
          viewURL.setPortletMode(PortletMode.VIEW);
          viewURL.setParameter("action", "ricerca");
          viewURL.setParameter("struts_action", "/asset_publisher/view_content");

          // String currentURL = HttpUtil.addParameter(PortalUtil.getCurrentURL(request), "_" +
          // request.getAttribute(WebKeys.PORTLET_ID) + "_cercaPerKeyword", keywords);
          viewURL.setParameter("redirect", returnURL.toString());

          viewURL.setParameter("assetEntryId", String.valueOf(assetEntry.getEntryId()));

          AssetRendererFactory assetRendererFactory = assetEntry.getAssetRendererFactory();

          AssetRenderer assetRenderer = assetEntry.getAssetRenderer();

          viewURL.setParameter("type", assetRendererFactory.getType());

          if (Validator.isNotNull(assetRenderer.getUrlTitle())) {

            if (assetRenderer.getGroupId() != themeDisplay.getScopeGroupId()) {
              viewURL.setParameter("groupId", String.valueOf(assetRenderer.getGroupId()));
            }

            viewURL.setParameter("urlTitle", assetRenderer.getUrlTitle());
          }

          break;
        }
      }

      return viewURL.toString();

    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
  public String getDisplayURL(ThemeDisplay themeDisplay, boolean privateLayout)
      throws PortalException, SystemException {

    return getDisplayURL(themeDisplay.getPortalURL(), themeDisplay.getPathMain(), privateLayout);
  }
  public String getDisplayURL(ThemeDisplay themeDisplay) throws PortalException, SystemException {

    return getDisplayURL(themeDisplay.getPortalURL(), themeDisplay.getPathMain(), false);
  }
  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);
  }
  protected void sendOpenIdRequest(
      ThemeDisplay themeDisplay, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);
    HttpSession session = request.getSession();

    LiferayPortletResponse liferayPortletResponse =
        PortalUtil.getLiferayPortletResponse(actionResponse);

    String openId = ParamUtil.getString(actionRequest, "openId");

    PortletURL portletURL = liferayPortletResponse.createActionURL();

    portletURL.setParameter("saveLastPath", Boolean.FALSE.toString());
    portletURL.setParameter(Constants.CMD, Constants.READ);
    portletURL.setParameter("struts_action", "/login/open_id");

    List<DiscoveryInformation> discoveryInformationList = _consumerManager.discover(openId);

    DiscoveryInformation discoveryInformation =
        _consumerManager.associate(discoveryInformationList);

    session.setAttribute(OpenIdWebKeys.OPEN_ID_DISCO, discoveryInformation);

    AuthRequest authRequest =
        _consumerManager.authenticate(
            discoveryInformation, portletURL.toString(), themeDisplay.getPortalURL());

    if (_userLocalService.fetchUserByOpenId(themeDisplay.getCompanyId(), openId) != null) {

      response.sendRedirect(authRequest.getDestinationUrl(true));

      return;
    }

    String screenName = getScreenName(openId);

    User user = _userLocalService.fetchUserByScreenName(themeDisplay.getCompanyId(), screenName);

    if (user != null) {
      _userLocalService.updateOpenId(user.getUserId(), openId);

      response.sendRedirect(authRequest.getDestinationUrl(true));

      return;
    }

    FetchRequest fetchRequest = FetchRequest.createFetchRequest();

    OpenIdProvider openIdProvider =
        _openIdProviderRegistry.getOpenIdProvider(discoveryInformation.getOPEndpoint());

    Map<String, String> openIdAXTypes = openIdProvider.getAxTypes();

    for (String openIdAXType : openIdAXTypes.keySet()) {
      fetchRequest.addAttribute(openIdAXType, openIdAXTypes.get(openIdAXType), true);
    }

    authRequest.addExtension(fetchRequest);

    SRegRequest sRegRequest = SRegRequest.createFetchRequest();

    sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_EMAIL, true);
    sRegRequest.addAttribute(_OPEN_ID_SREG_ATTR_FULLNAME, true);

    authRequest.addExtension(sRegRequest);

    response.sendRedirect(authRequest.getDestinationUrl(true));
  }