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

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


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

    // Extract the image style
    ImageStyle style = null;
    String styleId = StringUtils.trimToNull(request.getParameter(OPT_IMAGE_STYLE));
    if (styleId != null) {
      style = ImageStyleUtils.findStyle(styleId, site);
      if (style == null) {
        DispatchUtils.sendBadRequest("Image style '" + styleId + "' not found", request, response);
View Full Code Here


      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;
    }

    // Find the image style
    if (StringUtils.isNotBlank(imageStyle)) {
      style = ImageStyleUtils.findStyle(imageStyle, site);
      if (style != null) {
        linkToImage += "?style=" + style.getIdentifier();
        imageWidth = ImageStyleUtils.getStyledWidth(imageContent, style);
        imageHeight = ImageStyleUtils.getStyledHeight(imageContent, style);
        stashAndSetAttribute(ImageResourceTagExtraInfo.STYLE, style);
      } else {
        logger.warn("Image style '{}' not found to render on {}", imageStyle, request.getUrl());
View Full Code Here

    if (styleId == null)
      throw new IllegalArgumentException("Style identifier cannot be null");
    if (site == null)
      throw new IllegalArgumentException("Site cannot be null");
    for (Module m : site.getModules()) {
      ImageStyle style = m.getImageStyle(styleId);
      if (style != null)
        return style;
    }
    return null;
  }
View Full Code Here

    Document doc = docBuilder.parse(stylesDefinition.openStream());

    // Register the styles as services
    NodeList imagestyleNodes = XPathHelper.selectList(doc, "imagestyles/imagestyle", xpath);
    for (int i = 0; i < imagestyleNodes.getLength(); i++) {
      ImageStyle style = ImageStyleImpl.fromXml(imagestyleNodes.item(i), xpath);
      ServiceRegistration service = ctx.registerService(ImageStyle.class.getName(), style, null);
      styles.add(service);
      logger.debug("Registering image style '{}'", style);
    }
View Full Code Here

   *          the bundle context
   */
  private void unregisterImageStyles(BundleContext ctx) {
    logger.info("Unregistering weblounge ui imagestyles");
    for (ServiceRegistration service : styles) {
      ImageStyle style = (ImageStyle) ctx.getService(service.getReference());
      logger.debug("Unregistering image style '{}'", style);
      try {
        service.unregister();
      } catch (IllegalStateException e) {
        // Never mind, the service has been unregistered already
View Full Code Here

      // Try and read the file on disk
      if (definitionFile.isFile()) {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder;
        Document doc;
        ImageStyle style;
        try {
          docBuilder = docBuilderFactory.newDocumentBuilder();
          doc = docBuilder.parse(definitionFile);
          style = ImageStyleImpl.fromXml(doc.getFirstChild());

          // Is the style still the same?
          boolean stylesMatch = s.getWidth() == style.getWidth();
          stylesMatch = stylesMatch && s.getHeight() == style.getHeight();
          stylesMatch = stylesMatch && s.getScalingMode().equals(style.getScalingMode());
          stylesMatch = stylesMatch && s.getContexts().size() == style.getContexts().size();
          for (String ctx : s.getContexts()) {
            stylesMatch = stylesMatch && s.createPreview(ctx) == style.createPreview(ctx);
          }
          styleHasChanged = styleHasChanged || !stylesMatch;
        } catch (ParserConfigurationException e) {
          logger.error("Error setting up image style parser: {}", e.getMessage());
        } catch (SAXException e) {
View Full Code Here

   *
   * @see org.osgi.util.tracker.ServiceTracker#addingService(org.osgi.framework.ServiceReference)
   */
  @Override
  public Object addingService(ServiceReference reference) {
    ImageStyle style = (ImageStyle) context.getService(reference);
    logger.debug("Found image style '{}'", style.getIdentifier());
    styles.add(style);
    return style;
  }
View Full Code Here

   * @see org.osgi.util.tracker.ServiceTracker#removedService(org.osgi.framework.ServiceReference,
   *      java.lang.Object)
   */
  @Override
  public void removedService(ServiceReference reference, Object service) {
    ImageStyle style = (ImageStyle) service;
    logger.debug("Image style '{}' went away", style.getIdentifier());
    styles.remove(style);
    try {
      super.removedService(reference, service);
    } catch (IllegalStateException e) {
      // The service has been removed, probably due to bundle shutdown
View Full Code Here

    } catch (UnknownLanguageException e) {
      throw new WebApplicationException(Status.BAD_REQUEST);
    }

    // Search the site for the image style
    ImageStyle style = null;
    for (Module m : site.getModules()) {
      style = m.getImageStyle(styleId);
      if (style != null) {
        break;
      }
    }

    // Search the global styles
    if (style == null) {
      for (ImageStyle s : styles) {
        if (s.getIdentifier().equals(styleId)) {
          style = s;
          break;
        }
      }
    }

    // The image style was not found
    if (style == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Load the input stream from the scaled image
    File scaledResourceFile = ImageStyleUtils.getScaledFile(resource, language, style);

    // Is there an up-to-date, cached version on the client side?
    if (!ResourceUtils.hasChanged(request, scaledResourceFile)) {
      return Response.notModified().build();
    }

    ResourceURI resourceURI = resource.getURI();
    final ContentRepository contentRepository = getContentRepository(site, false);

    // When there is no scaling required, just return the original
    if (ImageScalingMode.None.equals(style.getScalingMode())) {
      return getResourceContent(request, resource, language);
    }

    // Find a serializer
    ResourceSerializer<?, ?> serializer = serializerService.getSerializerByType(resourceURI.getType());
View Full Code Here

    // Check the parameters
    if (styleId == null)
      throw new WebApplicationException(Status.BAD_REQUEST);

    // Search the site for the image style
    ImageStyle style = null;
    for (Module m : site.getModules()) {
      style = m.getImageStyle(styleId);
      if (style != null) {
        break;
      }
View Full Code Here

TOP

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

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.