|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xml.sax.helpers.XMLFilterImpl
net.sf.joost.stx.Processor
public class Processor
Processes an XML document as SAX XMLFilter. Actions are contained within an array of templates, received from a transform node.
Nested Class Summary | |
---|---|
class |
Processor.Data
Inner class for data which is processing/template specific. |
class |
Processor.DataStack
Inner class that implements a stack for Processor.Data objects. |
Field Summary | |
---|---|
private StringBuffer |
collectedCharacters
Buffer for collecting character data into single text nodes |
private Context |
context
The Context object |
private Processor.DataStack |
dataStack
Stack for Processor.Data objects |
private Stack |
eventStack
Stack for input events (of type SAXEvent ). |
private TemplateFactory.Instance[] |
globalTemplates
Array of global visible templates (templates with an attribute visibility="global" ). |
private Stack |
innerProcStack
Stack needed for inner processing (buffers, documents). |
private Hashtable |
inScopeNamespaces
The namespaces of the current scope |
private boolean |
insideCDATA
Set to true between startCDATA() and endCDATA() ,
needed for CDATA processing |
private boolean |
insideDTD
Set to true between startDTD(java.lang.String, java.lang.String, java.lang.String) and endDTD() ,
needed for ignoring comments |
private boolean |
isProcessorClass
|
private SAXEvent |
lastElement
Last event (this Processor uses one look-ahead) |
private static org.apache.commons.logging.Log |
log
|
private Stack |
namespaceContext
The namespace context as a stack |
private boolean |
nsContextActive
Flag that controls namespace contexts |
Properties |
outputProperties
|
static byte |
PASS_THROUGH_ALL
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_ATTRIBUTE
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_COMMENT
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_ELEMENT
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_NONE
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_PI
Possible actions when no matching template was found. |
static byte |
PASS_THROUGH_TEXT
Possible actions when no matching template was found. |
private int |
processStatus
contains the last return value after processing STX instructions |
private static String |
PROP_PREFIX
Standard prefix for SAX2 properties |
private int |
skipDepth
Depth in the subtree to be skipped; increased by startElement and decreased by endElement. |
private TransformFactory.Instance |
transformNode
The node representing the transformation sheet |
Fields inherited from interface net.sf.joost.Constants |
---|
DEBUG, DEFAULT_ENCODING, FEAT_NS, FEAT_NSPREFIX, FEATURE_URI_PREFIX, FUNC_NS, JOOST_EXT_NS, PR_ATTRIBUTES, PR_BUFFER, PR_CHILDREN, PR_CONTINUE, PR_ERROR, PR_SELF, PR_SIBLINGS, STX_NS |
Constructor Summary | |
---|---|
Processor(InputSource src,
ParseContext pContext)
Constructs a new Processor instance by parsing an
STX transformation sheet. |
|
Processor(Parser stxParser)
Constructs a new Processor instance from an existing Parser (Joost representation of an STX transformation sheet) |
|
Processor(Processor proc)
Constructs a copy of the given Processor. |
|
Processor(XMLReader reader,
InputSource src,
ParseContext pContext)
Constructs a new Processor instance by parsing an
STX transformation sheet. |
Method Summary | |
---|---|
void |
characters(char[] ch,
int start,
int length)
|
void |
clearParameters()
Clear all preset parameters |
private void |
clearProcessSiblings()
Clear all consecutive pending stx:process-siblings
instructions on the top of dataStack . |
private void |
clearProcessSiblings(Processor.Data stopData,
boolean clearLast)
Clear consecutive pending stx:process-siblings
instructions on the top of dataStack until
the passed object is encountered. |
void |
comment(char[] ch,
int start,
int length)
|
Processor |
copy()
Constructs a copy of this Processor. |
static XMLReader |
createXMLReader()
Create an XMLReader object (a SAX Parser) |
private AbstractInstruction |
doProcessLoop(AbstractInstruction inst,
SAXEvent event,
boolean skipProcessBase)
Performs the processing of the linked instruction chain until an end condition was met. |
void |
endCDATA()
|
void |
endDocument()
|
void |
endDTD()
|
void |
endElement(String uri,
String lName,
String qName)
|
void |
endEntity(String name)
|
private void |
endExternDocument()
Emits an endDocument event to an external handler
(in Context.targetHandler ), preceded by all necessary
namespace undeclarations (endPrefixMapping events). |
void |
endInnerProcessing()
Ends the inner processing by restoring the collected text data. |
void |
endPrefixMapping(String prefix)
|
private TemplateFactory.Instance |
findMatchingTemplate()
|
private boolean |
foundUnprocessedTemplate(TemplateFactory.Instance temp)
Check for the next best matching template after stx:process-self |
Context |
getContext()
Returns a ref to the current context of the processing. |
protected Processor.DataStack |
getDataStack()
Returns a reference to the data stack. |
Emitter |
getEmitter()
Returns a ref to the registered emitter |
Stack |
getEventStack()
Returns a reference to the event stack. |
protected SAXEvent |
getLastElement()
Returns a ref to the last element (look ahead) |
String |
getOutputEncoding()
|
Object |
getParameter(String name)
Returns a global parameter of the STX transformation sheet |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
|
private void |
init(TransformFactory.Instance pTransformNode)
Initialize a Processor object |
protected Emitter |
initializeEmitter(Context ctx)
The initialization of the emitter could be overriden for debug purpose. |
private void |
initNamespaces()
Create a fresh namespace hashtable |
void |
initOutputProperties()
Initialize the output properties to the values specified in the transformation sheet or to their default values, resp. |
private void |
processAttributes(Attributes attrs)
Simulate events for each of the attributes of the current element. |
private void |
processCharacters()
Process a text node (from several consecutive characters
events) |
private void |
processEvent()
Processes the upper most event on the event stack. |
void |
processingInstruction(String target,
String data)
|
protected int |
processInstruction(AbstractInstruction inst,
SAXEvent event)
Process an instruction. |
private void |
processLastElement(boolean hasChildren)
Process last element start (stored as lastElement in
startElement ) |
private void |
processSiblings()
Check and process pending templates whose processing was suspended by an stx:process-siblings instruction |
void |
setContentHandler(ContentHandler handler)
Registers a content handler. |
void |
setDeclHandler(DeclHandler handler)
Registers a declaration handler. |
void |
setDocumentLocator(Locator locator)
Store the locator in the context object |
void |
setErrorListener(ErrorListener listener)
Registers a ErrorListener object for reporting
errors while processing (transforming) the XML input |
void |
setLexicalHandler(LexicalHandler handler)
Registers a lexical handler. |
void |
setMessageEmitter(StxEmitter emitter)
Registers a message emitter for stx:message |
void |
setOutputURIResolver(OutputURIResolver resolver)
Registers an OutputURIResolver for stx:result-document |
void |
setParameter(String name,
Object value)
Sets a global parameter of the STX transformation sheet |
void |
setParent(XMLReader parent)
Assigns a parent to this filter instance. |
void |
setProperty(String prop,
Object value)
Set the property of a value on the underlying XMLReader. |
void |
setTransformerHandlerResolver(TransformerHandlerResolver resolver)
Registers a custom TransformerHandlerResolver object. |
void |
setURIResolver(URIResolver resolver)
Registers a URIResolver for stx:process-document |
void |
startCDATA()
|
void |
startDocument()
|
void |
startDTD(String name,
String publicId,
String systemId)
|
void |
startElement(String uri,
String lName,
String qName,
Attributes attrs)
|
void |
startEntity(String name)
|
private void |
startExternDocument()
Emits a startDocument event to an external handler
(in Context.targetHandler ), followed by all necessary
namespace declarations (startPrefixMapping events). |
void |
startInnerProcessing()
Starts the inner processing of a new buffer or another document by saving the text data already read and jumping to the targetted group (if specified). |
void |
startPrefixMapping(String prefix,
String uri)
|
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
---|
error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, notationDecl, parse, parse, resolveEntity, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, skippedEntity, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final byte PASS_THROUGH_NONE
stx:options' no-match-events
public static final byte PASS_THROUGH_ELEMENT
stx:options' no-match-events
public static final byte PASS_THROUGH_TEXT
stx:options' no-match-events
public static final byte PASS_THROUGH_COMMENT
stx:options' no-match-events
public static final byte PASS_THROUGH_PI
stx:options' no-match-events
public static final byte PASS_THROUGH_ATTRIBUTE
stx:options' no-match-events
public static final byte PASS_THROUGH_ALL
stx:options' no-match-events
private TransformFactory.Instance transformNode
private TemplateFactory.Instance[] globalTemplates
visibility="global"
).
private Context context
private int skipDepth
private boolean insideCDATA
startCDATA()
and endCDATA()
,
needed for CDATA processing
private boolean insideDTD
startDTD(java.lang.String, java.lang.String, java.lang.String)
and endDTD()
,
needed for ignoring comments
private StringBuffer collectedCharacters
private SAXEvent lastElement
private Hashtable inScopeNamespaces
private Stack namespaceContext
private boolean nsContextActive
private Stack eventStack
SAXEvent
). Every
startElement
event pushes itself on this stack, every
endElement
event pops its event from the stack.
Character events (text()), comments, PIs will be put on the stack
before processing and removed immediately afterwards. This stack is
needed for matching and for position counting within the parent of
each event.
private Stack innerProcStack
stx:process-document
and character data that has been already read as look-ahead
(collectedCharacters
).
public Properties outputProperties
private final boolean isProcessorClass
private Processor.DataStack dataStack
Processor.Data
objects
private static org.apache.commons.logging.Log log
private static String PROP_PREFIX
private int processStatus
Constructor Detail |
---|
public Processor(InputSource src, ParseContext pContext) throws IOException, SAXException
Processor
instance by parsing an
STX transformation sheet. This constructor attempts to create
its own XMLReader
object.
src
- the source for the STX transformation sheetpContext
- the parse context
IOException
- if src
couldn't be retrieved
SAXException
- if a SAX parser couldn't be createdpublic Processor(XMLReader reader, InputSource src, ParseContext pContext) throws IOException, SAXException
Processor
instance by parsing an
STX transformation sheet.
reader
- the parser that is used for reading the transformation
sheetsrc
- the source for the STX transformation sheetpContext
- a parse context
IOException
- if src
couldn't be retrieved
SAXException
- if a SAX parser couldn't be createdpublic Processor(Parser stxParser) throws SAXException
stxParser
- the Joost representation of a transformation sheet
SAXException
- if createXMLReader()
failspublic Processor(Processor proc) throws SAXException
proc
- the original Processor object
SAXException
- if the construction of a new XML parser failsMethod Detail |
---|
public Processor copy() throws SAXException
SAXException
- if the construction of a new XML parser failspublic static XMLReader createXMLReader() throws SAXException
XMLReader
object (a SAX Parser)
SAXException
- if a SAX Parser couldn't be createdprivate void init(TransformFactory.Instance pTransformNode)
Processor
object
private void initNamespaces()
protected Emitter initializeEmitter(Context ctx)
ctx
- The current context
public void initOutputProperties()
public void setParent(XMLReader parent)
setParent
in interface XMLFilter
setParent
in class XMLFilterImpl
public void setContentHandler(ContentHandler handler)
setContentHandler
in interface XMLReader
setContentHandler
in class XMLFilterImpl
public void setLexicalHandler(LexicalHandler handler)
public void setDeclHandler(DeclHandler handler)
public void setProperty(String prop, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
setProperty
in interface XMLReader
setProperty
in class XMLFilterImpl
SAXNotRecognizedException
SAXNotSupportedException
public void setErrorListener(ErrorListener listener)
ErrorListener
object for reporting
errors while processing (transforming) the XML input
public String getOutputEncoding()
public void setParameter(String name, Object value)
name
- the (expanded) parameter namevalue
- the parameter valuepublic Object getParameter(String name)
name
- the (expanded) parameter name
null
if this parameter
isn't presentpublic void clearParameters()
public void setTransformerHandlerResolver(TransformerHandlerResolver resolver)
TransformerHandlerResolver
object.
resolver
- the resolver to be registeredpublic void setURIResolver(URIResolver resolver)
stx:process-document
resolver
- the resolver to be registeredpublic void setOutputURIResolver(OutputURIResolver resolver)
OutputURIResolver
for stx:result-document
resolver
- the resolver to be registeredpublic void setMessageEmitter(StxEmitter emitter)
stx:message
emitter
- the emitter object to be registeredpublic void startInnerProcessing()
public void endInnerProcessing() throws SAXException
SAXException
private boolean foundUnprocessedTemplate(TemplateFactory.Instance temp)
stx:process-self
temp
- a template matching the current node
true
if this template hasn't been processed beforeprivate TemplateFactory.Instance findMatchingTemplate() throws SAXException
SAXException
private AbstractInstruction doProcessLoop(AbstractInstruction inst, SAXEvent event, boolean skipProcessBase) throws SAXException
processStatus
.
inst
- the first instruction in the chainevent
- the current eventskipProcessBase
- set if ProcessBase instructions shouldn't be
reported
SAXException
protected int processInstruction(AbstractInstruction inst, SAXEvent event) throws SAXException
inst
- The instruction which should be processedevent
- The current event
AbstractInstruction.process(net.sf.joost.stx.Context)
SAXException
- in case of parse-errorsprivate void processEvent() throws SAXException
SAXException
private void processLastElement(boolean hasChildren) throws SAXException
lastElement
in
startElement
)
SAXException
private void processCharacters() throws SAXException
characters
events)
SAXException
private void processAttributes(Attributes attrs) throws SAXException
stx:process-attributes
instruction.
attrs
- the attributes to be processed
SAXException
private void processSiblings() throws SAXException
SAXException
private void clearProcessSiblings() throws SAXException
stx:process-siblings
instructions on the top of dataStack
. Does nothing
if there's no stx:process-siblings
pending.
SAXException
private void clearProcessSiblings(Processor.Data stopData, boolean clearLast) throws SAXException
stx:process-siblings
instructions on the top of dataStack
until
the passed object is encountered.
stopData
- data for the last stx:process-siblings
instructionclearLast
- true
if the template in
stopData
itself must be cleared
SAXException
private void startExternDocument() throws SAXException
startDocument
event to an external handler
(in Context.targetHandler
), followed by all necessary
namespace declarations (startPrefixMapping
events).
SAXException
private void endExternDocument() throws SAXException
endDocument
event to an external handler
(in Context.targetHandler
), preceded by all necessary
namespace undeclarations (endPrefixMapping
events).
SAXException
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class XMLFilterImpl
SAXException
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class XMLFilterImpl
SAXException
public void startElement(String uri, String lName, String qName, Attributes attrs) throws SAXException
startElement
in interface ContentHandler
startElement
in class XMLFilterImpl
SAXException
public void endElement(String uri, String lName, String qName) throws SAXException
endElement
in interface ContentHandler
endElement
in class XMLFilterImpl
SAXException
public void characters(char[] ch, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class XMLFilterImpl
SAXException
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class XMLFilterImpl
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class XMLFilterImpl
SAXException
public void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class XMLFilterImpl
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class XMLFilterImpl
SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class XMLFilterImpl
public void startDTD(String name, String publicId, String systemId)
startDTD
in interface LexicalHandler
public void endDTD()
endDTD
in interface LexicalHandler
public void startEntity(String name) throws SAXException
startEntity
in interface LexicalHandler
SAXException
public void endEntity(String name) throws SAXException
endEntity
in interface LexicalHandler
SAXException
public void startCDATA() throws SAXException
startCDATA
in interface LexicalHandler
SAXException
public void endCDATA() throws SAXException
endCDATA
in interface LexicalHandler
SAXException
public void comment(char[] ch, int start, int length) throws SAXException
comment
in interface LexicalHandler
SAXException
public Stack getEventStack()
protected Processor.DataStack getDataStack()
public Context getContext()
public Emitter getEmitter()
protected SAXEvent getLastElement()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |