|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttomp.xtcl.filter.XTFilterImpl
tomp.xml.include.XIncludeFilter
This is a SAX filter which resolves all XInclude include elements before passing them on to the client application. Currently this class has the following known deviation from the XInclude specification:
Extensions made by JP and TP:
the URL of the included TEXT document (i.e. if parse='text'
)
can be in one of the following forms (lines are numbered starting at 1):
textfileurl#startLineNumber
will include only the line with startLineNumbertextfileurl#startLineNumber$count
will include count lines beginning from startLineNumbertextfileurl#startLineNumber-endLineNumber
will include all lines
beginning from startLineNumber and ending to (including) line endLineNumbertextfileurl#startLineNumber-
will include all lines
beginning from to the end of filetextfileurl#$countOfLines
or textfileurl#-countOfLines
will include first countOfLines lines
from the file
Extensions made by TP, Nov 2003:
Instead of specifying and start/end line and/or line count nummericaly,
Java-style regexp patterns can be put in slashes instead of the first or last line number.
textfileurl#/startLineRegexp/
will include only the line with startLineRegexptextfileurl#/startLineRegexp/$count
will include count lines beginning from start linetextfileurl#/startLineRegexp/-/endLineRegexp/
will include all lines
beginning from start line and ending to line (including) matching the end patterntextfileurl#/startLineRegexp/-endLineNo
will include all lines
beginning from start line and ending to line (including) specified by endLineNo
textfileurl#startLineNo-/endLineRegexp/
will include all lines
beginning from the start line number and ending to line (including) matching the end patterntextfileurl#-/endLineRegexp/
will include all lines
upto the line (including) matching the end patterntextfileurl#/startLineRegexp/-
will include all lines
beginning from to the end of fileFurthermore, I would definitely use a new instance of this class for each document you want to process. I doubt it can be used successfully on multiple documents. Furthermore, I can virtually guarantee that this class is not thread safe. You have been warned.
Since this class is not designed to be subclassed, and since I have not yet considered how that might affect the methods herein or what other protected methods might be needed to support subclasses, I have declared this class final. I may remove this restriction later, though the use-case for subclassing is weak. This class is designed to have its functionality extended via a a horizontal chain of filters, not a vertical hierarchy of sub and superclasses.
To use this class:
XIncludeFilter
object with a known base URLXMLReader
object from which the raw document will
be read to the setParent()
method of this object. ContentHandler
object to the
setContentHandler()
method of this object. This is the
object which will receive events from the parsed and included
document.
LexicalHandler
object as the value of this object's
http://xml.org/sax/properties/lexical-handler property.
Also make sure your LexicalHandler
asks this object
for the status of each comment using insideIncludeElement
before doing anything with the comment.
parse()
methode.g.
XIncludeFilter includer = new XIncludeFilter(base);
includer.setParent(parser);
includer.setContentHandler(new SAXXIncluder(System.out));
includer.parse(args[i]);
Field Summary | |
protected static java.lang.String |
REGEXP_DELIMITERS
the delimiters for regular expressions used to specify the first or last line |
protected static java.lang.String |
term1
the number of the first line to be included is specified in the URL after the term1 String |
protected static java.lang.String |
term2
the number of lines to be included is specified in the URL after the term2 String |
protected static java.lang.String |
term3
the number of the last line to be included is specified in the URL after the term3 String |
static java.lang.String |
XINCLUDE_NAMESPACE
|
Fields inherited from class tomp.xtcl.filter.XTFilterImpl |
contentHandler, dtdHandler, entityResolver, errorHandler, lexicalHandler, locator, parent |
Constructor Summary | |
XIncludeFilter()
|
Method Summary | |
void |
endDocument()
Filter an end document event. |
void |
endElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName)
Filter an end element event. |
void |
endPrefixMapping(java.lang.String prefix)
Filter an end Namespace prefix mapping event. |
protected static java.lang.String |
getFirstLineRegexp(java.lang.String url)
This method reads URL and returns the regular expression to match on the first line. |
protected static java.lang.String |
getLastLineRegexp(java.lang.String url)
This method reads URL and returns the regular expression to match on the last line. |
protected int |
getLineBegin(java.lang.String url)
This method reads URL and return the first line to read |
protected int |
getLineCount(java.lang.String url)
This method reads URL and return the amount of line line to read |
protected org.xml.sax.XMLReader |
getXMLReader(java.lang.String variant)
|
void |
characters(char[] ch,
int start,
int length)
Filter a character data event. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Filter an ignorable whitespace event. |
protected void |
includeXMLDocument(java.lang.String url,
java.lang.String variant)
This utility method reads a document at a specified URL and fires off calls to various ContentHandler methods.
|
boolean |
insideIncludeElement()
This utility method returns true if and only if this reader is currently inside a non-empty include element. |
protected boolean |
isLastLineNo(java.lang.String url)
|
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Filter a processing instruction event. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Filter a new document locator event. |
void |
skippedEntity(java.lang.String name)
Filter a skipped entity event. |
void |
startDocument()
Filter a start document event. |
void |
startElement(java.lang.String uri,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
Filter a start element event. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Filter a start Namespace prefix mapping event. |
Methods inherited from class tomp.xtcl.filter.XTFilterImpl |
comment, endCDATA, endDTD, endEntity, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getLexicalHandler, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setLexicalHandler, setParameter, setParent, setProperty, setupParse, startCDATA, startDTD, startEntity, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final java.lang.String REGEXP_DELIMITERS
protected static final java.lang.String term1
term1
String
protected static final java.lang.String term2
term2
String
protected static final java.lang.String term3
term3
String
public static final java.lang.String XINCLUDE_NAMESPACE
Constructor Detail |
public XIncludeFilter()
Method Detail |
public void setDocumentLocator(org.xml.sax.Locator locator)
XTFilterImpl
setDocumentLocator
in interface org.xml.sax.ContentHandler
setDocumentLocator
in class XTFilterImpl
locator
- The document locator.public boolean insideIncludeElement()
This utility method returns true if and only if this reader is currently inside a non-empty include element. (This is not the same as being inside the node set which replaces the include element.) This is primarily needed for comments inside include elements. It must be checked by the actual LexicalHandler to see whether a comment is passed or not.
public void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
XTFilterImpl
startElement
in interface org.xml.sax.ContentHandler
startElement
in class XTFilterImpl
uri
- The element's Namespace URI, or the empty string.localName
- The element's local name, or the empty string.qName
- The element's qualified (prefixed) name, or the empty
string.atts
- The element's attributes.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
XTFilterImpl
endElement
in interface org.xml.sax.ContentHandler
endElement
in class XTFilterImpl
uri
- The element's Namespace URI, or the empty string.localName
- The element's local name, or the empty string.qName
- The element's qualified (prefixed) name, or the empty
string.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void startDocument() throws org.xml.sax.SAXException
XTFilterImpl
startDocument
in interface org.xml.sax.ContentHandler
startDocument
in class XTFilterImpl
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void endDocument() throws org.xml.sax.SAXException
XTFilterImpl
endDocument
in interface org.xml.sax.ContentHandler
endDocument
in class XTFilterImpl
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
XTFilterImpl
startPrefixMapping
in interface org.xml.sax.ContentHandler
startPrefixMapping
in class XTFilterImpl
prefix
- The Namespace prefix.uri
- The Namespace URI.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
XTFilterImpl
endPrefixMapping
in interface org.xml.sax.ContentHandler
endPrefixMapping
in class XTFilterImpl
prefix
- The Namespace prefix.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
XTFilterImpl
characters
in interface org.xml.sax.ContentHandler
characters
in class XTFilterImpl
ch
- An array of characters.start
- The starting position in the array.length
- The number of characters to use from the array.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
XTFilterImpl
ignorableWhitespace
in interface org.xml.sax.ContentHandler
ignorableWhitespace
in class XTFilterImpl
ch
- An array of characters.start
- The starting position in the array.length
- The number of characters to use from the array.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
XTFilterImpl
processingInstruction
in interface org.xml.sax.ContentHandler
processingInstruction
in class XTFilterImpl
target
- The processing instruction target.data
- The text following the target.
org.xml.sax.SAXException
- The client may throw
an exception during processing.public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
XTFilterImpl
skippedEntity
in interface org.xml.sax.ContentHandler
skippedEntity
in class XTFilterImpl
name
- The name of the skipped entity.
org.xml.sax.SAXException
- The client may throw
an exception during processing.protected static java.lang.String getFirstLineRegexp(java.lang.String url)
This method reads URL and returns the regular expression to match on the first line.
url
- URL of the document that will be read
protected static java.lang.String getLastLineRegexp(java.lang.String url)
This method reads URL and returns the regular expression to match on the last line.
url
- URL of the document that will be read
protected int getLineBegin(java.lang.String url)
This method reads URL and return the first line to read
url
- URL of the document that will be read
protected int getLineCount(java.lang.String url)
This method reads URL and return the amount of line line to read
url
- URL of the document that will be read
protected boolean isLastLineNo(java.lang.String url)
protected void includeXMLDocument(java.lang.String url, java.lang.String variant) throws org.xml.sax.SAXException
This utility method reads a document at a specified URL
and fires off calls to various ContentHandler
methods.
It's used to include files with parse="xml"
url
- URL of the document that will be read
org.xml.sax.SAXException
- if the requested document cannot
be downloaded from the specified URL.protected org.xml.sax.XMLReader getXMLReader(java.lang.String variant) throws org.xml.sax.SAXException
org.xml.sax.SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |