protected void redirectUpdateAccount(
      HttpServletRequest request, HttpServletResponse response, User user) throws Exception {

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

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("saveLastPath", Boolean.FALSE.toString());
    portletURL.setParameter("struts_action", "/login/update_account");

    PortletURL redirectURL =
        PortletURLFactoryUtil.create(
            request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

    redirectURL.setParameter("struts_action", "/login/login_redirect");
    redirectURL.setParameter("emailAddress", user.getEmailAddress());
    redirectURL.setParameter("anonymousUser", Boolean.FALSE.toString());
    redirectURL.setPortletMode(PortletMode.VIEW);
    redirectURL.setWindowState(LiferayWindowState.POP_UP);

    portletURL.setParameter("redirect", redirectURL.toString());
    portletURL.setParameter("userId", String.valueOf(user.getUserId()));
    portletURL.setParameter("emailAddress", user.getEmailAddress());
    portletURL.setParameter("firstName", user.getFirstName());
    portletURL.setParameter("lastName", user.getLastName());
    portletURL.setPortletMode(PortletMode.VIEW);
    portletURL.setWindowState(LiferayWindowState.POP_UP);

    response.sendRedirect(portletURL.toString());
  }
  @Override
  public String getScopeDescriptiveName(ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    if (getGroupId() == themeDisplay.getScopeGroupId()) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-site"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
      StringBundler sb = new StringBundler(5);

      sb.append(themeDisplay.translate("current-page"));
      sb.append(StringPool.SPACE);
      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      return sb.toString();
    } else if (isLayoutPrototype()) {
      return themeDisplay.translate("default");
    } else {
      return HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale()));
    }
  }
  protected URLMenuItem getPortletTitleMenuItem(
      PortletRequest portletRequest, ThemeDisplay themeDisplay) {

    URLMenuItem urlMenuItem = new URLMenuItem();

    urlMenuItem.setIcon("icon-plus-sign-2");

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            portletRequest,
            BlogsPortletKeys.BLOGS,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/blogs/edit_entry");

    String currentURL = PortalUtil.getCurrentURL(portletRequest);

    portletURL.setParameter("redirect", currentURL);
    portletURL.setParameter("backURL", currentURL);

    urlMenuItem.setURL(portletURL.toString());

    return urlMenuItem;
  }
  protected String getSaveAndContinueRedirect(
      ActionRequest actionRequest, JournalArticle article, String redirect) throws Exception {

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

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            JournalPortletKeys.JOURNAL,
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcPath", "/edit_article.jsp");
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("referringPortletResource", referringPortletResource, false);
    portletURL.setParameter("resourcePrimKey", String.valueOf(article.getResourcePrimKey()), false);
    portletURL.setParameter("groupId", String.valueOf(article.getGroupId()), false);
    portletURL.setParameter("folderId", String.valueOf(article.getFolderId()), false);
    portletURL.setParameter("articleId", article.getArticleId(), false);
    portletURL.setParameter("version", String.valueOf(article.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      FileEntry fileEntry,
      String redirect)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/document_library/edit_file_entry");
    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("groupId", String.valueOf(fileEntry.getGroupId()), false);
    portletURL.setParameter("fileEntryId", String.valueOf(fileEntry.getFileEntryId()), false);
    portletURL.setParameter("version", String.valueOf(fileEntry.getVersion()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig, ActionRequest actionRequest, DDMStructure structure)
      throws Exception {

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/dynamic_data_mapping/copy_structure");

    long classNameId = PortalUtil.getClassNameId(DDMStructure.class);

    portletURL.setParameter("classNameId", String.valueOf(classNameId), false);

    portletURL.setParameter("classPK", String.valueOf(structure.getStructureId()), false);
    portletURL.setParameter(
        "copyFormTemplates", ParamUtil.getString(actionRequest, "copyFormTemplates"), false);
    portletURL.setParameter(
        "copyDisplayTemplates", ParamUtil.getString(actionRequest, "copyDisplayTemplates"), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
Example #7
0
  public static String getCreateAccountHREF(HttpServletRequest request, ThemeDisplay themeDisplay)
      throws Exception {

    if (Validator.isNull(PropsValues.COMPANY_SECURITY_STRANGERS_URL)) {
      PortletURL createAccountURL =
          new PortletURLImpl(
              request, PortletKeys.LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      createAccountURL.setWindowState(WindowState.MAXIMIZED);
      createAccountURL.setPortletMode(PortletMode.VIEW);

      createAccountURL.setParameter("saveLastPath", "0");
      createAccountURL.setParameter("struts_action", "/login/create_account");

      return createAccountURL.toString();
    }

    try {
      Layout layout =
          LayoutLocalServiceUtil.getFriendlyURLLayout(
              themeDisplay.getScopeGroupId(), false, PropsValues.COMPANY_SECURITY_STRANGERS_URL);

      return PortalUtil.getLayoutURL(layout, themeDisplay);
    } catch (NoSuchLayoutException nsle) {
    }

    return StringPool.BLANK;
  }
  protected void sendRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      ThemeDisplay themeDisplay,
      String login,
      String password)
      throws Exception {

    HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

    String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

    if (Validator.isNotNull(redirect)) {
      HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

      AuthenticatedSessionManagerUtil.login(request, response, login, password, false, null);
    } else {
      PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

      loginURL.setParameter("login", login);

      redirect = loginURL.toString();
    }

    actionResponse.sendRedirect(redirect);
  }
  protected String getSaveAndContinueRedirect(
      ActionRequest actionRequest, BlogsEntry entry, String redirect) throws Exception {

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

    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

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

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/blogs/edit_entry");

    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("backURL", backURL, false);
    portletURL.setParameter("groupId", String.valueOf(entry.getGroupId()), false);
    portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()), false);
    portletURL.setWindowState(actionRequest.getWindowState());

    return portletURL.toString();
  }
  @Override
  public String execute(
      StrutsAction originalStrutsAction, HttpServletRequest request, HttpServletResponse response)
      throws Exception {

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

    long plid = ParamUtil.getLong(request, "plid");
    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");
    int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_APPROVED);
    boolean maximized = ParamUtil.getBoolean(request, "maximized");

    KBArticle kbArticle = getKBArticle(resourcePrimKey, status);

    if (!isValidPlid(plid)) {
      plid = themeDisplay.getPlid();
    }

    PortletURL portletURL = null;

    if (kbArticle == null) {
      portletURL = getDynamicPortletURL(plid, status, request);
    }

    if (status != WorkflowConstants.STATUS_APPROVED) {
      portletURL = getDynamicPortletURL(plid, status, request);
    }

    if (portletURL == null) {
      portletURL = getKBArticleURL(plid, false, kbArticle, request);
    }

    if (portletURL == null) {
      portletURL = getKBArticleURL(plid, true, kbArticle, request);
    }

    if (portletURL == null) {
      portletURL = getDynamicPortletURL(plid, status, request);
    }

    if (maximized) {
      portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
      portletURL.setPortletMode(PortletMode.VIEW);
    }

    response.sendRedirect(portletURL.toString());

    return null;
  }
  protected void sendLoginRedirect(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

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

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            request, PortletKeys.FAST_LOGIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

    portletURL.setWindowState(LiferayWindowState.POP_UP);

    portletURL.setParameter("struts_action", "/login/login_redirect");

    response.sendRedirect(portletURL.toString());
  }
  @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 String getScopeDescriptiveName(ThemeDisplay themeDisplay) throws PortalException {

    if (getGroupId() == themeDisplay.getScopeGroupId()) {
      return StringUtil.appendParentheticalSuffix(
          themeDisplay.translate("current-site"),
          HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
    } else if (isLayout() && (getClassPK() == themeDisplay.getPlid())) {
      return StringUtil.appendParentheticalSuffix(
          themeDisplay.translate("current-page"),
          HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale())));
    } else if (isLayoutPrototype()) {
      return themeDisplay.translate("default");
    } else {
      return HtmlUtil.escape(getDescriptiveName(themeDisplay.getLocale()));
    }
  }
  protected void addPortletTitleAddCategoryMenuItem(
      List<MenuItem> menuItems,
      long categoryId,
      ThemeDisplay themeDisplay,
      PortletRequest portletRequest)
      throws PortalException {

    if (!containsPermission(
        themeDisplay.getPermissionChecker(),
        themeDisplay.getScopeGroupId(),
        categoryId,
        ActionKeys.ADD_CATEGORY)) {

      return;
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    String key = "category[message-board]";

    if (categoryId != MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID) {
      key = "subcategory[message-board]";
    }

    urlMenuItem.setLabel(LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), key));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            portletRequest,
            portletDisplay.getId(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/edit_category");
    portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest));
    portletURL.setParameter("parentCategoryId", String.valueOf(categoryId));

    urlMenuItem.setURL(portletURL.toString());

    menuItems.add(urlMenuItem);
  }
Example #15
0
  public String getJSON(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HttpSession session = request.getSession();

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

    Layout layout = themeDisplay.getLayout();

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    String portletId = ParamUtil.getString(request, "portletId");

    if (!PortletPermissionUtil.contains(
        permissionChecker, themeDisplay.getPlid(), portletId, ActionKeys.CONFIGURATION)) {

      return null;
    }

    String languageId = LanguageUtil.getLanguageId(request);
    String title = ParamUtil.getString(request, "title");

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    portletSetup.setValue("portlet-setup-title-" + languageId, title);
    portletSetup.setValue("portlet-setup-use-custom-title", "true");

    portletSetup.store();

    InvokerPortletImpl.clearResponse(
        session, layout.getPrimaryKey(), portletId, LanguageUtil.getLanguageId(request));

    return null;
  }
Example #16
0
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {
    if (!_processed) {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
      PortletConfig portletConfig =
          (PortletConfig) renderRequest.getAttribute("javax.portlet.config");
      _portletName = portletConfig.getPortletName();
      PortletURL pURL =
          PortletURLFactoryUtil.create(
              renderRequest,
              _portletName + "_WAR_" + _portletName + "portlet",
              themeDisplay.getPlid(),
              PortletRequest.ACTION_PHASE);
      pURL.setParameter(ActionRequest.ACTION_NAME, ProxyConstant.ACTION_LINK);
      _portletURL = pURL.toString();
      // read portlet config;
      PortletPreferences preferences = renderRequest.getPreferences();
      String portletResource = ParamUtil.getString(renderRequest, "portletResource");

      if (Validator.isNotNull(portletResource)) {
        try {
          preferences =
              PortletPreferencesFactoryUtil.getPortletSetup(renderRequest, portletResource);
        } catch (PortalException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (SystemException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      _proxyURL = preferences.getValue("url", "");
      log.info("proxyurl=" + _proxyURL);

      defaultProxyRequest();
      renderResponse.getWriter().print(_result);
    } else renderResponse.getWriter().print("processed");
  }
Example #17
0
  private void getPortletInfo(ActionRequest actionRequest) {
    log.info("getPortletInfo");
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig =
        (PortletConfig) actionRequest.getAttribute("javax.portlet.config");
    _portletName = portletConfig.getPortletName();
    PortletURL pURL =
        PortletURLFactoryUtil.create(
            actionRequest,
            _portletName + "_WAR_" + _portletName + "portlet",
            themeDisplay.getPlid(),
            PortletRequest.ACTION_PHASE);
    /*try {
    	pURL.setWindowState(WindowState.NORMAL );
    } catch (WindowStateException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }*/
    pURL.setParameter(ActionRequest.ACTION_NAME, ProxyConstant.ACTION_LINK);
    _portletURL = pURL.toString();

    // read portlet config;
    PortletPreferences preferences = actionRequest.getPreferences();
    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    if (Validator.isNotNull(portletResource)) {
      try {
        preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletResource);
      } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    _proxyURL = preferences.getValue("url", "");
  } /*
  @Override
  public void addSelection(
      ThemeDisplay themeDisplay,
      PortletPreferences portletPreferences,
      String portletId,
      long assetEntryId,
      int assetEntryOrder,
      String assetEntryType)
      throws Exception {

    AssetEntry assetEntry = AssetEntryLocalServiceUtil.getEntry(assetEntryId);

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    String assetEntryXml = _getAssetEntryXml(assetEntryType, assetEntry.getClassUuid());

    if (!ArrayUtil.contains(assetEntryXmls, assetEntryXml)) {
      if (assetEntryOrder > -1) {
        assetEntryXmls[assetEntryOrder] = assetEntryXml;
      } else {
        assetEntryXmls = ArrayUtil.append(assetEntryXmls, assetEntryXml);
      }

      portletPreferences.setValues("assetEntryXml", assetEntryXmls);
    }

    long plid = themeDisplay.getRefererPlid();

    if (plid == 0) {
      plid = themeDisplay.getPlid();
    }

    List<AssetEntry> assetEntries = new ArrayList<AssetEntry>();

    assetEntries.add(assetEntry);

    notifySubscribers(portletPreferences, plid, portletId, assetEntries);
  }
  protected void addPortletTitleAddMessageMenuItem(
      List<MenuItem> menuItems,
      long categoryId,
      ThemeDisplay themeDisplay,
      PortletRequest portletRequest)
      throws PortalException {

    if (!containsPermission(
        themeDisplay.getPermissionChecker(),
        themeDisplay.getScopeGroupId(),
        categoryId,
        ActionKeys.ADD_MESSAGE)) {

      return;
    }

    URLMenuItem urlMenuItem = new URLMenuItem();

    urlMenuItem.setLabel(
        LanguageUtil.get(PortalUtil.getHttpServletRequest(portletRequest), "thread"));

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    PortletURL portletURL =
        PortletURLFactoryUtil.create(
            portletRequest,
            portletDisplay.getId(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcRenderCommandName", "/message_boards/edit_message");
    portletURL.setParameter("redirect", PortalUtil.getCurrentURL(portletRequest));
    portletURL.setParameter("mbCategoryId", String.valueOf(categoryId));

    urlMenuItem.setURL(portletURL.toString());

    menuItems.add(urlMenuItem);
  }
  protected String getSaveAndContinueRedirect(
      PortletConfig portletConfig, ActionRequest actionRequest, BlogsEntry entry, String redirect)
      throws Exception {

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

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

    boolean preview = ParamUtil.getBoolean(actionRequest, "preview");

    PortletURLImpl portletURL =
        new PortletURLImpl(
            actionRequest,
            portletConfig.getPortletName(),
            themeDisplay.getPlid(),
            PortletRequest.RENDER_PHASE);

    portletURL.setWindowState(actionRequest.getWindowState());

    String portletName = portletConfig.getPortletName();

    if (portletName.equals(PortletKeys.BLOGS_ADMIN)) {
      portletURL.setParameter("struts_action", "/blogs_admin/edit_entry");
    } else {
      portletURL.setParameter("struts_action", "/blogs/edit_entry");
    }

    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
    portletURL.setParameter("redirect", redirect, false);
    portletURL.setParameter("backURL", backURL, false);
    portletURL.setParameter("groupId", String.valueOf(entry.getGroupId()), false);
    portletURL.setParameter("entryId", String.valueOf(entry.getEntryId()), false);
    portletURL.setParameter("preview", String.valueOf(preview), false);

    return portletURL.toString();
  }
  public static String getURL(
      HttpServletRequest request,
      ThemeDisplay themeDisplay,
      AssetRendererFactory assetRendererFactory,
      AssetRenderer assetRenderer)
      throws Exception {

    long classPK = assetRenderer.getClassPK();
    String className = assetRendererFactory.getClassName();
    String portletId = PortletProviderUtil.getPortletId(className, PortletProvider.Action.VIEW);

    PortletURL portletURL = null;

    if (className.equals(BlogsEntry.class.getName())) {
      portletURL =
          PortletURLFactoryUtil.create(
              request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcRenderCommandName", "/blogs/view_entry");
      portletURL.setParameter("entryId", String.valueOf(classPK));
    } else if (className.equals(JournalArticle.class.getName())) {
      JournalArticle journalArticle = JournalArticleLocalServiceUtil.getLatestArticle(classPK);

      portletURL =
          PortletURLFactoryUtil.create(
              request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      portletURL.setParameter("struts_action", "/journal_content/view");
      portletURL.setParameter("groupId", String.valueOf(journalArticle.getGroupId()));
      portletURL.setParameter("articleId", journalArticle.getArticleId());
    } else if (className.equals(KBArticle.class.getName())) {
      portletURL =
          PortletURLFactoryUtil.create(
              request,
              PortletKeys.KNOWLEDGE_BASE_ARTICLE_DEFAULT_INSTANCE,
              themeDisplay.getPlid(),
              PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/article/view_article.jsp");
      portletURL.setParameter("resourcePrimKey", String.valueOf(classPK));
    } else if (className.equals(MBMessage.class.getName())) {
      portletURL =
          PortletURLFactoryUtil.create(
              request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      portletURL.setParameter("struts_action", "/message_boards/view_message");
      portletURL.setParameter("messageId", String.valueOf(classPK));
    } else if (className.equals(WikiPage.class.getName())) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPage(classPK);

      portletURL =
          PortletURLFactoryUtil.create(
              request, portletId, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

      portletURL.setParameter("struts_action", "/wiki/view");
      portletURL.setParameter("nodeId", String.valueOf(wikiPage.getNodeId()));
      portletURL.setParameter("title", wikiPage.getTitle());
    }

    String currentURL = PortalUtil.getCurrentURL(request);

    if (portletURL == null) {
      return currentURL;
    }

    portletURL.setWindowState(WindowState.MAXIMIZED);
    portletURL.setPortletMode(PortletMode.VIEW);

    portletURL.setParameter("returnToFullPageURL", currentURL);

    return portletURL.toString();
  }
  protected String getPortletURL(HttpServletRequest request) throws Exception {

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

    String cacheability = ParamUtil.getString(request, "cacheability");
    boolean copyCurrentRenderParameters =
        ParamUtil.getBoolean(request, "copyCurrentRenderParameters");
    long doAsGroupId = ParamUtil.getLong(request, "doAsGroupId");
    long doAsUserId = ParamUtil.getLong(request, "doAsUserId");
    String doAsUserLanguageId = ParamUtil.getString(request, "doAsUserLanguageId");
    // boolean encrypt = ParamUtil.getBoolean(request, "encrypt");
    boolean escapeXml = ParamUtil.getBoolean(request, "escapeXml");
    String lifecycle = ParamUtil.getString(request, "lifecycle");
    String name = ParamUtil.getString(request, "name");
    boolean portletConfiguration = ParamUtil.getBoolean(request, "portletConfiguration");
    String portletId = ParamUtil.getString(request, "portletId");
    String portletMode = ParamUtil.getString(request, "portletMode");
    String resourceId = ParamUtil.getString(request, "resourceId");
    String returnToFullPageURL = ParamUtil.getString(request, "returnToFullPageURL");
    boolean secure = ParamUtil.getBoolean(request, "secure", request.isSecure());
    String windowState = ParamUtil.getString(request, "windowState");

    PortletURLImpl portletURL =
        new PortletURLImpl(request, portletId, themeDisplay.getPlid(), lifecycle);

    if (Validator.isNotNull(cacheability)) {
      portletURL.setCacheability(cacheability);
    }

    portletURL.setCopyCurrentRenderParameters(copyCurrentRenderParameters);

    if (doAsGroupId > 0) {
      portletURL.setDoAsGroupId(doAsGroupId);
    }

    if (doAsUserId > 0) {
      // portletURL.setDoAsUserId(doAsUserId);
    }

    if (Validator.isNotNull(doAsUserLanguageId)) {
      portletURL.setDoAsUserLanguageId(doAsUserLanguageId);
    }

    // portletURL.setEncrypt(encrypt);
    portletURL.setEscapeXml(escapeXml);

    if (lifecycle.equals(PortletRequest.ACTION_PHASE) && Validator.isNotNull(name)) {

      portletURL.setParameter(ActionRequest.ACTION_NAME, name);
    }

    portletURL.setPortletId(portletId);

    if (portletConfiguration) {
      String portletResource = ParamUtil.getString(request, "portletResource");
      String previewWidth = ParamUtil.getString(request, "previewWidth");

      portletURL.setParameter("struts_action", "/portlet_configuration/edit_configuration");
      portletURL.setParameter("returnToFullPageURL", returnToFullPageURL);
      portletURL.setParameter("portletResource", portletResource);
      portletURL.setParameter("previewWidth", previewWidth);
    }

    if (Validator.isNotNull(portletMode)) {
      portletURL.setPortletMode(PortletModeFactory.getPortletMode(portletMode));
    }

    if (Validator.isNotNull(resourceId)) {
      portletURL.setResourceID(resourceId);
    }

    if (!themeDisplay.isStateMaximized()) {
      if (Validator.isNotNull(returnToFullPageURL)) {
        portletURL.setParameter("returnToFullPageURL", returnToFullPageURL);
      }
    }

    portletURL.setSecure(secure);

    if (Validator.isNotNull(windowState)) {
      portletURL.setWindowState(WindowStateFactory.getWindowState(windowState));
    }

    String parameterMapString = ParamUtil.getString(request, "parameterMap");

    if (Validator.isNotNull(parameterMapString)) {
      Map<String, String> parameterMap =
          (Map<String, String>) JSONFactoryUtil.deserialize(parameterMapString);

      for (Map.Entry<String, String> entry : parameterMap.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        if ((key != null) && (value != null)) {
          portletURL.setParameter(key, value);
        }
      }
    }

    return portletURL.toString();
  }
  protected void doSaveEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

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

    String[] distributionScopeParts =
        StringUtil.split(ParamUtil.getString(actionRequest, "distributionScope"));

    long classNameId = 0;
    long classPK = 0;

    if (distributionScopeParts.length == 2) {
      classNameId = GetterUtil.getLong(distributionScopeParts[0]);

      if (classNameId > 0) {
        classPK = GetterUtil.getLong(distributionScopeParts[1]);
      }
    }

    String title = ParamUtil.getString(actionRequest, "title");
    String content = ParamUtil.getString(actionRequest, "content");
    String url = ParamUtil.getString(actionRequest, "url");
    String type = ParamUtil.getString(actionRequest, "type");

    int displayDateMonth = ParamUtil.getInteger(actionRequest, "displayDateMonth");
    int displayDateDay = ParamUtil.getInteger(actionRequest, "displayDateDay");
    int displayDateYear = ParamUtil.getInteger(actionRequest, "displayDateYear");
    int displayDateHour = ParamUtil.getInteger(actionRequest, "displayDateHour");
    int displayDateMinute = ParamUtil.getInteger(actionRequest, "displayDateMinute");
    int displayDateAmPm = ParamUtil.getInteger(actionRequest, "displayDateAmPm");

    if (displayDateAmPm == Calendar.PM) {
      displayDateHour += 12;
    }

    boolean displayImmediately = ParamUtil.getBoolean(actionRequest, "displayImmediately");

    int expirationDateMonth = ParamUtil.getInteger(actionRequest, "expirationDateMonth");
    int expirationDateDay = ParamUtil.getInteger(actionRequest, "expirationDateDay");
    int expirationDateYear = ParamUtil.getInteger(actionRequest, "expirationDateYear");
    int expirationDateHour = ParamUtil.getInteger(actionRequest, "expirationDateHour");
    int expirationDateMinute = ParamUtil.getInteger(actionRequest, "expirationDateMinute");
    int expirationDateAmPm = ParamUtil.getInteger(actionRequest, "expirationDateAmPm");

    if (expirationDateAmPm == Calendar.PM) {
      expirationDateHour += 12;
    }

    int priority = ParamUtil.getInteger(actionRequest, "priority");
    boolean alert = ParamUtil.getBoolean(actionRequest, "alert");

    if (entryId <= 0) {

      // Add entry

      AnnouncementsEntryServiceUtil.addEntry(
          themeDisplay.getPlid(),
          classNameId,
          classPK,
          title,
          content,
          url,
          type,
          displayDateMonth,
          displayDateDay,
          displayDateYear,
          displayDateHour,
          displayDateMinute,
          displayImmediately,
          expirationDateMonth,
          expirationDateDay,
          expirationDateYear,
          expirationDateHour,
          expirationDateMinute,
          priority,
          alert);
    } else {

      // Update entry

      AnnouncementsEntryServiceUtil.updateEntry(
          entryId,
          title,
          content,
          url,
          type,
          displayDateMonth,
          displayDateDay,
          displayDateYear,
          displayDateHour,
          displayDateMinute,
          expirationDateMonth,
          expirationDateDay,
          expirationDateYear,
          expirationDateHour,
          expirationDateMinute,
          priority);
    }
  }
Example #24
0
  @Override
  public void processAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

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

    try {
      if (cmd.equals(Constants.DELETE) || cmd.equals(Constants.DELETE_VERSIONS)) {

        deleteEntries(actionRequest, false);
      } else if (cmd.equals(Constants.EXPIRE)) {
        expireEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE)) {
        moveEntries(actionRequest);
      } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
        deleteEntries(actionRequest, true);
      }

      String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

      if (cmd.equals(Constants.DELETE_VERSIONS) && !ActionUtil.hasArticle(actionRequest)) {

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

        if (Validator.isNotNull(referringPortletResource)) {
          setForward(actionRequest, "portlet.journal.asset.add_asset_redirect");

          return;
        } else {
          ThemeDisplay themeDisplay =
              (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

          PortletURL portletURL =
              PortletURLFactoryUtil.create(
                  actionRequest,
                  portletConfig.getPortletName(),
                  themeDisplay.getPlid(),
                  PortletRequest.RENDER_PHASE);

          redirect = portletURL.toString();
        }
      }

      WindowState windowState = actionRequest.getWindowState();

      if (!windowState.equals(LiferayWindowState.POP_UP)) {
        sendRedirect(actionRequest, actionResponse);
      } else if (Validator.isNotNull(redirect)) {
        actionResponse.sendRedirect(redirect);
      }
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException
          || e instanceof NoSuchFolderException
          || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.journal.error");
      } else if (e instanceof DuplicateArticleIdException
          || e instanceof DuplicateFolderNameException
          || e instanceof NoSuchFolderException) {

        SessionErrors.add(actionRequest, e.getClass());
      } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        throw e;
      }
    }
  }
Example #25
0
  public static String getRefreshURL(HttpServletRequest request, ThemeDisplay themeDisplay) {

    StringBundler sb = new StringBundler(32);

    sb.append(themeDisplay.getPathMain());
    sb.append("/portal/render_portlet?p_l_id=");

    long plid = themeDisplay.getPlid();

    sb.append(plid);

    Portlet portlet = (Portlet) request.getAttribute(WebKeys.RENDER_PORTLET);

    String portletId = portlet.getPortletId();

    sb.append("&p_p_id=");
    sb.append(portletId);

    sb.append("&p_p_lifecycle=0&p_t_lifecycle=");
    sb.append(themeDisplay.getLifecycle());

    WindowState windowState = WindowState.NORMAL;

    if (themeDisplay.isStatePopUp()) {
      windowState = LiferayWindowState.POP_UP;
    } else {
      LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

      if (layoutTypePortlet.hasStateMaxPortletId(portletId)) {
        windowState = WindowState.MAXIMIZED;
      } else if (layoutTypePortlet.hasStateMinPortletId(portletId)) {
        windowState = WindowState.MINIMIZED;
      }
    }

    sb.append("&p_p_state=");
    sb.append(windowState);

    sb.append("&p_p_mode=view&p_p_col_id=");

    String columnId = (String) request.getAttribute(WebKeys.RENDER_PORTLET_COLUMN_ID);

    sb.append(columnId);

    Integer columnPos = (Integer) request.getAttribute(WebKeys.RENDER_PORTLET_COLUMN_POS);

    sb.append("&p_p_col_pos=");
    sb.append(columnPos);

    Integer columnCount = (Integer) request.getAttribute(WebKeys.RENDER_PORTLET_COLUMN_COUNT);

    sb.append("&p_p_col_count=");
    sb.append(columnCount);

    if (portlet.isStatic()) {
      sb.append("&p_p_static=1");

      if (portlet.isStaticStart()) {
        sb.append("&p_p_static_start=1");
      }
    }

    sb.append("&p_p_isolated=1");

    String doAsUserId = themeDisplay.getDoAsUserId();

    if (Validator.isNotNull(doAsUserId)) {
      sb.append("&doAsUserId=");
      sb.append(HttpUtil.encodeURL(doAsUserId));
    }

    String currentURL = PortalUtil.getCurrentURL(request);

    sb.append("&currentURL=");
    sb.append(HttpUtil.encodeURL(currentURL));

    String ppid = ParamUtil.getString(request, "p_p_id");

    if (ppid.equals(portletId)) {
      String namespace = PortalUtil.getPortletNamespace(portletId);

      Map<String, String[]> parameters = request.getParameterMap();

      for (Map.Entry<String, String[]> entry : parameters.entrySet()) {
        String name = entry.getKey();

        if (!PortalUtil.isReservedParameter(name)
            && !name.equals("currentURL")
            && !isRefreshURLReservedParameter(name, namespace)) {

          String[] values = entry.getValue();

          for (int i = 0; i < values.length; i++) {
            sb.append(StringPool.AMPERSAND);
            sb.append(name);
            sb.append(StringPool.EQUAL);
            sb.append(HttpUtil.encodeURL(values[i]));
          }
        }
      }
    }

    String outerPortletId = PortalUtil.getOuterPortletId(request);

    if (outerPortletId != null) {
      sb.append(StringPool.AMPERSAND);
      sb.append("p_o_p_id");
      sb.append(StringPool.EQUAL);
      sb.append(HttpUtil.encodeURL(outerPortletId));
    }

    return sb.toString();
  }
Example #26
0
  protected void compareVersions(RenderRequest renderRequest, RenderResponse renderResponse)
      throws Exception {

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

    long nodeId = ParamUtil.getLong(renderRequest, "nodeId");

    String title = ParamUtil.getString(renderRequest, "title");

    double sourceVersion = ParamUtil.getDouble(renderRequest, "sourceVersion");
    double targetVersion = ParamUtil.getDouble(renderRequest, "targetVersion");
    String type = ParamUtil.getString(renderRequest, "type", "escape");

    WikiPage sourcePage = WikiPageServiceUtil.getPage(nodeId, title, sourceVersion);
    WikiPage targetPage = WikiPageServiceUtil.getPage(nodeId, title, targetVersion);

    if (type.equals("html")) {
      WikiNode sourceNode = sourcePage.getNode();

      PortletURL viewPageURL = renderResponse.createRenderURL();

      viewPageURL.setParameter("struts_action", "/wiki/view");
      viewPageURL.setParameter("nodeName", sourceNode.getName());

      PortletURL editPageURL = renderResponse.createRenderURL();

      editPageURL.setParameter("struts_action", "/wiki/edit_page");
      editPageURL.setParameter("nodeId", String.valueOf(nodeId));
      editPageURL.setParameter("title", title);

      String attachmentURLPrefix =
          WikiUtil.getAttachmentURLPrefix(
              themeDisplay.getPathMain(), themeDisplay.getPlid(), nodeId, title);

      String htmlDiffResult =
          WikiUtil.diffHtml(sourcePage, targetPage, viewPageURL, editPageURL, attachmentURLPrefix);

      renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult);
    } else {
      String sourceContent = sourcePage.getContent();
      String targetContent = targetPage.getContent();

      sourceContent = WikiUtil.processContent(sourceContent);
      targetContent = WikiUtil.processContent(targetContent);

      if (type.equals("strip")) {
        sourceContent = HtmlUtil.extractText(sourceContent);
        targetContent = HtmlUtil.extractText(targetContent);
      } else {
        sourceContent = HtmlUtil.escape(sourceContent);
        targetContent = HtmlUtil.escape(targetContent);
      }

      List<DiffResult>[] diffResults =
          DiffUtil.diff(
              new UnsyncStringReader(sourceContent), new UnsyncStringReader(targetContent));

      renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
    }

    renderRequest.setAttribute(WebKeys.WIKI_NODE_ID, nodeId);
    renderRequest.setAttribute(WebKeys.TITLE, title);
    renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion);
  }
 @Override
 protected long getPlid(ThemeDisplay themeDisplay) {
   return themeDisplay.getPlid();
 }
  protected void sendEditArticleRedirect(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      JournalArticle article,
      String oldUrlTitle)
      throws Exception {

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

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

    int workflowAction =
        ParamUtil.getInteger(actionRequest, "workflowAction", WorkflowConstants.ACTION_PUBLISH);

    String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

    String namespace = PortalUtil.getPortletNamespace(portletId);

    if (Validator.isNotNull(oldUrlTitle)) {
      String oldRedirectParam = namespace + "redirect";

      String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false);

      if (Validator.isNotNull(oldRedirect)) {
        String newRedirect = HttpUtil.decodeURL(oldRedirect);

        newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, article.getUrlTitle());
        newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect");

        redirect = StringUtil.replace(redirect, oldRedirect, newRedirect);
      }
    }

    if ((actionName.equals("deleteArticle") || actionName.equals("deleteArticles"))
        && !ActionUtil.hasArticle(actionRequest)) {

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

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              actionRequest,
              themeDisplay.getPpid(),
              themeDisplay.getPlid(),
              PortletRequest.RENDER_PHASE);

      redirect = portletURL.toString();
    }

    if ((article != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

      redirect = getSaveAndContinueRedirect(actionRequest, article, redirect);

      if (actionName.equals("previewArticle")) {
        SessionMessages.add(actionRequest, "previewRequested");

        hideDefaultSuccessMessage(actionRequest);
      }
    } else {
      WindowState windowState = actionRequest.getWindowState();

      if (windowState.equals(LiferayWindowState.POP_UP)) {
        redirect = PortalUtil.escapeRedirect(redirect);

        if (Validator.isNotNull(redirect)) {
          if (actionName.equals("addArticle") && (article != null)) {
            redirect =
                HttpUtil.addParameter(
                    redirect, namespace + "className", JournalArticle.class.getName());
            redirect =
                HttpUtil.addParameter(
                    redirect,
                    namespace + "classPK",
                    JournalArticleAssetRenderer.getClassPK(article));
          }

          actionResponse.sendRedirect(redirect);
        }
      }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    HeaderCacheServletResponse headerCacheServletResponse = null;

    if (response instanceof HeaderCacheServletResponse) {
      headerCacheServletResponse = (HeaderCacheServletResponse) response;
    } else {
      headerCacheServletResponse = new HeaderCacheServletResponse(response);
    }

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

    Layout layout = themeDisplay.getLayout();

    Boolean layoutDefault = (Boolean) request.getAttribute(WebKeys.LAYOUT_DEFAULT);

    if ((layoutDefault != null) && (layoutDefault.booleanValue())) {
      Layout requestedLayout = (Layout) request.getAttribute(WebKeys.REQUESTED_LAYOUT);

      if (requestedLayout != null) {
        String redirectParam = "redirect";

        if (Validator.isNotNull(PropsValues.AUTH_LOGIN_PORTLET_NAME)) {
          redirectParam =
              PortalUtil.getPortletNamespace(PropsValues.AUTH_LOGIN_PORTLET_NAME) + redirectParam;
        }

        String authLoginURL = null;

        if (PrefsPropsUtil.getBoolean(
            themeDisplay.getCompanyId(),
            PropsKeys.CAS_AUTH_ENABLED,
            PropsValues.CAS_AUTH_ENABLED)) {

          authLoginURL = themeDisplay.getURLSignIn();
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PortalUtil.getCommunityLoginURL(themeDisplay);
        }

        if (Validator.isNull(authLoginURL)) {
          authLoginURL = PropsValues.AUTH_LOGIN_URL;
        }

        if (Validator.isNull(authLoginURL)) {
          PortletURL loginURL = LoginUtil.getLoginURL(request, themeDisplay.getPlid());

          authLoginURL = loginURL.toString();
        }

        String currentURL = PortalUtil.getCurrentURL(request);

        authLoginURL = HttpUtil.setParameter(authLoginURL, redirectParam, currentURL);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect requested layout to " + authLoginURL);
        }

        headerCacheServletResponse.sendRedirect(authLoginURL);
      } else {
        String redirect = PortalUtil.getLayoutURL(layout, themeDisplay);

        if (_log.isDebugEnabled()) {
          _log.debug("Redirect default layout to " + redirect);
        }

        headerCacheServletResponse.sendRedirect(redirect);
      }

      return null;
    }

    long plid = ParamUtil.getLong(request, "p_l_id");

    if (_log.isDebugEnabled()) {
      _log.debug("p_l_id is " + plid);
    }

    if (plid > 0) {
      ActionForward actionForward =
          processLayout(mapping, request, headerCacheServletResponse, plid);

      String contentType = response.getContentType();

      CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

      if (contentType != null) {
        response.setContentType(contentType);
      }

      return actionForward;
    } else {
      try {
        forwardLayout(request);

        return mapping.findForward(ActionConstants.COMMON_FORWARD_JSP);
      } catch (Exception e) {
        PortalUtil.sendError(e, request, headerCacheServletResponse);

        CacheResponseUtil.setHeaders(response, headerCacheServletResponse.getHeaders());

        return null;
      }
    }
  }
 @Override
 protected long getPlid(ThemeDisplay themeDisplay) throws PortalException {
   return themeDisplay.getPlid();
 }