org.faceless.graph2
Class XMLGraph

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by org.faceless.graph2.XMLGraph
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler
Direct Known Subclasses:
EmbeddedXMLGraph

public class XMLGraph
extends DefaultHandler

The XMLGraph class provides a simple XML interface into the Graph library. At it's simplest, it can be used as follows to parse an InputStream containing XML and convert that to a PNG image written to an OutputStream

 XMLGraph parser = new XMLGraph();
 parser.parse(new InputSource(inputstream));
 Graph graph = parser.getGraph();
 ImageOutput out = new ImageOutput(parser.getWidth(), parser.getHeight());
 graph.draw(out);
 out.writePNG(outputstream, 256);
 
Alternatively, as this class implements ContentHandler users may extend the class as necessary or use it as the end stage of an XSL transformation.


Field Summary
protected  Locator locator
          The Locator object, as set by setDocumentLocator(org.xml.sax.Locator)
static String NAMESPACE
          The namespace used for the XML parsed by this class.
 
Constructor Summary
XMLGraph()
          Create a new XMLGraph parser
 
Method Summary
 void characters(char[] buf, int off, int len)
           
 void endDocument()
           
 void endElement(String nspace, String tag, String qname)
           
static XMLGraphResourceProvider getDefaultResourceProvider(String format)
          Return a XMLGraphResourceProvider appropriate for the specified format
 Set getFonts()
          Return the list of font names used in the graph.
 Graph getGraph()
          Return the graph generated by the parse(org.xml.sax.InputSource) method
 int getHeight()
          Return the width of the graph, as specified in the XML with the height attribute
 int getWidth()
          Return the width of the graph, as specified in the XML with the width attribute
 void parse(InputSource source)
          Parse the specified InputSource using any available XMLReader
 void parse(InputSource source, XMLReader reader)
          Parse the specified InputSource using the specified XMLReader.
 void setDocumentLocator(Locator locator)
           
 void setResourceProvider(XMLGraphResourceProvider p)
           Set the XMLGraphResourceProvider implementation to use for providing resources when parsing the graph XML.
 void startElement(String nspace, String tag, String qname, Attributes atts)
           
 void warning(SAXParseException e)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMESPACE

public static final String NAMESPACE
The namespace used for the XML parsed by this class.

Since:
2.0.3
See Also:
Constant Field Values

locator

protected Locator locator
The Locator object, as set by setDocumentLocator(org.xml.sax.Locator)

Constructor Detail

XMLGraph

public XMLGraph()
Create a new XMLGraph parser

Method Detail

parse

public void parse(InputSource source)
           throws SAXException,
                  IOException
Parse the specified InputSource using any available XMLReader

Throws:
SAXException
IOException

parse

public void parse(InputSource source,
                  XMLReader reader)
           throws SAXException,
                  IOException
Parse the specified InputSource using the specified XMLReader.

Throws:
SAXException
IOException

getGraph

public Graph getGraph()
Return the graph generated by the parse(org.xml.sax.InputSource) method


getFonts

public Set getFonts()
Return the list of font names used in the graph. This is necessary as many Output classes will require these font names to be mapped to actual Fonts.

Returns:
a Set containing 0 or more String objects

getWidth

public int getWidth()
Return the width of the graph, as specified in the XML with the width attribute


getHeight

public int getHeight()
Return the width of the graph, as specified in the XML with the height attribute


warning

public void warning(SAXParseException e)
             throws SAXException
Specified by:
warning in interface ErrorHandler
Overrides:
warning in class DefaultHandler
Throws:
SAXException

setResourceProvider

public void setResourceProvider(XMLGraphResourceProvider p)

Set the XMLGraphResourceProvider implementation to use for providing resources when parsing the graph XML.

Parameters:
p - the implementation of XMLGraphResourceProvider to use

setDocumentLocator

public void setDocumentLocator(Locator locator)
Specified by:
setDocumentLocator in interface ContentHandler
Overrides:
setDocumentLocator in class DefaultHandler

startElement

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

endElement

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

characters

public void characters(char[] buf,
                       int off,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class DefaultHandler
Throws:
SAXException

endDocument

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

getDefaultResourceProvider

public static XMLGraphResourceProvider getDefaultResourceProvider(String format)
Return a XMLGraphResourceProvider appropriate for the specified format

Parameters:
format - the output format, eg "png", "pdf", "swf"
Since:
2.4.4


Copyright © 2001-2011 Big Faceless Organization