org.faceless.graph2.tag
Class EmbeddedXMLGraph

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.faceless.graph2.XMLGraph
          extended by 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 accompanying GraphServlet 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-functioning

 EmbeddedXMLGraph 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

Field Summary
 
Fields inherited from class org.faceless.graph2.XMLGraph
locator, NAMESPACE
 
Constructor Summary
EmbeddedXMLGraph()
           
 
Method Summary
 void characters(char[] buf, int off, int len)
           
 void doEmbed(Embedder embedder, String id, String servlet, Map pageresources, Map contextresources, Writer pageout, OutputStream imageout)
          Create the graph and the HTML required to embed it using the specified Embedder.
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmbeddedXMLGraph

public EmbeddedXMLGraph()
Method Detail

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class DefaultHandler
Throws:
SAXException

startElement

public void startElement(String nspace,
                         String tag,
                         String qname,
                         Attributes atts)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class XMLGraph
Throws:
SAXException

endElement

public void endElement(String nspace,
                       String tag,
                       String qname)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class XMLGraph
Throws:
SAXException

characters

public void characters(char[] buf,
                       int off,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class XMLGraph
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 pageresources,
                    Map contextresources,
                    Writer pageout,
                    OutputStream imageout)
             throws IOException
Create the graph and the HTML required to embed it using the specified Embedder. The Embedder is initialized and its Embedder.convert() method called. A new Embedder must be supplied to each call of this method - typically this is obtained by a call to EmbedderFactory.newEmbedder(java.lang.String) method.

Parameters:
embedder - the Embedder used to convert the Graph to HTML and binary output
id - the ID to use for the graph, if one hasn't been specified with the "id" attribute
servlet - 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 URLs
contextresources - 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 to
imageout - the OutputStream to write the graph binary data to
Throws:
IOException


Copyright © 2001-2011 Big Faceless Organization