dk.brics.xmlgraph.converter
Class Template2XMLGraph

java.lang.Object
  extended by dk.brics.xmlgraph.converter.Template2XMLGraph

public class Template2XMLGraph
extends Object

Production of XML graph fragment from an XML template constant or a complete XML document.

In templates, gaps are encoded as follows:

gap kindencoding
<[g]><gn:template-gap gap="g"/>
a=[g]<gn:attribute-gap gap="g" name="a"/>
<[T g]><gn:template-gap gap="g" type="t"/>
a=[T g]<gn:attribute-gap gap="g" type="t" name="a"/>
where the gn prefix refers to the namespace http://www.brics.dk/xmlgraph/gap, a and t are QNames, and g is a Name.

Note that in templates, the root element in the given XML template constant is only used as a container, and only its contents (and namespace declarations) are relevant.


Field Summary
static String GAP_NAMESPACE
          Namespace for gap encoding.
 
Constructor Summary
Template2XMLGraph(XMLGraph xg, boolean document_mode)
          Constructs a new converter.
 
Method Summary
 Document build(Reader reader, Origin origin)
          Builds JDOM representation of the given template or document.
 Document build(URL url, Origin origin)
          Builds JDOM representation of the given template or document.
 XMLGraph convert(Document d, Origin origin)
          Converts the given template or document to a new XML graph.
 XMLGraphFragment extend(Document d, Origin origin)
          Extends the current XML graph with a fragment corresponding to the given XML template constant.
 void useSurroundingChoiceNodes(boolean b)
          Enables/disables use of extra ChoiceNodes around each ElementNode and AttributeNode and above each TextNode.
 void useTypedGaps(boolean b)
          Enables/disables use of typed gaps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GAP_NAMESPACE

public static final String GAP_NAMESPACE
Namespace for gap encoding.

See Also:
Constant Field Values
Constructor Detail

Template2XMLGraph

public Template2XMLGraph(XMLGraph xg,
                         boolean document_mode)
Constructs a new converter.

Parameters:
xg - XML graph where fragments are to be added (set to null if using convert)
document_mode - if true, this converter works with complete documents rather that templates
Method Detail

build

public Document build(Reader reader,
                      Origin origin)
               throws ConverterException
Builds JDOM representation of the given template or document.

Parameters:
reader - reader of XML template or document
origin - source information (null if not applicable)
Returns:
JDOM document
Throws:
ConverterException - if unable to build

build

public Document build(URL url,
                      Origin origin)
               throws ConverterException
Builds JDOM representation of the given template or document.

Parameters:
url - URL of XML template or document
origin - source information (null if not applicable)
Returns:
JDOM document
Throws:
ConverterException - if unable to build

convert

public XMLGraph convert(Document d,
                        Origin origin)
                 throws ConverterException
Converts the given template or document to a new XML graph.

Parameters:
d - JDOM representation of XML template or document
origin - source information (null if not applicable)
Returns:
XML graph
Throws:
ConverterException - if unable to convert

extend

public XMLGraphFragment extend(Document d,
                               Origin origin)
                        throws ConverterException
Extends the current XML graph with a fragment corresponding to the given XML template constant.

Parameters:
d - JDOM representation of XML template or document
origin - source information (null if not applicable)
Returns:
XML graph fragment encapsulation
Throws:
ConverterException - if unable to convert

useSurroundingChoiceNodes

public void useSurroundingChoiceNodes(boolean b)
Enables/disables use of extra ChoiceNodes around each ElementNode and AttributeNode and above each TextNode. Default: disabled.

Parameters:
b - enable if true, disable if false

useTypedGaps

public void useTypedGaps(boolean b)
Enables/disables use of typed gaps. Default: enabled.

Parameters:
b - enable if true, disable if false


Copyright © 2005-2010 Anders Møller.