protected Resource createResource(Java2DUserResource resource) { boolean cacheable = isCacheableSet(resource.getClass()); boolean versioned = isVersionedSet(resource.getClass()); if (resource instanceof Java2DAnimatedUserResource) { Java2DAnimatedUserResource java2DAnimatedUserResource = (Java2DAnimatedUserResource) resource; return new Java2DAnimatedUserResourceWrapperImpl(java2DAnimatedUserResource, cacheable, versioned); } else { return new Java2DUserResourceWrapperImpl(resource, cacheable, versioned); } }
@Override protected Date getLastModified(FacesContext context) { return getWrapped().getLastModified(); }
protected void paintAndWrite(ImageOutputStream outputStream) throws IOException { Java2DUserResource resource = getWrapped(); ImageType imageType = resource.getImageType(); BufferedImage image = imageType.createImage(resource.getDimension()); Graphics2D g2d = null; try { g2d = createGraphics(image); resource.paint(g2d); ImageIO.write(image, imageType.getFormatName(), outputStream); } finally { if (g2d != null) { g2d.dispose(); } } }
@Override public String getRequestPath() { // detect unsupported types early checkSupportedFormat(getWrapped().getImageType()); return super.getRequestPath(); }
protected Integer getColorValueParameter(FacesContext context, String name, boolean useDefault) { Skin skin; if (useDefault) { skin = SkinFactory.getInstance(context).getDefaultSkin(context); } else { skin = SkinFactory.getInstance(context).getSkin(context); } return decodeColor((String) skin.getParameter(context, name)); }
public InputStream getInputStream() throws IOException { FastBufferOutputStream fbos = new FastBufferOutputStream(); ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(fbos); try { paintAndWrite(imageOutputStream); } finally { if (imageOutputStream != null) { try { imageOutputStream.close(); } catch (IOException e) { LOGGER.debug(e.getMessage(), e); } try { fbos.close(); } catch (IOException e) { // Swallow } } } ByteBuffer buffer = fbos.getFirstBuffer(); buffer.compact(); return new FastBufferInputStream(buffer); }
@Override protected Map<String, String> getWrappedResourceResponseHeaders() { return getWrapped().getResponseHeaders(); }
public String getContentType() { return getWrapped().getImageType().getMimeType(); }