Package org.faceless.graph2.tag
Class EmbeddedXMLGraph
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.faceless.graph2.XMLGraph
-
- org.faceless.graph2.tag.EmbeddedXMLGraph
-
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
public class EmbeddedXMLGraph extends XMLGraph
An extension of XMLGraph which handles rollovers, and creates HTML which can be embedded in a webpage to display the generated Graph. This class is designed for use with the tag library and accompanyingGraphServlet
to serve the images, and it's rare that a user would need to be concerned with this class directly.In the event there is a need to call this class directly, here's an example showing broadly how to generate a bitmap graph, and the HTML to display it in a webpage. We say broadly because without the matching
GraphServlet
, JavaScript and (usually) tag library this example is non-functioningEmbeddedXMLGraph xml = new EmbeddedXMLGraph(); xml.parse(inputsource); String id = "graph1"; // if no ID attribute is specified in the XML String servlet = "/path/to/servlet/"; // URL that will serve the image we create StringWriter writer = new StringWriter(); ByteArrayOutputStream imageout = new ByteArrayOutputStream(); Embedder embedder = new PNGEmbedder(); xml.doEmbed(embedder, id, servlet, null, null, writer, imageout); writer.close(); imageout.close(); // The graph image was written to "imageout", the HTML to display it // was sent to "writer".
- Since:
- 2.4
-
-
Constructor Summary
Constructors Constructor Description EmbeddedXMLGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] buf, int off, int len)
void
doEmbed(Embedder embedder, String id, String servlet, Map<String,URL> pageresources, Map<URL,Object> contextresources, Writer pageout, OutputStream imageout)
Create the graph and the HTML required to embed it using the specifiedEmbedder
.void
endElement(String nspace, String tag, String qname)
String
getRequestedFormat()
Return the "format" attribute from the XML.void
startDocument()
void
startElement(String nspace, String tag, String qname, Attributes atts)
-
Methods inherited from class org.faceless.graph2.XMLGraph
endDocument, getDefaultResourceProvider, getFonts, getGraph, getHeight, getWidth, parse, parse, setDocumentLocator, setResourceProvider, warning
-
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
-
-
-
-
Method Detail
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Overrides:
startDocument
in classDefaultHandler
- Throws:
SAXException
-
startElement
public void startElement(String nspace, String tag, String qname, Attributes atts) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classXMLGraph
- Throws:
SAXException
-
endElement
public void endElement(String nspace, String tag, String qname) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classXMLGraph
- Throws:
SAXException
-
characters
public void characters(char[] buf, int off, int len) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classXMLGraph
- Throws:
SAXException
-
getRequestedFormat
public String getRequestedFormat()
Return the "format" attribute from the XML.- Since:
- 2.4.3
-
doEmbed
public void doEmbed(Embedder embedder, String id, String servlet, Map<String,URL> pageresources, Map<URL,Object> contextresources, Writer pageout, OutputStream imageout) throws IOException
Create the graph and the HTML required to embed it using the specifiedEmbedder
. The Embedder is initialized and itsEmbedder.convert()
method called. A new Embedder must be supplied to each call of this method - typically this is obtained by a call toEmbedderFactory.newEmbedder(java.lang.String)
method.- Parameters:
embedder
- the Embedder used to convert the Graph to HTML and binary outputid
- the ID to use for the graph, if one hasn't been specified with the "id" attributeservlet
- The full path to the graph servlet, eg "/app/servlet/GraphServlet/3/". The format of this String will depend on the Servlet that is serving the Graph.pageresources
- A mapping of String->URL of any resources that are specified on this for this page. Typically the keys are font names, the values URLscontextresources
- A map of URL->Object of any resources that apply beyond the life of the page containing this Graph. Typically the keys are URLs and the values Fonts. The map may be altered by this routine.pageout
- the Writer to write the HTML code toimageout
- the OutputStream to write the graph binary data to- Throws:
IOException
-
-