@Test @Category(UnitTest.class) public void testBadFormat() throws Exception { try { ImageHandlerFactory.getHandler("abc", ImageRenderer.class); assertFalse(false); } catch (Exception e) { assertEquals(e.getMessage(), "Unsupported image format - abc"); } try { ImageHandlerFactory.getHandler("tif", ColorScaleApplier.class); assertFalse(false); } catch (Exception e) { assertEquals(e.getMessage(), "Unsupported image format - tif"); } try { ImageHandlerFactory.getHandler("tiff", ColorScaleApplier.class); assertFalse(false); } catch (Exception e) { assertEquals(e.getMessage(), "Unsupported image format - 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);  }