|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.avalon.framework.logger.AbstractLoggable | +--org.apache.cocoon.xml.AbstractXMLProducer | +--org.apache.cocoon.xml.AbstractXMLPipe | +--org.apache.cocoon.transformation.AbstractTransformer | +--org.apache.cocoon.transformation.AbstractSAXTransformer
This class is the basis for all transformers. It provides various useful methods and hooks for implementing own custom transformers.
The basic behaviour of each transformer consists of the following four parts:
For all these four purposes the AbstractSunshineTransformer offers some powerful methods and hooks:
Namespace handling
By setting the instance variable namespaceURI to the namespace the events are filtered and only events with this namespace are send to the two hooks startTransformingElement() and endTransformingElement().
It is possible to override the default namespace for the transformer by specifying the parameter "namespaceURI" in the pipeline. This avoids possible namespace collisions.
Recording of information
There are several methods for recording information, e.g. startRecording(), startTextRecording() etc. These methods collect information from the xml stream for further processing.
Creating new events
New events can be easily created with the sendEvents()
method, the sendStartElementEvent()
methods, the sendEndElementEvent()
method or the sendTextEvent()
method.
Initialization
Before the document is processed the setupTransforming() hook is invoked.
Field Summary | |
protected Context |
context
The current Context object |
protected java.lang.String |
defaultNamespaceURI
This is the default namespace used by the transformer. |
protected org.xml.sax.helpers.AttributesImpl |
emptyAttributes
Empty attributes (for performance). |
protected boolean |
ignoreEmptyCharacters
Controlls SAX event handling If set to true all characters events containing only whitespaces are ignored. |
protected int |
ignoreEventsCount
Controlls SAX event handling If this is incremented all events are not forwarded to the next pipeline component, but the hooks are still called. |
protected int |
ignoreHooksCount
Controlls SAX event handling If this is greater than zero, the hooks are not called. |
protected boolean |
ignoreWhitespaces
Controlls SAX event handling. |
protected org.apache.avalon.framework.component.ComponentManager |
manager
The Avalon ComponentManager for getting Components |
protected java.lang.String |
namespaceURI
The used namespace for the SAX filtering. |
protected java.util.Map |
objectModel
The current objectModel of the environment |
protected org.apache.avalon.framework.parameters.Parameters |
parameters
The parameters specified in the sitemap |
protected java.util.Stack |
recorderStack
The stack of current used recorders |
protected Request |
request
The current Request object |
protected SourceResolver |
resolver
The SourceResolver for this request |
protected Response |
response
The current Response object |
protected java.lang.String |
source
The source attribute specified in the sitemap |
protected java.util.Stack |
stack
A stack for collecting information. |
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
contentHandler, lexicalHandler, xmlConsumer |
Fields inherited from interface org.apache.cocoon.transformation.Transformer |
ROLE |
Constructor Summary | |
AbstractSAXTransformer()
|
Method Summary | |
protected void |
addRecorder(XMLConsumer recorder)
Add a new recorder to the recording chain. |
void |
characters(char[] p0,
int p1,
int p2)
Process the SAX event. |
void |
comment(char[] ary,
int start,
int length)
SAX Event handling |
void |
compose(org.apache.avalon.framework.component.ComponentManager manager)
Avalon Composable Interface |
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration)
Avalon Configurable Interface |
void |
endCDATA()
SAX Event handling |
void |
endDocument()
Process the SAX event. |
void |
endDTD()
SAX Event handling |
void |
endElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw)
Process the SAX event. |
void |
endEntity(java.lang.String name)
SAX Event handling |
org.apache.excalibur.source.SourceParameters |
endParametersRecording(org.apache.avalon.framework.parameters.Parameters source)
End recording of parameters If source is null a new parameters object is created, otherwise the parameters are added to this object. |
org.apache.excalibur.source.SourceParameters |
endParametersRecording(org.apache.excalibur.source.SourceParameters source)
End recording of parameters If source is null a new parameters object is created, otherwise the parameters are added to this object. |
void |
endPrefixMapping(java.lang.String prefix)
SAX Event handling |
org.w3c.dom.DocumentFragment |
endRecording()
Stop DocumentFragment recording. |
java.lang.String |
endSerializedXMLRecording()
Return the serialized xml string. |
java.lang.String |
endTextRecording()
Stop recording of text and return the recorded information. |
void |
endTransformingElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw)
Start processing elements of our namespace. |
void |
ignorableWhitespace(char[] p0,
int p1,
int p2)
Process the SAX event. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
SAX Event handling |
void |
recycle()
Recycle this component. |
protected java.lang.Object |
removeRecorder()
Remove a recorder from the recording chain. |
void |
sendEndElementEvent(java.lang.String localname)
Send SAX events to the next pipeline component. |
protected void |
sendEndPrefixMapping()
Send all end prefix mapping events to the current content handler |
void |
sendEvents(org.w3c.dom.Node node)
Send SAX events to the next pipeline component. |
void |
sendParametersEvents(org.apache.excalibur.source.SourceParameters pars)
Send SAX events for the SourceParameters .
|
void |
sendStartElementEvent(java.lang.String localname)
Send SAX events to the next pipeline component. |
void |
sendStartElementEvent(java.lang.String localname,
org.xml.sax.Attributes attr)
Send SAX events to the next pipeline component. |
protected void |
sendStartPrefixMapping()
Send all start prefix mapping events to the current content handler |
void |
sendTextEvent(java.lang.String text)
Send SAX events to the next pipeline component. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
SAX Event handling |
void |
setup(SourceResolver resolver,
java.util.Map objectModel,
java.lang.String src,
org.apache.avalon.framework.parameters.Parameters par)
Setup the next round. |
void |
setupTransforming()
Setup the transformation of an xml document. |
void |
skippedEntity(java.lang.String name)
SAX Event handling |
void |
startCDATA()
SAX Event handling |
void |
startDocument()
Process the SAX event. |
void |
startDTD(java.lang.String name,
java.lang.String public_id,
java.lang.String system_id)
SAX Event handling |
void |
startElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw,
org.xml.sax.Attributes attr)
Process the SAX event. |
void |
startEntity(java.lang.String name)
SAX Event handling |
void |
startParametersRecording()
Start recording of parameters. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
SAX Event handling |
void |
startRecording()
Start DocumentFragment recording. |
void |
startSerializedXMLRecording(java.util.Properties format)
Start recording of serialized xml All events are converted to an xml string which can be retrieved by endSerializedXMLRecording. |
void |
startTextRecording()
Start recording of text. |
void |
startTransformingElement(java.lang.String uri,
java.lang.String name,
java.lang.String raw,
org.xml.sax.Attributes attr)
Start processing elements of our namespace. |
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
setConsumer, setContentHandler, setLexicalHandler |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable |
getLogger, setLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.cocoon.xml.XMLProducer |
setConsumer |
Field Detail |
protected boolean ignoreWhitespaces
protected boolean ignoreEmptyCharacters
protected int ignoreEventsCount
protected int ignoreHooksCount
protected java.lang.String namespaceURI
protected java.lang.String defaultNamespaceURI
protected java.util.Stack stack
protected java.util.Stack recorderStack
protected Request request
protected Response response
protected Context context
protected java.util.Map objectModel
protected org.apache.avalon.framework.parameters.Parameters parameters
protected java.lang.String source
protected org.apache.avalon.framework.component.ComponentManager manager
protected SourceResolver resolver
protected org.xml.sax.helpers.AttributesImpl emptyAttributes
Constructor Detail |
public AbstractSAXTransformer()
Method Detail |
public void configure(org.apache.avalon.framework.configuration.Configuration configuration) throws org.apache.avalon.framework.configuration.ConfigurationException
configure
in interface org.apache.avalon.framework.configuration.Configurable
public void setup(SourceResolver resolver, java.util.Map objectModel, java.lang.String src, org.apache.avalon.framework.parameters.Parameters par) throws ProcessingException, org.xml.sax.SAXException, java.io.IOException
resolver
- The current SourceResolverobjectModel
- The objectModel of the environment.src
- The value of the src attribute in the sitemap.par
- The parameters from the sitemap.public void recycle()
recycle
in interface org.apache.avalon.excalibur.pool.Recyclable
recycle
in class AbstractXMLProducer
public void compose(org.apache.avalon.framework.component.ComponentManager manager)
compose
in interface org.apache.avalon.framework.component.Composable
manager
- The Avalon Component Managerpublic void startDocument() throws org.xml.sax.SAXException
setupTransforming()
is invoked.startDocument
in class AbstractXMLPipe
ContentHandler.startDocument()
public void endDocument() throws org.xml.sax.SAXException
endDocument
in class AbstractXMLPipe
ContentHandler.endDocument()
public void startElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr) throws org.xml.sax.SAXException
startElement
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.loc
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.raw
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.a
- The attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object.public void endElement(java.lang.String uri, java.lang.String name, java.lang.String raw) throws org.xml.sax.SAXException
endElement
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.loc
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.raw
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.public void characters(char[] p0, int p1, int p2) throws org.xml.sax.SAXException
characters
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
c
- The characters from the XML document.start
- The start position in the array.len
- The number of characters to read from the array.public void ignorableWhitespace(char[] p0, int p1, int p2) throws org.xml.sax.SAXException
ignorableWhitespace
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
c
- The characters from the XML document.start
- The start position in the array.len
- The number of characters to read from the array.protected void addRecorder(XMLConsumer recorder)
protected java.lang.Object removeRecorder()
public void startRecording() throws org.xml.sax.SAXException
public org.w3c.dom.DocumentFragment endRecording() throws org.xml.sax.SAXException
public void startTextRecording() throws org.xml.sax.SAXException
public java.lang.String endTextRecording() throws org.xml.sax.SAXException
public void startSerializedXMLRecording(java.util.Properties format) throws org.xml.sax.SAXException
format
- The format for the serialized output. If null
is specified, the default format is used.public java.lang.String endSerializedXMLRecording() throws org.xml.sax.SAXException, ProcessingException
public void startParametersRecording() throws org.xml.sax.SAXException
public org.apache.excalibur.source.SourceParameters endParametersRecording(org.apache.avalon.framework.parameters.Parameters source) throws org.xml.sax.SAXException
source
- An optional parameters object.public org.apache.excalibur.source.SourceParameters endParametersRecording(org.apache.excalibur.source.SourceParameters source) throws org.xml.sax.SAXException
source
- An optional parameters object.public void setupTransforming() throws java.io.IOException, ProcessingException, org.xml.sax.SAXException
public void startTransformingElement(java.lang.String uri, java.lang.String name, java.lang.String raw, org.xml.sax.Attributes attr) throws ProcessingException, java.io.IOException, org.xml.sax.SAXException
uri
- The namespace of the element.name
- The local name of the element.raw
- The qualified name of the element.attr
- The attributes of the element.public void endTransformingElement(java.lang.String uri, java.lang.String name, java.lang.String raw) throws ProcessingException, java.io.IOException, org.xml.sax.SAXException
uri
- The namespace of the element.name
- The local name of the element.raw
- The qualified name of the element.public void sendTextEvent(java.lang.String text) throws org.xml.sax.SAXException
text
- The string containing the information.public void sendStartElementEvent(java.lang.String localname) throws org.xml.sax.SAXException
localname
- The name of the event.public void sendStartElementEvent(java.lang.String localname, org.xml.sax.Attributes attr) throws org.xml.sax.SAXException
localname
- The name of the event.attr
- The Attributes of the elementpublic void sendEndElementEvent(java.lang.String localname) throws org.xml.sax.SAXException
localname
- The name of the event.public void sendEvents(org.w3c.dom.Node node) throws org.xml.sax.SAXException
node
- The tree to be included.public void sendParametersEvents(org.apache.excalibur.source.SourceParameters pars) throws org.xml.sax.SAXException
SourceParameters
.
For each parametername/value pair an element is
created with the name of the parameter and the content
of this element is the value.public void startEntity(java.lang.String name) throws org.xml.sax.SAXException
startEntity
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
name
- The name of the entity. If it is a parameter entity, the
name will begin with '%'.public void endEntity(java.lang.String name) throws org.xml.sax.SAXException
endEntity
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
name
- The name of the entity that is ending.protected void sendStartPrefixMapping() throws org.xml.sax.SAXException
protected void sendEndPrefixMapping() throws org.xml.sax.SAXException
public void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
locator
- An object that can return the location of any SAX
document event.public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
startPrefixMapping
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
prefix
- The Namespace prefix being declared.uri
- The Namespace URI the prefix is mapped to.public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
endPrefixMapping
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
prefix
- The prefix that was being mapping.public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
processingInstruction
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
target
- The processing instruction target.data
- The processing instruction data, or null if none was
supplied.public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
skippedEntity
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
name
- The name of the skipped entity. If it is a parameter
entity, the name will begin with '%'.public void startDTD(java.lang.String name, java.lang.String public_id, java.lang.String system_id) throws org.xml.sax.SAXException
startDTD
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
name
- The document type name.publicId
- The declared public identifier for the external DTD
subset, or null if none was declared.systemId
- The declared system identifier for the external DTD
subset, or null if none was declared.public void endDTD() throws org.xml.sax.SAXException
endDTD
in class AbstractXMLPipe
public void startCDATA() throws org.xml.sax.SAXException
startCDATA
in class AbstractXMLPipe
public void endCDATA() throws org.xml.sax.SAXException
endCDATA
in class AbstractXMLPipe
public void comment(char[] ary, int start, int length) throws org.xml.sax.SAXException
comment
in class AbstractXMLPipe
org.apache.cocoon.xml.AbstractXMLPipe
ch
- An array holding the characters in the comment.start
- The starting position in the array.len
- The number of characters to use from the array.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |