@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;
  }
  @Override
  public void sendRedirect(String redirect) throws IOException {
    String portalURL = PortalUtil.getPortalURL(_request);

    if (redirect.charAt(0) == CharPool.SLASH) {
      if (Validator.isNotNull(portalURL)) {
        redirect = portalURL.concat(redirect);
      }
    }

    if (!CookieKeys.hasSessionId(_request) && redirect.startsWith(portalURL)) {

      redirect = PortalUtil.getURLWithSessionId(redirect, _request.getSession().getId());
    }

    _request.setAttribute(AbsoluteRedirectsResponse.class.getName(), redirect);

    super.sendRedirect(redirect);
  }
  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;
  }
Пример #4
0
  private String _getURL(
      HttpServletRequest request, boolean resetMaxState, boolean resetRenderParameters)
      throws PortalException, SystemException {

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

    if (resetMaxState) {
      Layout layout = themeDisplay.getLayout();

      LayoutTypePortlet layoutTypePortlet = null;

      if (layout.equals(this)) {
        layoutTypePortlet = themeDisplay.getLayoutTypePortlet();
      } else {
        try {
          layoutTypePortlet = _getLayoutTypePortletClone(request);
        } catch (IOException ioe) {
          _log.error("Unable to clone layout settings", ioe);

          layoutTypePortlet = (LayoutTypePortlet) getLayoutType();
        }
      }

      if (layoutTypePortlet.hasStateMax()) {
        String portletId = StringUtil.split(layoutTypePortlet.getStateMax())[0];

        PortletURLImpl portletURLImpl =
            new PortletURLImpl(request, portletId, getPlid(), PortletRequest.ACTION_PHASE);

        try {
          portletURLImpl.setWindowState(WindowState.NORMAL);
          portletURLImpl.setPortletMode(PortletMode.VIEW);
        } catch (PortletException pe) {
          throw new SystemException(pe);
        }

        portletURLImpl.setAnchor(false);

        if (PropsValues.LAYOUT_DEFAULT_P_L_RESET && !resetRenderParameters) {

          portletURLImpl.setParameter("p_l_reset", "0");
        } else if (!PropsValues.LAYOUT_DEFAULT_P_L_RESET && resetRenderParameters) {

          portletURLImpl.setParameter("p_l_reset", "1");
        }

        return portletURLImpl.toString();
      }
    }

    String portalURL = PortalUtil.getPortalURL(request);

    String url = PortalUtil.getLayoutURL(this, themeDisplay);

    if (!CookieKeys.hasSessionId(request)
        && (url.startsWith(portalURL) || url.startsWith(StringPool.SLASH))) {

      url = PortalUtil.getURLWithSessionId(url, request.getSession().getId());
    }

    if (!resetMaxState) {
      return url;
    }

    if (PropsValues.LAYOUT_DEFAULT_P_L_RESET && !resetRenderParameters) {
      url = HttpUtil.addParameter(url, "p_l_reset", 0);
    } else if (!PropsValues.LAYOUT_DEFAULT_P_L_RESET && resetRenderParameters) {

      url = HttpUtil.addParameter(url, "p_l_reset", 1);
    }

    return url;
  }
Пример #5
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;
  }