Package org.faceless.graph2
Class XMLGraph
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- 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 OutputStreamXMLGraph 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 implementsContentHandler
users may extend the class as necessary or use it as the end stage of an XSL transformation.
-
-
Constructor Summary
Constructors Constructor Description XMLGraph()
Create a new XMLGraph parser
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] buf, int off, int len)
void
endDocument()
void
endElement(String nspace, String tag, String qname)
static XMLGraphResourceProvider
getDefaultResourceProvider(String format)
Return aXMLGraphResourceProvider
appropriate for the specified formatSet<String>
getFonts()
Return the list of font names used in the graph.Graph
getGraph()
Return the graph generated by theparse(org.xml.sax.InputSource)
methodint
getHeight()
Return the width of the graph, as specified in the XML with theheight
attributeint
getWidth()
Return the width of the graph, as specified in the XML with thewidth
attributevoid
parse(InputSource source)
Parse the specified InputSource using any availableXMLReader
void
parse(InputSource source, XMLReader reader)
Parse the specified InputSource using the specifiedXMLReader
.void
setDocumentLocator(Locator locator)
void
setResourceProvider(XMLGraphResourceProvider p)
Set theXMLGraphResourceProvider
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
-
-
-
-
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
-
-
Method Detail
-
parse
public void parse(InputSource source) throws SAXException, IOException
Parse the specified InputSource using any availableXMLReader
- Throws:
SAXException
IOException
-
parse
public void parse(InputSource source, XMLReader reader) throws SAXException, IOException
Parse the specified InputSource using the specifiedXMLReader
.- Throws:
SAXException
IOException
-
getGraph
public Graph getGraph()
Return the graph generated by theparse(org.xml.sax.InputSource)
method
-
getFonts
public Set<String> 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 moreString
objects
-
getWidth
public int getWidth()
Return the width of the graph, as specified in the XML with thewidth
attribute
-
getHeight
public int getHeight()
Return the width of the graph, as specified in the XML with theheight
attribute
-
warning
public void warning(SAXParseException e) throws SAXException
- Specified by:
warning
in interfaceErrorHandler
- Overrides:
warning
in classDefaultHandler
- 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 interfaceContentHandler
- Overrides:
setDocumentLocator
in classDefaultHandler
-
startElement
public void startElement(String nspace, String tag, String qname, Attributes atts) throws SAXException
- Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
endElement
public void endElement(String nspace, String tag, String qname) throws SAXException
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
- Throws:
SAXException
-
characters
public void characters(char[] buf, int off, int len) throws SAXException
- Specified by:
characters
in interfaceContentHandler
- Overrides:
characters
in classDefaultHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
- Specified by:
endDocument
in interfaceContentHandler
- Overrides:
endDocument
in classDefaultHandler
- Throws:
SAXException
-
getDefaultResourceProvider
public static XMLGraphResourceProvider getDefaultResourceProvider(String format)
Return aXMLGraphResourceProvider
appropriate for the specified format- Parameters:
format
- the output format, eg "png", "pdf", "swf"- Since:
- 2.4.4
-
-