@Test public void testDownloadAttachmentWithUnsupportedFileType() { XWikiAttachment attachment = mock(XWikiAttachment.class); when(attachment.getMimeType()).thenReturn("image/notsupported"); when(attachment.getDate()).thenReturn(new Date(0)); assertSame(attachment, plugin.downloadAttachment(attachment, new XWikiContext())); }
@Override public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) { if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment; } int height = -1; try { height = Integer.parseInt(context.getRequest().getParameter("height")); } catch (NumberFormatException e) { } int width = -1; try { width = Integer.parseInt(context.getRequest().getParameter("width")); } catch (NumberFormatException e) { } float quality = -1; try { quality = Float.parseFloat(context.getRequest().getParameter("quality")); } catch (NumberFormatException e) { } catch (NullPointerException e) { } if (height <= 0 && width <= 0 && quality < 0) { return attachment; } try { return downloadImage(attachment, width, height, quality, context); } catch (Exception e) { LOG.warn("Failed to transform image attachment.", e); return attachment; } }
ImagePlugin extends XWikiDefaultPlugin { @Override public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) { if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment; } int height = -1; try { height = Integer.parseInt(context.getRequest().getParameter("height")); } catch (NumberFormatException e) { } int width = -1; try { width = Integer.parseInt(context.getRequest().getParameter("width")); } catch (NumberFormatException e) { } float quality = -1; try { quality = Float.parseFloat(context.getRequest().getParameter("quality")); } catch (NumberFormatException e) { } catch (NullPointerException e) { } if (height <= 0 && width <= 0 && quality < 0) { return attachment; } try { return downloadImage(attachment, width, height, quality, context); } catch (Exception e) { LOG.warn("Failed to transform image attachment.", e); return attachment; } } }
ImagePlugin extends XWikiDefaultPlugin { @Override public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) { if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment; } int height = -1; try { height = Integer.parseInt(context.getRequest().getParameter("height")); } catch (NumberFormatException e) { } int width = -1; try { width = Integer.parseInt(context.getRequest().getParameter("width")); } catch (NumberFormatException e) { } float quality = -1; try { quality = Float.parseFloat(context.getRequest().getParameter("quality")); } catch (NumberFormatException e) { } catch (NullPointerException e) { } if (height <= 0 && width <= 0 && quality < 0) { return attachment; } try { return downloadImage(attachment, width, height, quality, context); } catch (Exception e) { LOG.warn("Failed to transform image attachment.", e); return attachment; } } ImagePlugin(String name, String className, XWikiContext context); }
ImagePlugin extends XWikiDefaultPlugin { @Override public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) { if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment; } int height = -1; try { height = Integer.parseInt(context.getRequest().getParameter("height")); } catch (NumberFormatException e) { } int width = -1; try { width = Integer.parseInt(context.getRequest().getParameter("width")); } catch (NumberFormatException e) { } float quality = -1; try { quality = Float.parseFloat(context.getRequest().getParameter("quality")); } catch (NumberFormatException e) { } catch (NullPointerException e) { } if (height <= 0 && width <= 0 && quality < 0) { return attachment; } try { return downloadImage(attachment, width, height, quality, context); } catch (Exception e) { LOG.warn("Failed to transform image attachment.", e); return attachment; } } ImagePlugin(String name, String className, XWikiContext context); @Override Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context); @Override String getName(); @Override void init(XWikiContext context); @Override void flushCache(); @Override XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context); int getWidth(XWikiAttachment attachment, XWikiContext context); int getHeight(XWikiAttachment attachment, XWikiContext context); }
ImagePlugin extends XWikiDefaultPlugin { @Override public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) { if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment; } int height = -1; try { height = Integer.parseInt(context.getRequest().getParameter("height")); } catch (NumberFormatException e) { } int width = -1; try { width = Integer.parseInt(context.getRequest().getParameter("width")); } catch (NumberFormatException e) { } float quality = -1; try { quality = Float.parseFloat(context.getRequest().getParameter("quality")); } catch (NumberFormatException e) { } catch (NullPointerException e) { } if (height <= 0 && width <= 0 && quality < 0) { return attachment; } try { return downloadImage(attachment, width, height, quality, context); } catch (Exception e) { LOG.warn("Failed to transform image attachment.", e); return attachment; } } ImagePlugin(String name, String className, XWikiContext context); @Override Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context); @Override String getName(); @Override void init(XWikiContext context); @Override void flushCache(); @Override XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context); int getWidth(XWikiAttachment attachment, XWikiContext context); int getHeight(XWikiAttachment attachment, XWikiContext context);  }