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 implementsContentHandlerusers 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 voidcharacters(char[] buf, int off, int len)voidendDocument()voidendElement(String nspace, String tag, String qname)static XMLGraphResourceProvidergetDefaultResourceProvider(String format)Return aXMLGraphResourceProviderappropriate for the specified formatSet<String>getFonts()Return the list of font names used in the graph.GraphgetGraph()Return the graph generated by theparse(org.xml.sax.InputSource)methodintgetHeight()Return the width of the graph, as specified in the XML with theheightattributeintgetWidth()Return the width of the graph, as specified in the XML with thewidthattributevoidparse(InputSource source)Parse the specified InputSource using any availableXMLReadervoidparse(InputSource source, XMLReader reader)Parse the specified InputSource using the specifiedXMLReader.voidsetDocumentLocator(Locator locator)voidsetResourceProvider(XMLGraphResourceProvider p)Set theXMLGraphResourceProviderimplementation to use for providing resources when parsing the graph XML.voidstartElement(String nspace, String tag, String qname, Attributes atts)voidwarning(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:
SAXExceptionIOException
-
parse
public void parse(InputSource source, XMLReader reader) throws SAXException, IOException
Parse the specified InputSource using the specifiedXMLReader.- Throws:
SAXExceptionIOException
-
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
Setcontaining 0 or moreStringobjects
-
getWidth
public int getWidth()
Return the width of the graph, as specified in the XML with thewidthattribute
-
getHeight
public int getHeight()
Return the width of the graph, as specified in the XML with theheightattribute
-
warning
public void warning(SAXParseException e) throws SAXException
- Specified by:
warningin interfaceErrorHandler- Overrides:
warningin classDefaultHandler- Throws:
SAXException
-
setResourceProvider
public void setResourceProvider(XMLGraphResourceProvider p)
Set the
XMLGraphResourceProviderimplementation 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:
setDocumentLocatorin interfaceContentHandler- Overrides:
setDocumentLocatorin classDefaultHandler
-
startElement
public void startElement(String nspace, String tag, String qname, Attributes atts) throws SAXException
- Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
endElement
public void endElement(String nspace, String tag, String qname) throws SAXException
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
characters
public void characters(char[] buf, int off, int len) throws SAXException- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
getDefaultResourceProvider
public static XMLGraphResourceProvider getDefaultResourceProvider(String format)
Return aXMLGraphResourceProviderappropriate for the specified format- Parameters:
format- the output format, eg "png", "pdf", "swf"- Since:
- 2.4.4
-
-