Package ch.entwine.weblounge.common.content.image

Examples of ch.entwine.weblounge.common.content.image.ImageContent


      return SKIP_BODY;
    }

    ResourceURI uri = null;
    ImageResource image = null;
    ImageContent imageContent = null;
    String linkToImage = null;
    PrintWriter writer = null;

    try {
      writer = response.getWriter();

      for (int i = 0; i < result.getItems().length; i++) {
        uri = new ImageResourceURIImpl(site, null, result.getItems()[i].getId());
        if (repository.exists(uri)) {
          image = (ImageResource) repository.get(uri);
          language = LanguageUtils.getPreferredLanguage(image, request, site);
          image.switchTo(language);
          imageContent = image.getContent(language);

          linkToImage = UrlUtils.concat("/weblounge-images", image.getIdentifier(), imageContent.getFilename());

          // Find the image style

          writer.write("<a href=\"");
          writer.write(linkToImage + "?style=" + this.styleNormal); // normal
View Full Code Here


    // Try to add content items to non-existing resources
    String newfilename = "newimage.jpeg";
    String mimetype = "image/png";
    Language language = jpegContent.getLanguage();
    ImageContent updatedContent = new ImageContentImpl(newfilename, language, mimetype, 1000, 600);
    r = repository.putContent(imageURI, updatedContent, pngContentURL.openStream());
    ResourceContent c = r.getContent(language);
    assertEquals(pngFileSize, c.getSize());
    assertEquals(mimetype, c.getMimetype());
View Full Code Here

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

    // Load the image contents from the repository
    ImageContent imageContents = imageResource.getContent(language);

    // Add mime type header
    String contentType = imageContents.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);

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

    // Determine the resource's modification date
    long resourceLastModified = ResourceUtils.getModificationDate(imageResource, language).getTime();

    // Add last modified header
    response.setDateHeader("Last-Modified", resourceLastModified);

    // Add ETag header
    response.setHeader("ETag", ResourceUtils.getETagValue(imageResource));

    // Load the input stream from the repository
    InputStream imageInputStream = null;
    try {
      imageInputStream = contentRepository.getContent(imageURI, language);
    } catch (Throwable t) {
      logger.error("Error loading {} image '{}' from {}: {}", new Object[] {
          language,
          imageResource,
          contentRepository,
          t.getMessage() });
      logger.error(t.getMessage(), t);
      IOUtils.closeQuietly(imageInputStream);
      return false;
    }

    // Write the image back to the client
    try {
      response.setHeader("Content-Length", Long.toString(imageContents.getSize()));
      response.setHeader("Content-Disposition", "inline; filename=" + imageContents.getFilename());
      IOUtils.copy(imageInputStream, response.getOutputStream());
      response.getOutputStream().flush();
    } catch (EOFException e) {
      logger.debug("Error writing image '{}' back to client: connection closed by client", imageResource);
      return true;
View Full Code Here

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

    ImageResource image = null;
    ImageContent imageContent = null;
    ImageStyle style = null;
    String linkToImage = null;
    int imageWidth = 0;
    int imageHeight = 0;

    // Try to determine the language
    Language language = request.getLanguage();

    // Load the content
    try {
      image = (ImageResource) repository.get(uri);
      if (image == null) {
        logger.warn("Non existing image {} requested on {}", uri, request.getUrl());
        return SKIP_BODY;
      }
      image.switchTo(language);

      Language contentLanguage = null;
      contentLanguage = LanguageUtils.getPreferredContentLanguage(image, request, site);
      if (contentLanguage == null) {
        logger.warn("Image {} does not have suitable content", image);
        return SKIP_BODY;
      }

      imageContent = image.getContent(contentLanguage);
      if (imageContent == null)
        imageContent = image.getOriginalContent();
      imageWidth = imageContent.getWidth();
      imageHeight = imageContent.getHeight();
      // TODO: Make this a reference rather than a hard coded string
      linkToImage = UrlUtils.concat("/weblounge-images", image.getIdentifier(), language.getIdentifier());
    } catch (ContentRepositoryException e) {
      logger.warn("Error trying to load image " + uri + " on " + request.getUrl() + ": " + e.getMessage(), e);
      return SKIP_BODY;
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 ImageContent) {
      ImageContent content = (ImageContent) obj;
      if (width != content.getWidth())
        return false;
      if (height != content.getHeight())
        return false;
      if (dateTaken != null) {
        if (!dateTaken.equals(content.getDateTaken()))
          return false;
      } else {
        if (content.getDateTaken() != null)
          return false;
      }
      if (!StringUtils.trimToEmpty(location).equals(StringUtils.trimToEmpty(content.getLocation())))
        return false;
      if (gpsLat != content.getGpsLat())
        return false;
      if (gpsLong != content.getGpsLong())
        return false;
      if (filmspeed != content.getFilmspeed())
        return false;
      if (fnumber != content.getFNumber())
        return false;
      if (focalWidth != content.getFocalWidth())
        return false;
      if (exposureTime != content.getExposureTime())
        return false;
      return super.equals(content);
    }
    return false;
  }
View Full Code Here

   */
  public ImageContent createFromContent(InputStream is, User user,
      Language language, long size, String fileName, String mimeType)
      throws IOException {

    ImageContent content = new ImageContentImpl(fileName, language, mimeType);

    // Use the logged in user as the author
    content.setCreator(user);

    // Set the creation date
    content.setCreationDate(new Date());

    MemoryCacheSeekableStream mcss = new MemoryCacheSeekableStream(is);
    UnclosableInputStream bis = new UnclosableInputStream(mcss);

    // Read the Exif metadata (if available)
    try {
      readExifMetadata(content, bis);
    } catch (Throwable t) {
      logger.warn("Error extracting Exif metadata from {}: {}", fileName, t.getMessage());
    }

    // Read the JAI metadata
    if (content.getWidth() <= 0 || content.getHeight() <= 0) {
      try {
        mcss.seek(0);
        readJAIMetadata(content, mcss);
      } catch (Throwable t) {
        logger.warn("Error extracting metadata using java advanced imaging (jai) from {}: {}", fileName, t.getMessage());
View Full Code Here

   * .
   */
  @Test
  public void testCreateFromContent() throws Exception {
    InputStream is = ImageContentReaderTest.class.getResourceAsStream("/" + fileName);
    ImageContent content = reader.createFromContent(is, user, language, size, fileName, mimeType);
    assertEquals(imageWidth, content.getWidth());
    assertEquals(imageHeight, content.getHeight());
  }
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.common.content.image.ImageContent

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.