bloritsch 2003/03/12 07:05:17
Modified: src/java/org/apache/cocoon/transformation
SourceWritingTransformer.java
src/java/org/apache/cocoon/transformation/helpers
DefaultIncludeCacheManager.java
PreemptiveLoader.java
src/java/org/apache/cocoon/xml/dom DOMUtil.java
Log:
many compilation fixes, as well as re-implementing my change to make cornerstone
unnecessary
Revision Changes Path
1.2 +118 -57
cocoon-2.1/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
Index: SourceWritingTransformer.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SourceWritingTransformer.java 9 Mar 2003 00:09:39 -0000 1.1
+++ SourceWritingTransformer.java 12 Mar 2003 15:05:17 -0000 1.2
@@ -50,10 +50,6 @@
*/
package org.apache.cocoon.transformation;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.Map;
-
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentSelector;
@@ -62,6 +58,7 @@
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.components.source.WriteableSAXSource;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.xml.XMLUtils;
@@ -76,11 +73,16 @@
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Map;
+
/**
/**
- * This transformer allows you to output to a ModifiableSource.
+ * This transformer allows you to output to a WriteableSource.
*
* <p>Definition:</p>
* <pre>
@@ -346,11 +348,30 @@
", name=" + name + ", raw=" + raw + ", attr=" + attr);
}
// Element: insert
- if (this.state == STATE_OUTSIDE
- && (name.equals(INSERT_ELEMENT) || name.equals(WRITE_ELEMENT))) {
+ if (name.equals(INSERT_ELEMENT)
+ && this.state == STATE_OUTSIDE) {
+ this.state = STATE_INSERT;
+ this.parent_state = STATE_INSERT;
+ if (attr.getValue(CREATE_ATTRIBUTE) != null
+ && attr.getValue(CREATE_ATTRIBUTE).equals("false")) {
+ this.stack.push("false");
+ } else {
+ this.stack.push("true");
+ }
+ if (attr.getValue(OVERWRITE_ATTRIBUTE) != null
+ && attr.getValue(OVERWRITE_ATTRIBUTE).equals("false")) {
+ this.stack.push("false");
+ } else {
+ this.stack.push("true");
+ }
+ this.stack.push(attr.getValue(SERIALIZER_ATTRIBUTE));
+ this.stack.push("INSERT");
- this.state = (name.equals(INSERT_ELEMENT) ? STATE_INSERT : STATE_WRITE);
- this.parent_state = this.state;
+ // Element: write
+ } else if (name.equals(WRITE_ELEMENT)
+ && this.state == STATE_OUTSIDE) {
+ this.state = STATE_WRITE;
+ this.parent_state = STATE_WRITE;
if (attr.getValue(CREATE_ATTRIBUTE) != null
&& attr.getValue(CREATE_ATTRIBUTE).equals("false")) {
this.stack.push("false");
@@ -364,7 +385,7 @@
this.stack.push("true"); // default value
}
this.stack.push(attr.getValue(SERIALIZER_ATTRIBUTE));
- this.stack.push("END");
+ this.stack.push("WRITE");
// Element: file
} else if (name.equals(SOURCE_ELEMENT)
@@ -424,23 +445,21 @@
", name=" + name +
", raw=" + raw);
}
- if ((name.equals(INSERT_ELEMENT) && this.state == STATE_INSERT)
- || (name.equals(WRITE_ELEMENT) && this.state == STATE_WRITE)) {
+ if (name.equals(INSERT_ELEMENT) == true && this.state == STATE_INSERT) {
// get the information from the stack
- DocumentFragment fragment = null;
String tag;
- String sourceName = null;
- String path = (this.state == STATE_INSERT ? null : "/");
- // source:write's path can be empty
- String replacePath = null;
- String reinsert = null;
+ String fileName = null;
+ DocumentFragment fragment = null;
+ String path = null;
+ String replacePath = null;
+ String reinsert = null;
do {
tag = (String)this.stack.pop();
if (tag.equals("PATH") == true) {
path = (String)this.stack.pop();
} else if (tag.equals("FILE") == true) {
- sourceName = (String)this.stack.pop();
+ fileName = (String)this.stack.pop();
} else if (tag.equals("FRAGMENT") == true) {
fragment = (DocumentFragment)this.stack.pop();
} else if (tag.equals("REPLACE") == true) {
@@ -448,13 +467,47 @@
} else if (tag.equals("REINSERT") == true) {
reinsert = (String)this.stack.pop();
}
- } while ( !tag.equals("END") );
+ } while (tag.equals("INSERT") == false);
+ final String localSerializer = (String)this.stack.pop();
+ final boolean overwrite = this.stack.pop().equals("true");
+ final boolean create = this.stack.pop().equals("true");
+ this.insertFragment(fileName,
+ path,
+ fragment,
+ replacePath,
+ create,
+ overwrite,
+ reinsert,
+ localSerializer,
+ name);
+
+ this.state = STATE_OUTSIDE;
+
+ } else if (name.equals(WRITE_ELEMENT) == true && this.state == STATE_WRITE)
{
+
+ // get the information from the stack
+ String tag;
+ String fileName = null;
+ DocumentFragment fragment = null;
+ String path = "/"; // source:write's path can be empty
+ String replacePath = null;
+ String reinsert = null;
+ do {
+ tag = (String)this.stack.pop();
+ if (tag.equals("PATH") == true) {
+ path = (String)this.stack.pop();
+ } else if (tag.equals("FILE") == true) {
+ fileName = (String)this.stack.pop();
+ } else if (tag.equals("FRAGMENT") == true) {
+ fragment = (DocumentFragment)this.stack.pop();
+ }
+ } while (tag.equals("WRITE") == false);
final String localSerializer = (String)this.stack.pop();
final boolean overwrite = this.stack.pop().equals("true");
final boolean create = this.stack.pop().equals("true");
- this.insertFragment(sourceName,
+ this.insertFragment(fileName,
path,
fragment,
replacePath,
@@ -581,7 +634,7 @@
target = source.getURI();
if ( exists == true && this.state == STATE_INSERT ) {
message = "content inserted at: " + path;
- resource = SourceUtil.toDOM( source );
+ resource = SourceUtil.toDOM( source, this.manager );
// import the fragment
Node importNode = resource.importNode(fragment, true);
// get the node
@@ -665,45 +718,53 @@
// write source
if ( resource != null) {
resource.normalize();
- // use serializer
- if (localSerializer == null) localSerializer =
this.configuredSerializerName;
- if (localSerializer != null) {
- // Lookup the Serializer
- ComponentSelector selector = null;
- Serializer serializer = null;
- OutputStream oStream = null;
- try {
- selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
- serializer = (Serializer)selector.select(localSerializer);
- oStream = ws.getOutputStream();
- serializer.setOutputStream(oStream);
- DOMStreamer streamer = new DOMStreamer(serializer);
- streamer.stream(resource);
- } finally {
- if (oStream != null) {
- oStream.flush();
- try {
- oStream.close();
- failed = false;
- } catch (Throwable t) {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("FAIL (oStream.close)
exception"+t, t);
- }
- throw new ProcessingException("Could not process
your document.", t);
- } finally {
- if ( selector != null ) {
- selector.release( serializer );
- this.manager.release( selector );
+ if (source instanceof WriteableSAXSource) {
+ ContentHandler contentHandler =
((WriteableSAXSource)ws).getContentHandler();
+ DOMStreamer streamer = new DOMStreamer(contentHandler);
+ streamer.stream(resource);
+ localSerializer = "null";
+ failed = false;
+ } else {
+ // use serializer
+ if (localSerializer == null) localSerializer =
this.configuredSerializerName;
+ if (localSerializer != null) {
+ // Lookup the Serializer
+ ComponentSelector selector = null;
+ Serializer serializer = null;
+ OutputStream oStream = null;
+ try {
+ selector =
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
+ serializer =
(Serializer)selector.select(localSerializer);
+ oStream = ws.getOutputStream();
+ serializer.setOutputStream(oStream);
+ DOMStreamer streamer = new DOMStreamer(serializer);
+ streamer.stream(resource);
+ } finally {
+ if (oStream != null) {
+ oStream.flush();
+ try {
+ oStream.close();
+ failed = false;
+ } catch (Throwable t) {
+ if (this.getLogger().isDebugEnabled() == true) {
+ this.getLogger().debug("FAIL
(oStream.close) exception"+t, t);
+ }
+ throw new ProcessingException("Could not
process your document.", t);
+ } finally {
+ if ( selector != null ) {
+ selector.release( serializer );
+ this.manager.release( selector );
+ }
}
}
}
+ } else {
+ if (this.getLogger().isDebugEnabled() == true) {
+ this.getLogger().debug("ERROR no serializer");
+ }
+ //throw new ProcessingException("No serializer specified
for writing to source " + systemID);
+ message = "That source requires a serializer, please add
the appropirate tag to your code.";
}
- } else {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("ERROR no serializer");
- }
- //throw new ProcessingException("No serializer specified for
writing to source " + systemID);
- message = "That source requires a serializer, please add the
appropirate tag to your code.";
}
}
} catch (DOMException de) {
1.3 +4 -4
cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java
Index: DefaultIncludeCacheManager.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultIncludeCacheManager.java 11 Mar 2003 16:33:37 -0000 1.2
+++ DefaultIncludeCacheManager.java 12 Mar 2003 15:05:17 -0000 1.3
@@ -377,7 +377,7 @@
serializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
XMLTeePipe tee = new XMLTeePipe(handler, serializer);
- SourceUtil.toSAX(source, tee);
+ SourceUtil.toSAX(source, tee, manager);
SourceValidity[] validities = new SourceValidity[1];
validities[0] = session.getExpiresValidity();
@@ -385,7 +385,7 @@
(byte[])serializer.getSAXFragment());
session.getCacheStorageProxy().put(uri, response);
} else {
- SourceUtil.toSAX(source, handler);
+ SourceUtil.toSAX(source, handler, manager);
}
} catch (ProcessingException pe) {
@@ -464,7 +464,7 @@
public void run() {
try {
- SourceUtil.toSAX(this.source, this.serializer);
+ SourceUtil.toSAX(this.source, this.serializer, this.manager);
this.content = (byte[])this.serializer.getSAXFragment();
} catch (Exception local) {
this.exception = local;
1.2 +2 -2
cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/PreemptiveLoader.java
Index: PreemptiveLoader.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/PreemptiveLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PreemptiveLoader.java 9 Mar 2003 00:09:41 -0000 1.1
+++ PreemptiveLoader.java 12 Mar 2003 15:05:17 -0000 1.2
@@ -155,7 +155,7 @@
source = resolver.resolveURI(uri);
serializer = (XMLSerializer)manager.lookup(XMLSerializer.ROLE);
- SourceUtil.toSAX(source, serializer);
+ SourceUtil.toSAX(source, serializer, manager);
SourceValidity[] validities = new SourceValidity[1];
validities[0] = new
ExpiresValidity(((Long)object[2]).longValue() * 1000); // milliseconds!
1.2 +2 -2 cocoon-2.1/src/java/org/apache/cocoon/xml/dom/DOMUtil.java
Index: DOMUtil.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/xml/dom/DOMUtil.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DOMUtil.java 9 Mar 2003 00:09:48 -0000 1.1
+++ DOMUtil.java 12 Mar 2003 15:05:17 -0000 1.2
@@ -54,8 +54,8 @@
import org.apache.xpath.XPathAPI;
import org.apache.excalibur.xml.xpath.NodeListImpl;
import org.apache.excalibur.xml.xpath.XPathProcessor;
-import org.apache.excalibur.xml.xpath.XPathUtil;
import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.components.xpath.XPathUtil;
import org.apache.cocoon.xml.IncludeXMLConsumer;
import org.apache.excalibur.xml.sax.SAXParser;
import org.apache.excalibur.xml.sax.XMLizable;