Package ch.entwine.weblounge.common.content.file

Examples of ch.entwine.weblounge.common.content.file.FileContent


      DispatchUtils.sendNotModified(request, response);
      return true;
    }

    // Add mime type header
    FileContent content = fileResource.getContent(language);

    // If the content is hosted externally, send a redirect and be done with it
    if (content.getExternalLocation() != null) {
      try {
        response.sendRedirect(content.getExternalLocation().toExternalForm());
      } catch (IOException e) {
        logger.debug("Client ignore redirect to {}", content.getExternalLocation());
      }
      return true;
    }

    String contentType = content.getMimetype();
    if (contentType == null)
      contentType = MediaType.APPLICATION_OCTET_STREAM;

    // Set the content type
    String characterEncoding = response.getCharacterEncoding();
    if (StringUtils.isNotBlank(characterEncoding))
      response.setContentType(contentType + "; charset=" + characterEncoding.toLowerCase());
    else
      response.setContentType(contentType);

    // Browser caches and proxies are allowed to keep a copy
    response.setHeader("Cache-Control", "public, max-age=" + revalidationTime);

    // Add last modified header
    response.setDateHeader("Last-Modified", ResourceUtils.getModificationDate(fileResource, language).getTime());

    // Add ETag header
    String eTag = ResourceUtils.getETagValue(fileResource);
    response.setHeader("ETag", eTag);

    // Set the Expires header
    response.setDateHeader("Expires", expirationDate);

    // Add content disposition header
    response.setHeader("Content-Disposition", "inline; filename=" + content.getFilename());

    // Add content size
    response.setHeader("Content-Length", Long.toString(content.getSize()));

    // Write the file back to the response
    InputStream fileContents = null;
    try {
      fileContents = contentRepository.getContent(fileURI, language);
View Full Code Here


      logger.error("Error trying to look up file {} from {}", fileId, repository);
      return SKIP_BODY;
    }

    FileResource file = null;
    FileContent fileContent = null;

    // Determine the languages
    Language language = request.getLanguage();

    // Store the result in the jsp page context
View Full Code Here

   * @see ch.entwine.weblounge.common.impl.content.ResourceContentImpl#equals(java.lang.Object)
   */
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof FileContent) {
      FileContent content = (FileContent) obj;
      if (size != content.getSize())
        return false;
      return super.equals(content);
    }
    return false;
  }
View Full Code Here

      }
    });

    // Set file-related response information
    if (resourceContent instanceof FileContent) {
      FileContent fileContent = (FileContent) resourceContent;
      if (fileContent.getMimetype() != null)
        response.type(fileContent.getMimetype());
      else
        response.type(MediaType.APPLICATION_OCTET_STREAM);
      if (fileContent.getSize() > 0)
        response.header("Content-Length", fileContent.getSize());
    }

    // Add an e-tag and send the response
    response.header("Content-Disposition", "inline; filename=" + resource.getContent(language).getFilename());
    response.tag(ResourceUtils.getETagValue(resource));
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.file.FileContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.