Package org.faceless.graph2.tag
Interface EmbedderFactory
-
public interface EmbedderFactory
Factory interface for a factory returning an
Factories are recognised automatically by the context whenever it's reloaded - so installing a custom factory is as simple as writing your own and placing it in a Jar in the classpath. Here's a simple example showing how to add a handler for JPEG images (note this is just an example - JPEG is a poor second to PNG for this sort of image). First, compile the following source file:Embedder
object. Any EmbedderFactories available to the Context will be checked to see if they match the "format" attribute of the XML, and if they do anEmbedder
will be created.package mypackage; import java.io.*; import javax.imageio.*; import org.faceless.graph2.tag.*; public class JPEGEmbedderFactory extends EmbedderFactory { public boolean matches(String format) { return "jpeg".equals(format); } public Embedder newEmbedder() { return new PNGEmbedder() { public String getMIMEType() { return "image/jpeg"; } public void writeBitmap(ImageOutput img, OutputStream out) throws IOException { ImageIO.write(img.getImage(), "JPEG", out); } }; } }
Second, create the following file exactly as it is here:# List of EmbedderFactories in this Jar mypackage.JPEGEmbedderFactory
Finally, add this file asMETA-INF/services/org.faceless.graph2.tag.EmbedderFactories
along with the class files created above to a Jar file. The Jar should contain the following files.mypackage/JPEGEmbedderFactory.class mypackage/JPEGEmbedderFactory$1.class META-INF/services/org.faceless.graph2.tag.EmbedderFactories
Make the Jar available to your web application and reload the context. You'll then be able to addformat="jpeg"
as an attribute to your graphs to create JPEG images.- Since:
- 2.4
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
matches(String type)
Return true if this Factory mathches the specified typeEmbedder
newEmbedder(String type)
Create a new Embedder object
-