Пример #1
0
  protected void remoteServeResource(
      ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

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

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setRequestParameters(resourceRequest, resourceResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2");
    addOAuthParameter(oAuthRequest, "p_p_resource_id", resourceRequest.getResourceID());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    String contentType = response.getHeader(HttpHeaders.CONTENT_TYPE);

    if (contentType.startsWith(ContentTypes.APPLICATION_OCTET_STREAM)) {
      String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION);
      int contentLength = GetterUtil.getInteger(response.getHeader(HttpHeaders.CONTENT_LENGTH));

      PortletResponseUtil.sendFile(
          resourceRequest,
          resourceResponse,
          getFileName(contentDisposition),
          response.getStream(),
          contentLength,
          contentType,
          HttpHeaders.CONTENT_DISPOSITION_ATTACHMENT);
    } else {
      PortletResponseUtil.write(resourceResponse, response.getStream());
    }
  }
Пример #2
0
  public void serveKBArticleRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws Exception {

    if (!PortalUtil.isRSSFeedsEnabled()) {
      PortalUtil.sendRSSFeedsDisabledError(resourceRequest, resourceResponse);

      return;
    }

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

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

    int rssDelta = ParamUtil.getInteger(resourceRequest, "rssDelta");
    String rssDisplayStyle = ParamUtil.getString(resourceRequest, "rssDisplayStyle");
    String rssFormat = ParamUtil.getString(resourceRequest, "rssFormat");

    String rss =
        KBArticleServiceUtil.getKBArticleRSS(
            resourcePrimKey,
            WorkflowConstants.STATUS_APPROVED,
            rssDelta,
            rssDisplayStyle,
            rssFormat,
            themeDisplay);

    PortletResponseUtil.sendFile(
        resourceRequest,
        resourceResponse,
        null,
        rss.getBytes(StringPool.UTF8),
        ContentTypes.TEXT_XML_UTF8);
  }
Пример #3
0
  public void serveAttachment(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws Exception {

    long companyId = ParamUtil.getLong(resourceRequest, "companyId");
    String fileName = ParamUtil.getString(resourceRequest, "fileName");

    String shortFileName = FileUtil.getShortFileName(fileName);
    InputStream is = DLStoreUtil.getFileAsStream(companyId, CompanyConstants.SYSTEM, fileName);
    String contentType = MimeTypesUtil.getContentType(fileName);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, shortFileName, is, contentType);
  }
  protected void serveTempImageFile(MimeResponse mimeResponse, InputStream tempImageStream)
      throws Exception {

    ImageBag imageBag = ImageToolUtil.read(tempImageStream);

    byte[] bytes = ImageToolUtil.getBytes(imageBag.getRenderedImage(), imageBag.getType());

    String contentType = MimeTypesUtil.getExtensionContentType(imageBag.getType());

    mimeResponse.setContentType(contentType);

    PortletResponseUtil.write(mimeResponse, bytes);
  }
Пример #5
0
  public void serveAttachment(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws Exception {

    long fileEntryId = ParamUtil.getLong(resourceRequest, "fileEntryId");

    FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);

    PortletResponseUtil.sendFile(
        resourceRequest,
        resourceResponse,
        fileEntry.getTitle(),
        fileEntry.getContentStream(),
        fileEntry.getMimeType());
  }
  @Override
  public boolean serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
      throws PortletException {

    if (!(resourceResponse instanceof MimeResponse)) {
      return false;
    }

    String fileName = getFileName(resourceRequest);

    try {
      PortletResponseUtil.sendFile(
          resourceRequest,
          resourceResponse,
          fileName,
          getPropertiesAsBytes(resourceRequest, resourceResponse),
          ContentTypes.TEXT_XML_UTF8);
    } catch (Exception e) {
      throw new PortletException(e);
    }

    return true;
  }