cziegeler 2002/07/17 08:13:01
Modified: src/java/org/apache/cocoon/transformation
SourceWritingTransformer.java
Log:
Fixing dom problems in source writing transformer
Revision Changes Path
1.9 +38 -27
xml-cocoon2/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
Index: SourceWritingTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SourceWritingTransformer.java 4 Jul 2002 12:23:32 -0000 1.8
+++ SourceWritingTransformer.java 17 Jul 2002 15:13:01 -0000 1.9
@@ -656,7 +656,21 @@
}
if (replaceNode != null) {
if (overwrite == true) {
- parent.replaceChild(importNode, replaceNode);
+ if (parent.getNodeType() == Node.DOCUMENT_NODE) {
+ // replacing of the document element is not
allowed
+ Parser parser =
(Parser)this.manager.lookup(Parser.ROLE);
+ try {
+ resource = parser.createDocument();
+ } finally {
+ this.manager.release( parser );
+ }
+
+
resource.appendChild(resource.importNode(importNode, true));
+ parent = resource;
+ replaceNode = resource.importNode(replaceNode,
true);
+ } else {
+ parent.replaceChild(importNode, replaceNode);
+ }
message += ", replacing: " + replacePath;
if (reinsertPath != null) {
Node insertAt = XMLUtil.getSingleNode(parent,
reinsertPath);
@@ -683,25 +697,25 @@
parent.appendChild(importNode);
}
} else if (create == true) {
- Parser parser =
(Parser)this.manager.lookup(Parser.ROLE);
- try {
- resource = parser.createDocument();
- } finally {
- this.manager.release( parser );
- }
- // import the fragment
- Node importNode = resource.importNode(fragment,
true);
- if ( path.equals("") ) { // this is allowed in
write
- resource.appendChild(importNode);
- message = "entire source overwritten";
+ Parser parser = (Parser)this.manager.lookup(Parser.ROLE);
+ try {
+ resource = parser.createDocument();
+ } finally {
+ this.manager.release( parser );
+ }
+ // import the fragment
+ Node importNode = resource.importNode(fragment, true);
+ if ( path.equals("") ) { // this is allowed in write
+ resource.appendChild(importNode);
+ message = "entire source overwritten";
- } else {
- // get the node
- Node parent =
XMLUtil.selectSingleNode(resource, path);
- // add fragment
- parent.appendChild(importNode);
- message = "content appended to: " + path;
- }
+ } else {
+ // get the node
+ Node parent = XMLUtil.selectSingleNode(resource, path);
+ // add fragment
+ parent.appendChild(importNode);
+ message = "content appended to: " + path;
+ }
} else {
message = "create not allowed";
resource = null;/**/
@@ -739,9 +753,9 @@
failed = false;
} catch (Throwable t) {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("FAIL
(oStream.close) exception"+t);
- throw new ProcessingException("Could not
process your document.", t);
+ 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 );
@@ -761,21 +775,18 @@
}
} catch (DOMException de) {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("FAIL exception: "+de);
+ this.getLogger().debug("FAIL exception: "+de, de);
}
- //throw new ProcessingException("Could not process your document.", de);
message = "There was a problem manipulating your document: " + de;
} catch (ComponentException ce) {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("FAIL exception: "+ce);
+ this.getLogger().debug("FAIL exception: "+ce, ce);
}
- //throw new ProcessingException("Unable to lookup component.", ce);
message = "There was a problem looking up a component: " + ce;
} catch (SourceException se) {
if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("FAIL exception: "+se);
+ this.getLogger().debug("FAIL exception: "+se, se);
}
- //throw new ProcessingException("Error during resolving "+systemID, se);
message = "There was a problem resolving that source: [" + systemID +
"] : " + se;
} finally {
this.resolver.release( source );
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]