@Test public void testImageThumbnail() throws IOException { context.currentResource("/content/apache/sling-apache-org/index/apache.png"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); TransformationImpl transformation = new TransformationImpl(); List<Resource> handlers = new ArrayList<>(); Map<String, Object> size = new HashMap<>(); size.put(SizeHandler.PN_WIDTH, 200); size.put(SizeHandler.PN_HEIGHT, 200); size.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "sling-cms/components/caconfig/transformationhandlers/size"); handlers.add(new MockResource("/conf", size, Mockito.mock(ResourceResolver.class))); Map<String, Object> crop = new HashMap<>(); crop.put(CropHandler.PN_POSITION, "center"); crop.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "sling-cms/components/caconfig/transformationhandlers/crop"); handlers.add(new MockResource("/conf", crop, Mockito.mock(ResourceResolver.class))); transformation.sethandlers(handlers); transformer.transform(context.currentResource(), transformation, OutputFileFormat.PNG, baos); assertNotNull(baos); IOUtils.copy(new ByteArrayInputStream(baos.toByteArray()), new File("src/test/resources/thumbnail.png")); }
@Override public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out) throws IOException { ThumbnailProvider provider = getThumbnailProvider(resource); log.debug("Using thumbnail provider {} for resource {}", provider, resource); Builder<? extends InputStream> builder = Thumbnails.of(provider.getThumbnail(resource)); for (Resource config : transformation.getHandlers()) { log.debug("Handling command: {}", config); TransformationHandler handler = getTransformationHandler(config.getResourceType()); if (handler != null) { log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(), config.getName()); handler.handle(builder, config); } else { log.info("No handler found for: {}", config.getName()); } } builder.outputFormat(format.toString()); builder.toOutputStream(out); }
TransformerImpl implements Transformer { @Override public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out) throws IOException { ThumbnailProvider provider = getThumbnailProvider(resource); log.debug("Using thumbnail provider {} for resource {}", provider, resource); Builder<? extends InputStream> builder = Thumbnails.of(provider.getThumbnail(resource)); for (Resource config : transformation.getHandlers()) { log.debug("Handling command: {}", config); TransformationHandler handler = getTransformationHandler(config.getResourceType()); if (handler != null) { log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(), config.getName()); handler.handle(builder, config); } else { log.info("No handler found for: {}", config.getName()); } } builder.outputFormat(format.toString()); builder.toOutputStream(out); } }
TransformerImpl implements Transformer { @Override public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out) throws IOException { ThumbnailProvider provider = getThumbnailProvider(resource); log.debug("Using thumbnail provider {} for resource {}", provider, resource); Builder<? extends InputStream> builder = Thumbnails.of(provider.getThumbnail(resource)); for (Resource config : transformation.getHandlers()) { log.debug("Handling command: {}", config); TransformationHandler handler = getTransformationHandler(config.getResourceType()); if (handler != null) { log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(), config.getName()); handler.handle(builder, config); } else { log.info("No handler found for: {}", config.getName()); } } builder.outputFormat(format.toString()); builder.toOutputStream(out); }  }
TransformerImpl implements Transformer { @Override public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out) throws IOException { ThumbnailProvider provider = getThumbnailProvider(resource); log.debug("Using thumbnail provider {} for resource {}", provider, resource); Builder<? extends InputStream> builder = Thumbnails.of(provider.getThumbnail(resource)); for (Resource config : transformation.getHandlers()) { log.debug("Handling command: {}", config); TransformationHandler handler = getTransformationHandler(config.getResourceType()); if (handler != null) { log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(), config.getName()); handler.handle(builder, config); } else { log.info("No handler found for: {}", config.getName()); } } builder.outputFormat(format.toString()); builder.toOutputStream(out); }  void addThumbnailProvider(ThumbnailProvider thumbnailProvider); void addTransformationHandler(TransformationHandler handler); List<TransformationHandler> getHandlers(); List<ThumbnailProvider> getThumbnailProviders(); TransformationHandler getTransformationHandler(String resourceType); @Override void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out); }
TransformerImpl implements Transformer { @Override public void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out) throws IOException { ThumbnailProvider provider = getThumbnailProvider(resource); log.debug("Using thumbnail provider {} for resource {}", provider, resource); Builder<? extends InputStream> builder = Thumbnails.of(provider.getThumbnail(resource)); for (Resource config : transformation.getHandlers()) { log.debug("Handling command: {}", config); TransformationHandler handler = getTransformationHandler(config.getResourceType()); if (handler != null) { log.debug("Invoking handler {} for command {}", handler.getClass().getCanonicalName(), config.getName()); handler.handle(builder, config); } else { log.info("No handler found for: {}", config.getName()); } } builder.outputFormat(format.toString()); builder.toOutputStream(out); }  void addThumbnailProvider(ThumbnailProvider thumbnailProvider); void addTransformationHandler(TransformationHandler handler); List<TransformationHandler> getHandlers(); List<ThumbnailProvider> getThumbnailProviders(); TransformationHandler getTransformationHandler(String resourceType); @Override void transform(Resource resource, Transformation transformation, OutputFileFormat format, OutputStream out);  }