@Test @Category(UnitTest.class) public void testFormatVariants() throws Exception { ImageRenderer renderer = (ImageRenderer) ImageHandlerFactory.getHandler("png", ImageRenderer.class); assertTrue(renderer instanceof PngImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/png")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("PNG", ImageRenderer.class); assertTrue(renderer instanceof PngImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/png")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("jpg", ImageRenderer.class); assertTrue(renderer instanceof JpegImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/jpeg")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("JPG", ImageRenderer.class); assertTrue(renderer instanceof JpegImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/jpeg")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("jpeg", ImageRenderer.class); assertTrue(renderer instanceof JpegImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/jpeg")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("JPEG", ImageRenderer.class); assertTrue(renderer instanceof JpegImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/jpeg")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("tif", ImageRenderer.class); assertTrue(renderer instanceof TiffImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/tiff")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("TIF", ImageRenderer.class); assertTrue(renderer instanceof TiffImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/tiff")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("tiff", ImageRenderer.class); assertTrue(renderer instanceof TiffImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/tiff")); renderer = (ImageRenderer) ImageHandlerFactory.getHandler("TIFF", ImageRenderer.class); assertTrue(renderer instanceof TiffImageRenderer); assertTrue(renderer.getMimeTypes()[0].equals("image/tiff")); ColorScaleApplier applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("png", ColorScaleApplier.class); assertTrue(applier instanceof PngColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/png")); applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("PNG", ColorScaleApplier.class); assertTrue(applier instanceof PngColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/png")); applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("jpg", ColorScaleApplier.class); assertTrue(applier instanceof JpegColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/jpeg")); applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("JPG", ColorScaleApplier.class); assertTrue(applier instanceof JpegColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/jpeg")); applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("jpeg", ColorScaleApplier.class); assertTrue(applier instanceof JpegColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/jpeg")); applier = (ColorScaleApplier) ImageHandlerFactory.getHandler("JPEG", ColorScaleApplier.class); assertTrue(applier instanceof JpegColorScaleApplier); assertTrue(applier.getMimeTypes()[0].equals("image/jpeg")); ImageResponseWriter writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("png", ImageResponseWriter.class); assertTrue(writer instanceof PngImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/png")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("PNG", ImageResponseWriter.class); assertTrue(writer instanceof PngImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/png")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("jpg", ImageResponseWriter.class); assertTrue(writer instanceof JpegImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/jpeg")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("JPG", ImageResponseWriter.class); assertTrue(writer instanceof JpegImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/jpeg")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("jpeg", ImageResponseWriter.class); assertTrue(writer instanceof JpegImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/jpeg")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("JPEG", ImageResponseWriter.class); assertTrue(writer instanceof JpegImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/jpeg")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("tif", ImageResponseWriter.class); assertTrue(writer instanceof TiffImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/tiff")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("TIF", ImageResponseWriter.class); assertTrue(writer instanceof TiffImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/tiff")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("tiff", ImageResponseWriter.class); assertTrue(writer instanceof TiffImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/tiff")); writer = (ImageResponseWriter) ImageHandlerFactory.getHandler("TIFF", ImageResponseWriter.class); assertTrue(writer instanceof TiffImageResponseWriter); assertTrue(writer.getMimeTypes()[0].equals("image/tiff")); }
@SuppressWarnings("unused") public static Object getHandler(String imageFormat, Class<?> handlerType) throws IllegalAccessException, InstantiationException { if (org.apache.commons.lang3.StringUtils.isEmpty(imageFormat)) { throw new IllegalArgumentException("NULL image format requested."); } log.debug("Requested image format: {}", imageFormat); imageFormat = imageFormat.toLowerCase(); if (handlerType == null) { throw new IllegalArgumentException("NULL handler type requested."); } log.debug("Requested handler type: {}", handlerType.getName()); if (mimeTypeHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = mimeTypeHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } if (imageFormatHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = imageFormatHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } throw new IllegalArgumentException("Unsupported image format - " + imageFormat); }
ImageHandlerFactory { @SuppressWarnings("unused") public static Object getHandler(String imageFormat, Class<?> handlerType) throws IllegalAccessException, InstantiationException { if (org.apache.commons.lang3.StringUtils.isEmpty(imageFormat)) { throw new IllegalArgumentException("NULL image format requested."); } log.debug("Requested image format: {}", imageFormat); imageFormat = imageFormat.toLowerCase(); if (handlerType == null) { throw new IllegalArgumentException("NULL handler type requested."); } log.debug("Requested handler type: {}", handlerType.getName()); if (mimeTypeHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = mimeTypeHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } if (imageFormatHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = imageFormatHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } throw new IllegalArgumentException("Unsupported image format - " + imageFormat); } }
ImageHandlerFactory { @SuppressWarnings("unused") public static Object getHandler(String imageFormat, Class<?> handlerType) throws IllegalAccessException, InstantiationException { if (org.apache.commons.lang3.StringUtils.isEmpty(imageFormat)) { throw new IllegalArgumentException("NULL image format requested."); } log.debug("Requested image format: {}", imageFormat); imageFormat = imageFormat.toLowerCase(); if (handlerType == null) { throw new IllegalArgumentException("NULL handler type requested."); } log.debug("Requested handler type: {}", handlerType.getName()); if (mimeTypeHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = mimeTypeHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } if (imageFormatHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = imageFormatHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } throw new IllegalArgumentException("Unsupported image format - " + imageFormat); }  }
ImageHandlerFactory { @SuppressWarnings("unused") public static Object getHandler(String imageFormat, Class<?> handlerType) throws IllegalAccessException, InstantiationException { if (org.apache.commons.lang3.StringUtils.isEmpty(imageFormat)) { throw new IllegalArgumentException("NULL image format requested."); } log.debug("Requested image format: {}", imageFormat); imageFormat = imageFormat.toLowerCase(); if (handlerType == null) { throw new IllegalArgumentException("NULL handler type requested."); } log.debug("Requested handler type: {}", handlerType.getName()); if (mimeTypeHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = mimeTypeHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } if (imageFormatHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = imageFormatHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } throw new IllegalArgumentException("Unsupported image format - " + imageFormat); }  @SuppressWarnings("unused") static Object getHandler(String imageFormat, Class<?> handlerType); static String[] getImageFormats(Class<?> handlerType); static String[] getMimeFormats(Class<?> handlerType); }
ImageHandlerFactory { @SuppressWarnings("unused") public static Object getHandler(String imageFormat, Class<?> handlerType) throws IllegalAccessException, InstantiationException { if (org.apache.commons.lang3.StringUtils.isEmpty(imageFormat)) { throw new IllegalArgumentException("NULL image format requested."); } log.debug("Requested image format: {}", imageFormat); imageFormat = imageFormat.toLowerCase(); if (handlerType == null) { throw new IllegalArgumentException("NULL handler type requested."); } log.debug("Requested handler type: {}", handlerType.getName()); if (mimeTypeHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = mimeTypeHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } if (imageFormatHandlers.containsKey(handlerType)) { Map<String, Class<?>> handlers = imageFormatHandlers.get(handlerType); if (handlers.containsKey(imageFormat)) { Object cl; cl = handlers.get(imageFormat.toLowerCase()).newInstance(); return cl; } } throw new IllegalArgumentException("Unsupported image format - " + imageFormat); }  @SuppressWarnings("unused") static Object getHandler(String imageFormat, Class<?> handlerType); static String[] getImageFormats(Class<?> handlerType); static String[] getMimeFormats(Class<?> handlerType);  }