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;
  }
  @Override
  protected long getLastModified(HttpServletRequest request) {
    try {
      Date modifiedDate = null;

      Image image = getImage(request, true);

      if (image != null) {
        modifiedDate = image.getModifiedDate();
      } else {
        String path = HttpUtil.fixPath(request.getPathInfo());

        String[] pathArray = StringUtil.split(path, CharPool.SLASH);

        if (pathArray.length == 0) {
          return -1;
        }

        if (pathArray[0].equals("language")) {
          return -1;
        }

        FileEntry fileEntry = null;

        try {
          fileEntry = getFileEntry(pathArray);
        } catch (Exception e) {
        }

        if (fileEntry == null) {
          return -1;
        } else {
          String version = ParamUtil.getString(request, "version");

          if (Validator.isNotNull(version)) {
            FileVersion fileVersion = fileEntry.getFileVersion(version);

            modifiedDate = fileVersion.getModifiedDate();
          } else {
            modifiedDate = fileEntry.getModifiedDate();
          }
        }
      }

      if (modifiedDate == null) {
        modifiedDate = PortalUtil.getUptime();
      }

      // Round down and remove milliseconds

      return (modifiedDate.getTime() / 1000) * 1000;
    } catch (PrincipalException pe) {
      if (_log.isWarnEnabled()) {
        _log.warn(pe, pe);
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return -1;
  }
Exemplo n.º 3
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;
  }