| Method from org.apache.cocoon.transformation.AbstractSAXTransformer Detail: |
protected void addRecorder(XMLConsumer recorder) {
if (this.recorderStack.empty()) {
// redirect if first (top) recorder
this.originalLexicalHandler = this.lexicalHandler;
this.originalContentHandler = this.contentHandler;
}
setContentHandler(recorder);
setLexicalHandler(recorder);
this.recorderStack.push(recorder);
}
Add a new recorder to the recording chain.
Do not invoke this method directly. |
public void characters(char[] p0,
int p1,
int p2) throws SAXException {
if (this.ignoreEventsCount == 0) {
if (this.ignoreEmptyCharacters) {
String value = new String(p0, p1, p2);
if (value.trim().length() > 0) {
super.characters(p0, p1, p2);
}
} else {
super.characters(p0, p1, p2);
}
}
}
|
public void comment(char[] ary,
int start,
int length) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.comment(ary, start, length);
}
}
|
public void configure(Configuration configuration) throws ConfigurationException {
String tFactoryClass = configuration.getChild("transformer-factory").getValue(null);
if (tFactoryClass != null) {
try {
this.tfactory = (SAXTransformerFactory) ClassUtils.newInstance(tFactoryClass);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Using transformer factory " + tFactoryClass);
}
} catch (Exception e) {
throw new ConfigurationException("Cannot load transformer factory " + tFactoryClass, e);
}
} else {
// Standard TrAX behaviour
this.tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
}
tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
}
|
public void dispose() {
this.manager = null;
}
|
public void endCDATA() throws SAXException {
if (this.ignoreEventsCount == 0) {
super.endCDATA();
}
}
|
public void endDTD() throws SAXException {
if (this.ignoreEventsCount == 0) {
super.endDTD();
}
}
|
public void endDocument() throws SAXException {
if (this.ignoreEventsCount == 0) {
super.endDocument();
}
}
Process the SAX event. The processing of the document is finished. |
public void endElement(String uri,
String name,
String raw) throws SAXException {
if (namespaceURI.equals(uri) && this.ignoreHooksCount == 0) {
// this is our namespace:
try {
endTransformingElement(uri, name, raw);
} catch (ProcessingException e) {
throw new SAXException("ProcessingException: " + e, e);
} catch (IOException e) {
throw new SAXException("IOException occured during processing: " + e, e);
}
} else {
if (ignoreEventsCount == 0) {
super.endElement(uri, name, raw);
}
}
}
Process the SAX event. The namespace of the event is checked.
If it is the defined namespace for this transformer,
the #endTransformingElement hook is called. |
public void endEntity(String name) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.endEntity(name);
}
}
|
public SourceParameters endParametersRecording(Parameters source) throws SAXException {
sendEndPrefixMapping();
ParametersRecorder recorder = (ParametersRecorder) this.removeRecorder();
SourceParameters parameters = recorder.getParameters(source);
if (getLogger().isDebugEnabled()) {
getLogger().debug("End parameters recording. Parameters=" + parameters);
}
return parameters;
}
End recording of parameters
If source is null a new parameters object is created, otherwise
the parameters are added to this object. |
public SourceParameters endParametersRecording(SourceParameters source) throws SAXException {
sendEndPrefixMapping();
ParametersRecorder recorder = (ParametersRecorder) removeRecorder();
SourceParameters parameters = recorder.getParameters(source);
if (getLogger().isDebugEnabled()) {
getLogger().debug("End parameters recording. Parameters=" + parameters);
}
return parameters;
}
End recording of parameters
If source is null a new parameters object is created, otherwise
the parameters are added to this object. |
public void endPrefixMapping(String prefix) throws SAXException {
if (prefix != null) {
// Find and remove the namespace prefix
boolean found = false;
for (int i = this.namespaces.size() - 1; i >= 0; i--) {
final String[] prefixAndUri = (String[]) this.namespaces.get(i);
if (prefixAndUri[0].equals(prefix)) {
this.namespaces.remove(i);
found = true;
break;
}
}
if (!found) {
throw new SAXException("Namespace for prefix '" + prefix + "' not found.");
}
if (prefix.equals(this.ourPrefix)) {
// Reset our current prefix
this.ourPrefix = null;
// Now search if we have a different prefix for our namespace
for (int i = this.namespaces.size() - 1; i >= 0; i--) {
final String[] prefixAndUri = (String[]) this.namespaces.get(i);
if (namespaceURI.equals(prefixAndUri[1])) {
this.ourPrefix = prefixAndUri[0];
break;
}
}
}
}
if (this.ignoreEventsCount == 0) {
super.endPrefixMapping(prefix);
}
}
|
public DocumentFragment endRecording() throws SAXException {
sendEndPrefixMapping();
DOMBuilder builder = (DOMBuilder) removeRecorder();
builder.endElement("", "cocoon", "cocoon");
builder.endDocument();
// Create Document Fragment
final Document doc = builder.getDocument();
final DocumentFragment fragment = doc.createDocumentFragment();
final Node root = doc.getDocumentElement();
// Remove empty text nodes and collapse neighbouring text nodes
root.normalize();
// Move all nodes into the fragment
boolean space = true;
while (root.hasChildNodes()) {
Node child = root.getFirstChild();
root.removeChild(child);
// Leave out leading whitespace nodes
// FIXME: Why leading spaces are trimmed at all? Why not trailing spaces?
if (space && child.getNodeType() == Node.TEXT_NODE
&& child.getNodeValue().trim().length() == 0) {
continue;
}
space = false;
fragment.appendChild(child);
}
if (getLogger().isDebugEnabled()) {
Object serializedXML = null;
try {
serializedXML = fragment == null? "null": XMLUtils.serializeNode(fragment, XMLUtils.createPropertiesForXML(false));
} catch (ProcessingException ignore) {
serializedXML = fragment;
}
getLogger().debug("End recording. Fragment=" + serializedXML);
}
return fragment;
}
Stop DOM DocumentFragment recording.
This method returns the resulting DocumentFragment, normalized. |
public XMLizable endSAXRecording() throws SAXException {
sendEndPrefixMapping();
return (XMLizable) removeRecorder();
}
Stop recording of SAX events.
This method returns the resulting XMLizable. |
public String endSerializedXMLRecording() throws SAXException, ProcessingException {
XMLizable xml = endSAXRecording();
String text = XMLUtils.serialize(xml, (Properties) this.stack.pop());
if (getLogger().isDebugEnabled()) {
getLogger().debug("End serialized XML recording. XML=" + text);
}
return text;
}
Return the serialized xml string. |
public String endTextRecording() throws SAXException {
sendEndPrefixMapping();
TextRecorder recorder = (TextRecorder) removeRecorder();
String text = recorder.getText();
if (getLogger().isDebugEnabled()) {
getLogger().debug("End text recording. Text=" + text);
}
return text;
}
Stop recording of text and return the recorded information. |
public void endTransformingElement(String uri,
String name,
String raw) throws IOException, SAXException, ProcessingException {
if (this.ignoreEventsCount == 0) {
super.endElement(uri, name, raw);
}
}
Start processing elements of our namespace.
This hook is invoked for each sax event with our namespace. |
protected String findPrefixMapping(String uri) {
final int l = this.namespaces.size();
for (int i = 0; i < l; i++) {
String[] prefixAndUri = (String[]) this.namespaces.get(i);
if (prefixAndUri[1].equals(uri)) {
return prefixAndUri[0];
}
}
return null;
}
Find prefix mapping for the given namespace URI. |
protected AttributesImpl getMutableAttributes(Attributes a) {
if ( a instanceof AttributesImpl && !(a instanceof ImmutableAttributesImpl)) {
return (AttributesImpl)a;
}
return new AttributesImpl(a);
}
Helper method to get a modifiable attribute set. |
public void ignorableWhitespace(char[] p0,
int p1,
int p2) throws SAXException {
if (ignoreWhitespaces == false && ignoreEventsCount == 0) {
super.ignorableWhitespace(p0, p1, p2);
}
}
|
public void processingInstruction(String target,
String data) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.processingInstruction(target, data);
}
}
|
public void recycle() {
this.namespaceURI = null;
this.objectModel = null;
this.request = null;
this.response = null;
this.context = null;
this.resolver = null;
this.stack.clear();
this.recorderStack.clear();
this.parameters = null;
this.source = null;
this.namespaces.clear();
this.ourPrefix = null;
super.recycle();
}
|
protected Object removeRecorder() {
Object recorder = this.recorderStack.pop();
if (this.recorderStack.empty() == true) {
// undo redirect if no recorder any more
setContentHandler(originalContentHandler);
setLexicalHandler(originalLexicalHandler);
this.originalLexicalHandler = null;
this.originalContentHandler = null;
} else {
XMLConsumer next = (XMLConsumer) recorderStack.peek();
setContentHandler(next);
setLexicalHandler(next);
}
return recorder;
}
Remove a recorder from the recording chain.
Do not invoke this method directly. |
public void sendEndElementEvent(String localname) throws SAXException {
endElement("", localname, localname);
}
Send SAX events to the next pipeline component.
The endElement event for the given element is send
to the next component in the current pipeline.
The element has no namespace. |
public void sendEndElementEventNS(String localname) throws SAXException {
endElement(this.namespaceURI,
localname, this.ourPrefix + ':" + localname);
}
Send SAX events to the next pipeline component.
The endElement event for the given element is send
to the next component in the current pipeline.
The element has the namespace of the transformer. |
protected void sendEndPrefixMapping() throws SAXException {
final int l = this.namespaces.size();
for (int i = 0; i < l; i++) {
String[] prefixAndUri = (String[]) this.namespaces.get(i);
super.contentHandler.endPrefixMapping(prefixAndUri[0]);
}
}
Send all end prefix mapping events to the current content handler |
public void sendEvents(Node node) throws SAXException {
IncludeXMLConsumer.includeNode(node, this, this);
}
Send SAX events to the next pipeline component.
The node is parsed and the events are send to
the next component in the pipeline. |
public void sendParametersEvents(SourceParameters pars) throws SAXException {
if (pars != null) {
Iterator names = pars.getParameterNames();
while (names.hasNext()) {
final String currentName = (String)names.next();
Iterator values = pars.getParameterValues(currentName);
while (values.hasNext()) {
final String currentValue = (String)values.next();
sendStartElementEvent(currentName);
sendTextEvent(currentValue);
sendEndElementEvent(currentName);
}
}
}
}
Send SAX events for the 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 sendStartElementEvent(String localname) throws SAXException {
startElement("", localname, localname, EMPTY_ATTRIBUTES);
}
Send SAX events to the next pipeline component.
The startElement event for the given element is send
to the next component in the current pipeline.
The element has no namespace and no attributes |
public void sendStartElementEvent(String localname,
Attributes attr) throws SAXException {
startElement("", localname, localname, attr);
}
Send SAX events to the next pipeline component.
The startElement event for the given element is send
to the next component in the current pipeline.
The element has no namespace. |
public void sendStartElementEventNS(String localname) throws SAXException {
startElement(this.namespaceURI,
localname, this.ourPrefix + ':" + localname, EMPTY_ATTRIBUTES);
}
Send SAX events to the next pipeline component.
The startElement event for the given element is send
to the next component in the current pipeline.
The element has the namespace of the transformer,
but not attributes |
public void sendStartElementEventNS(String localname,
Attributes attr) throws SAXException {
startElement(this.namespaceURI,
localname, this.ourPrefix + ':" + localname, attr);
}
Send SAX events to the next pipeline component.
The startElement event for the given element is send
to the next component in the current pipeline.
The element has the namespace of the transformer. |
protected void sendStartPrefixMapping() throws SAXException {
final int l = this.namespaces.size();
for (int i = 0; i < l; i++) {
String[] prefixAndUri = (String[]) this.namespaces.get(i);
super.contentHandler.startPrefixMapping(prefixAndUri[0], prefixAndUri[1]);
}
}
Send all start prefix mapping events to the current content handler |
public void sendTextEvent(String text) throws SAXException {
characters(text.toCharArray(), 0, text.length());
}
Send SAX events to the next pipeline component.
The characters event for the given text is send to the next
component in the current pipeline. |
public void service(ServiceManager manager) throws ServiceException {
//
// Lifecycle
//
/* (non-Javadoc)
* @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
*/
this.manager = manager;
}
|
public void setDocumentLocator(Locator locator) {
if (this.ignoreEventsCount == 0) {
super.setDocumentLocator(locator);
}
}
|
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters params) throws IOException, SAXException, ProcessingException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Setup resolver=" + resolver +
", objectModel=" + objectModel +
", src=" + src +
", parameters=" + params);
}
// defaultNamespaceURI should never be null
if (this.defaultNamespaceURI == null) {
this.defaultNamespaceURI = "";
}
this.objectModel = objectModel;
this.request = ObjectModelHelper.getRequest(objectModel);
this.response = ObjectModelHelper.getResponse(objectModel);
this.context = ObjectModelHelper.getContext(objectModel);
this.resolver = resolver;
this.parameters = params;
this.source = src;
this.isInitialized = false;
// get the current namespace
this.namespaceURI = params.getParameter("namespaceURI",
this.defaultNamespaceURI);
this.ignoreHooksCount = 0;
this.ignoreEventsCount = 0;
this.ignoreWhitespaces = true;
this.ignoreEmptyCharacters = false;
}
|
public void setupTransforming() throws IOException, SAXException, ProcessingException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("setupTransforming");
}
this.stack.clear();
this.recorderStack.clear();
this.ignoreWhitespaces = true;
this.ignoreEmptyCharacters = false;
}
Setup the transformation of an xml document.
This method is called just before the transformation (sending of sax events)
starts. It should be used to initialize setup parameter depending on the
object modell. |
public void skippedEntity(String name) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.skippedEntity(name);
}
}
|
public void startCDATA() throws SAXException {
if (this.ignoreEventsCount == 0) {
super.startCDATA();
}
}
|
public void startDTD(String name,
String public_id,
String system_id) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.startDTD(name, public_id, system_id);
}
}
|
public void startDocument() throws SAXException {
if (!this.isInitialized) {
try {
setupTransforming();
} catch (ProcessingException e) {
throw new SAXException("ProcessingException: " + e, e);
} catch (IOException e) {
throw new SAXException("IOException: " + e, e);
}
this.isInitialized = true;
}
if (this.ignoreEventsCount == 0) {
super.startDocument();
}
}
Process the SAX event. A new document is processed. The hook method
#setupTransforming is invoked. |
public void startElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
if (namespaceURI.equals(uri) && ignoreHooksCount == 0) {
// this is our namespace:
try {
startTransformingElement(uri, name, raw, attr);
} catch (ProcessingException e) {
throw new SAXException("ProcessingException: " + e, e);
} catch (IOException e) {
throw new SAXException("IOException occured during processing: " + e, e);
}
} else {
if (ignoreEventsCount == 0) {
super.startElement(uri, name, raw, attr);
}
}
}
Process the SAX event. The namespace of the event is checked.
If it is the defined namespace for this transformer,
the #startTransformingElement hook is called. |
public void startEntity(String name) throws SAXException {
if (this.ignoreEventsCount == 0) {
super.startEntity(name);
}
}
|
public void startParametersRecording() throws SAXException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Start parameters recording");
}
addRecorder(new ParametersRecorder());
sendStartPrefixMapping();
}
Start recording of parameters.
All events are not forwarded and the incoming xml is converted to
parameters. Each toplevel node is a parameter and its text subnodes
form the value.
The Parameters can eiter be retrieved by endParametersRecording(). |
public void startPrefixMapping(String prefix,
String uri) throws SAXException {
if (prefix != null) {
this.namespaces.add(new String[] {prefix, uri});
}
if (namespaceURI.equals(uri)) {
this.ourPrefix = prefix;
}
if (this.ignoreEventsCount == 0) {
super.startPrefixMapping(prefix, uri);
}
}
|
public void startRecording() throws SAXException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Start recording");
}
DOMBuilder builder = new DOMBuilder(this.tfactory);
addRecorder(builder);
builder.startDocument();
builder.startElement("", "cocoon", "cocoon", EMPTY_ATTRIBUTES);
sendStartPrefixMapping();
}
Start DOM DocumentFragment recording.
All incoming events are recorded and not forwarded. The resulting
DocumentFragment can be obtained by the matching #endRecording call. |
public void startSAXRecording() throws SAXException {
addRecorder(new SaxBuffer());
sendStartPrefixMapping();
}
Start recording of SAX events.
All incoming events are recorded and not forwarded. The resulting
XMLizable can be obtained by the matching #endSAXRecording call. |
public void startSerializedXMLRecording(Properties format) throws SAXException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Start serialized XML recording. Format=" + format);
}
this.stack.push(format == null? XMLUtils.createPropertiesForXML(false): format);
startSAXRecording();
}
Start recording of serialized xml
All events are converted to an xml string which can be retrieved by
endSerializedXMLRecording. |
public void startTextRecording() throws SAXException {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Start text recording");
}
addRecorder(new TextRecorder());
sendStartPrefixMapping();
}
Start recording of a text.
No events forwarded, and all characters events
are collected into a string. |
public void startTransformingElement(String uri,
String name,
String raw,
Attributes attr) throws IOException, SAXException, ProcessingException {
if (this.ignoreEventsCount == 0) {
super.startElement(uri, name, raw, attr);
}
}
Start processing elements of our namespace.
This hook is invoked for each sax event with our namespace. |