You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/02/13 12:50:31 UTC
cvs commit: cocoon-2.1/src/java/org/apache/cocoon/transformation AbstractSAXTransformer.java
cziegeler 2004/02/13 03:50:30
Modified: . status.xml
src/blocks/portal/java/org/apache/cocoon/portal/transformation
CopletTransformer.java
src/java/org/apache/cocoon/xml SaxBuffer.java
src/java/org/apache/cocoon/transformation
AbstractSAXTransformer.java
Log:
Patch for any elemens inside a coplet:content element and not just only text from Jon Evans.
Adding SAX recording to AbstractSAXTransformer.
Revision Changes Path
1.241 +7 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.240
retrieving revision 1.241
diff -u -r1.240 -r1.241
--- status.xml 13 Feb 2004 00:34:05 -0000 1.240
+++ status.xml 13 Feb 2004 11:50:30 -0000 1.241
@@ -196,6 +196,12 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="update" fixes-bug="26896" due-to-email="jon.evans@misgl.com" due-to="Jon Evans">
+ Patch for any elemens inside a coplet:content element and not just only text.
+ </action>
+ <action dev="CZ" type="update">
+ Adding SAX recording to AbstractSAXTransformer.
+ </action>
<action dev="VG" type="remove">
Remove non-FOM flow classes and system.js
</action>
1.14 +6 -5 cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java
Index: CopletTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/portal/java/org/apache/cocoon/portal/transformation/CopletTransformer.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- CopletTransformer.java 12 Dec 2003 15:53:19 -0000 1.13
+++ CopletTransformer.java 13 Feb 2004 11:50:30 -0000 1.14
@@ -64,6 +64,7 @@
import org.apache.cocoon.portal.event.impl.JXPathEvent;
import org.apache.cocoon.xml.AttributesImpl;
import org.apache.commons.jxpath.JXPathContext;
+import org.apache.excalibur.xml.sax.XMLizable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -126,7 +127,7 @@
protected List collectedEvents = new ArrayList();
/** The content of the links */
- protected String content;
+ protected XMLizable content;
/**
* Creates new CopletTransformer.
@@ -228,7 +229,7 @@
}
this.stack.push(format);
} else if ( name.equals(CONTENT_ELEM) && this.insideLinks ) {
- this.startTextRecording();
+ this.startSAXRecording();
} else {
super.startTransformingElement(uri, name, raw, attr);
}
@@ -264,7 +265,7 @@
}
this.collectedEvents.clear();
if ( this.content != null ) {
- this.sendTextEvent(this.content);
+ this.content.toSAX(this.contentHandler);
this.content = null;
}
String elem = (String)this.stack.pop();
@@ -272,7 +273,7 @@
this.sendEndElementEvent(elem);
}
} else if ( name.equals(CONTENT_ELEM) && this.insideLinks ) {
- this.content = this.endTextRecording();
+ this.content = this.endSAXRecording();
} else if (!name.equals(COPLET_ELEM)) {
super.endTransformingElement(uri, name, raw);
}
1.8 +2 -2 cocoon-2.1/src/java/org/apache/cocoon/xml/SaxBuffer.java
Index: SaxBuffer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/xml/SaxBuffer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SaxBuffer.java 26 Dec 2003 14:42:04 -0000 1.7
+++ SaxBuffer.java 13 Feb 2004 11:50:30 -0000 1.8
@@ -79,7 +79,7 @@
* @author <a href="mailto:dev@cocoon.apache.org">Apache Cocoon Team</a>
* @version CVS $Id$
*/
-public class SaxBuffer implements ContentHandler, LexicalHandler, XMLizable, Recyclable {
+public class SaxBuffer implements XMLConsumer, XMLizable, Recyclable {
/**
* Stores list of {@link SaxBit} objects.
1.8 +114 -91 cocoon-2.1/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
Index: AbstractSAXTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractSAXTransformer.java 23 Dec 2003 15:28:33 -0000 1.7
+++ AbstractSAXTransformer.java 13 Feb 2004 11:50:30 -0000 1.8
@@ -67,10 +67,12 @@
import org.apache.cocoon.transformation.helpers.ParametersRecorder;
import org.apache.cocoon.transformation.helpers.TextRecorder;
import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.cocoon.xml.SaxBuffer;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.xml.XMLUtils;
import org.apache.cocoon.xml.dom.DOMBuilder;
import org.apache.excalibur.source.SourceParameters;
+import org.apache.excalibur.xml.sax.XMLizable;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
@@ -85,6 +87,12 @@
import java.util.*;
/**
+ * @author CZiegeler
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+/**
* This class is the basis for all transformers. It provides various useful
* methods and hooks for implementing own custom transformers.<p>
* <p>
@@ -202,20 +210,15 @@
/** The current prefix for our namespace */
private String ourPrefix;
- /**
- * Avalon Configurable Interface
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
public void configure(Configuration configuration)
throws ConfigurationException {
}
- /**
- * Setup the next round.
- * The instance variables are initialised.
- * @param resolver The current SourceResolver
- * @param objectModel The objectModel of the environment.
- * @param src The value of the src attribute in the sitemap.
- * @param par The parameters from the sitemap.
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
*/
public void setup(SourceResolver resolver,
Map objectModel,
@@ -257,8 +260,8 @@
}
}
- /**
- * Recycle this component.
+ /* (non-Javadoc)
+ * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
*/
public void recycle() {
super.recycle();
@@ -275,9 +278,8 @@
this.ourPrefix = null;
}
- /**
- * Avalon Serviceable Interface
- * @param manager The Avalon Service Manager
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager manager) throws ServiceException {
this.manager = manager;
@@ -436,73 +438,25 @@
}
/**
- * Start DocumentFragment recording.
- * All invoking events are recorded and not forwarded. The resulting
- * DocumentFragment can be obtained by the matching endRecording() call.
+ * Start recording of SAX events
+ * All incomming events are recorded and not forwarded. The result
+ * can be obtained by the matching endSAXRecording() call.
+ * @since 2.1.5
*/
- public void startRecording()
+ public void startSAXRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("BEGIN startRecording");
- }
- DOMBuilder builder = new DOMBuilder();
- this.addRecorder(builder);
- builder.startDocument();
- builder.startElement("", "cocoon", "cocoon", new AttributesImpl());
-
- this.sendStartPrefixMapping();
-
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("END startRecording");
- }
+ this.addRecorder(new SaxBuffer());
}
/**
* Stop DocumentFragment recording.
- * All invoking events are recorded and not forwarded. This method returns
+ * All incomming events are recorded and not forwarded. This method returns
* the resulting DocumentFragment.
+ * @since 2.1.5
*/
- public DocumentFragment endRecording()
+ public XMLizable endSAXRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled()) {
- this.getLogger().debug("BEGIN endRecording");
- }
-
- this.sendEndPrefixMapping();
-
- DOMBuilder builder = (DOMBuilder)this.removeRecorder();
- builder.endElement("", "cocoon", "cocoon");
- builder.endDocument();
-
- // Create Document Fragment
- final Document doc = builder.getDocument();
- final DocumentFragment recordedDocFrag = doc.createDocumentFragment();
- final Node root = doc.getDocumentElement();
- root.normalize();
- Node child;
- boolean appendedNode = false;
- while (root.hasChildNodes() == true) {
- child = root.getFirstChild();
- root.removeChild(child);
- // Leave out empty text nodes before any other node
- if (appendedNode == true
- || child.getNodeType() != Node.TEXT_NODE
- || child.getNodeValue().trim().length() > 0) {
- recordedDocFrag.appendChild(child);
- appendedNode = true;
- }
- }
-
- if (this.getLogger().isDebugEnabled()) {
- Object serializedXML = null;
- try {
- serializedXML = (recordedDocFrag == null ? "null" : XMLUtils.serializeNodeToXML(recordedDocFrag));
- } catch (ProcessingException ignore) {
- serializedXML = recordedDocFrag;
- }
- this.getLogger().debug("END endRecording fragment=" + serializedXML);
- }
- return recordedDocFrag;
+ return (XMLizable)this.removeRecorder();
}
/**
@@ -649,6 +603,76 @@
return pars;
}
+ /**
+ * Start DocumentFragment recording.
+ * All incomming events are recorded and not forwarded. The resulting
+ * DocumentFragment can be obtained by the matching endRecording() call.
+ */
+ public void startRecording()
+ throws SAXException {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("BEGIN startRecording");
+ }
+ DOMBuilder builder = new DOMBuilder();
+ this.addRecorder(builder);
+ builder.startDocument();
+ builder.startElement("", "cocoon", "cocoon", new AttributesImpl());
+
+ this.sendStartPrefixMapping();
+
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("END startRecording");
+ }
+ }
+
+ /**
+ * Stop DocumentFragment recording.
+ * All incomming events are recorded and not forwarded. This method returns
+ * the resulting DocumentFragment.
+ */
+ public DocumentFragment endRecording()
+ throws SAXException {
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("BEGIN endRecording");
+ }
+
+ this.sendEndPrefixMapping();
+
+ DOMBuilder builder = (DOMBuilder)this.removeRecorder();
+ builder.endElement("", "cocoon", "cocoon");
+ builder.endDocument();
+
+ // Create Document Fragment
+ final Document doc = builder.getDocument();
+ final DocumentFragment recordedDocFrag = doc.createDocumentFragment();
+ final Node root = doc.getDocumentElement();
+ root.normalize();
+ Node child;
+ boolean appendedNode = false;
+ while (root.hasChildNodes() == true) {
+ child = root.getFirstChild();
+ root.removeChild(child);
+ // Leave out empty text nodes before any other node
+ if (appendedNode == true
+ || child.getNodeType() != Node.TEXT_NODE
+ || child.getNodeValue().trim().length() > 0) {
+ recordedDocFrag.appendChild(child);
+ appendedNode = true;
+ }
+ }
+
+ if (this.getLogger().isDebugEnabled()) {
+ Object serializedXML = null;
+ try {
+ serializedXML = (recordedDocFrag == null ? "null" : XMLUtils.serializeNodeToXML(recordedDocFrag));
+ } catch (ProcessingException ignore) {
+ serializedXML = recordedDocFrag;
+ }
+ this.getLogger().debug("END endRecording fragment=" + serializedXML);
+ }
+ return recordedDocFrag;
+ }
+
// ************
// Hooks
// ************
@@ -950,54 +974,53 @@
if (this.ignoreEventsCount == 0) super.endPrefixMapping(prefix);
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
*/
public void processingInstruction(String target, String data)
- throws SAXException {
+ throws SAXException {
if (this.ignoreEventsCount == 0) super.processingInstruction(target, data);
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
*/
public void skippedEntity(String name)
- throws SAXException {
+ throws SAXException {
if (this.ignoreEventsCount == 0) super.skippedEntity(name);
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ext.LexicalHandler#startDTD(java.lang.String, java.lang.String, java.lang.String)
*/
public void startDTD(String name, String public_id, String system_id)
- throws SAXException {
+ throws SAXException {
if (this.ignoreEventsCount == 0) super.startDTD(name, public_id, system_id);
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ext.LexicalHandler#endDTD()
*/
public void endDTD() throws SAXException {
if (this.ignoreEventsCount == 0) super.endDTD();
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ext.LexicalHandler#startCDATA()
*/
public void startCDATA() throws SAXException {
if (this.ignoreEventsCount == 0) super.startCDATA();
}
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ext.LexicalHandler#endCDATA()
*/
public void endCDATA() throws SAXException {
if (this.ignoreEventsCount == 0) super.endCDATA();
}
-
- /**
- * SAX Event handling
+ /* (non-Javadoc)
+ * @see org.xml.sax.ext.LexicalHandler#comment(char[], int, int)
*/
public void comment(char ary[], int start, int length)
throws SAXException {