net.n3.nanoxml
Class XIncludeXMLBuilder

java.lang.Object
  extended by net.n3.nanoxml.StdXMLBuilder
      extended by net.n3.nanoxml.XIncludeXMLBuilder
All Implemented Interfaces:
IXMLBuilder

public class XIncludeXMLBuilder
extends StdXMLBuilder

Extend the XMLBuilder to add XInclude functionality


Field Summary
static java.lang.String ACCEPT_ENCODING
          The attribute describing the accept header that will be used with http based includes.
static java.lang.String ENCODING_ATTRIB
          The attribute to decribe the encoding of the text include (no effect when parse='xml')
static java.lang.String FALLBACK_ELEMENT
          The element for handling fallbacks.
static java.lang.String FRAGMENT
          The fragment element is a root node element that can be used to wrap xml fragments for inclusion.
static java.lang.String FRAGMENT_NS
          Namespace for the "fragment" element used to include xml documents with no explicit root node.
static java.lang.String HREF_ATTRIB
          The location of the included data
static java.lang.String INCLUDE_ELEMENT
          The name of the include element (this should be "include" using the INCLUDE_NS but namespaces are not supported
static java.lang.String INCLUDE_NS
          Namespace for XInclude (NOTE that this is not used at the moment).
static java.lang.String PARSE_ATTRIB
          Parse attribute.
static java.lang.String XPOINTER_ATTRIB
          The xpointer attribute.
 
Constructor Summary
XIncludeXMLBuilder()
           
 
Method Summary
 void endElement(java.lang.String name, java.lang.String nsPrefix, java.lang.String nsSystemID)
          This method is called when the end of an XML elemnt is encountered.
private  IXMLReader getReader(XMLElement element)
          Return a reader for the specified INCLUDE_ELEMENT.
private  IXMLReader handleFallback(XMLElement include)
          Handle the fallback if one exists.
private  void includeText(XMLElement element, IXMLReader reader)
          Include plain text.
private  void includeXML(XMLElement element, IXMLReader reader)
          Include the xml contained in the specified reader.
private  void processXInclude(XMLElement element)
          This method handles XInclude elements in the code
 void startBuilding(java.lang.String systemID, int lineNr)
          used to record the system id for this document.
 
Methods inherited from class net.n3.nanoxml.StdXMLBuilder
addAttribute, addPCData, elementAttributesProcessed, finalize, getCurrentElement, getResult, getStack, newProcessingInstruction, setRootElement, startElement
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INCLUDE_NS

public static final java.lang.String INCLUDE_NS
Namespace for XInclude (NOTE that this is not used at the moment). The specification can be found here.

See Also:
Constant Field Values

INCLUDE_ELEMENT

public static final java.lang.String INCLUDE_ELEMENT
The name of the include element (this should be "include" using the INCLUDE_NS but namespaces are not supported

See Also:
Constant Field Values

HREF_ATTRIB

public static final java.lang.String HREF_ATTRIB
The location of the included data

See Also:
Constant Field Values

XPOINTER_ATTRIB

public static final java.lang.String XPOINTER_ATTRIB
The xpointer attribute. This must not be used when "parse='text'"

See Also:
Constant Field Values

ENCODING_ATTRIB

public static final java.lang.String ENCODING_ATTRIB
The attribute to decribe the encoding of the text include (no effect when parse='xml')

See Also:
Constant Field Values

ACCEPT_ENCODING

public static final java.lang.String ACCEPT_ENCODING
The attribute describing the accept header that will be used with http based includes.

See Also:
Constant Field Values

FALLBACK_ELEMENT

public static final java.lang.String FALLBACK_ELEMENT
The element for handling fallbacks. This should be called "fallback" and be in the INCLUDE_NS but namespaces are not supported

See Also:
Constant Field Values

PARSE_ATTRIB

public static final java.lang.String PARSE_ATTRIB
Parse attribute. If missing this implies "xml" its other valid value is "text"

See Also:
Constant Field Values

FRAGMENT_NS

public static final java.lang.String FRAGMENT_NS
Namespace for the "fragment" element used to include xml documents with no explicit root node.

See Also:
Constant Field Values

FRAGMENT

public static final java.lang.String FRAGMENT
The fragment element is a root node element that can be used to wrap xml fragments for inclusion. It is removed during the include operation. This should be called "fragment" and be in the FRAGMENT_NS but namespaces are not supported.

See Also:
Constant Field Values
Constructor Detail

XIncludeXMLBuilder

public XIncludeXMLBuilder()
Method Detail

endElement

public void endElement(java.lang.String name,
                       java.lang.String nsPrefix,
                       java.lang.String nsSystemID)
Description copied from class: StdXMLBuilder
This method is called when the end of an XML elemnt is encountered.

Specified by:
endElement in interface IXMLBuilder
Overrides:
endElement in class StdXMLBuilder
Parameters:
name - the name of the element
nsPrefix - the prefix used to identify the namespace
nsSystemID - the system ID associated with the namespace
See Also:
StdXMLBuilder.startElement(java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)

processXInclude

private void processXInclude(XMLElement element)
This method handles XInclude elements in the code

Parameters:
element - the node currently being procesed. In this case it should be the INCLUDE_ELEMENT

handleFallback

private IXMLReader handleFallback(XMLElement include)
Handle the fallback if one exists. If one does not exist then throw a runtime exception as this is a fatal error

Parameters:
include - the include element
Returns:
a reader for the fallback

includeXML

private void includeXML(XMLElement element,
                        IXMLReader reader)
Include the xml contained in the specified reader. This content will be parsed and attached to the parent of the element node

Parameters:
element - the include element
reader - the reader containing the xml to parse and include.

includeText

private void includeText(XMLElement element,
                         IXMLReader reader)
Include plain text. The reader contains the content in the appropriate encoding as determined by the ENCODING_ATTRIB if one was present.

Parameters:
element - the include element
reader - the reader containing the include text

getReader

private IXMLReader getReader(XMLElement element)
                      throws XMLParseException,
                             java.io.IOException
Return a reader for the specified INCLUDE_ELEMENT. The caller is responsible for closing the reader produced.

Parameters:
element - the include element to obtain a reader for
Returns:
a reader for the include element
Throws:
XMLParseException - if a problem occurs parsing the INCLUDE_ELEMENT
java.io.IOException - if the href cannot be read

startBuilding

public void startBuilding(java.lang.String systemID,
                          int lineNr)
used to record the system id for this document.

Specified by:
startBuilding in interface IXMLBuilder
Overrides:
startBuilding in class StdXMLBuilder
Parameters:
systemID - the system id of the document being built
lineNr - the line number