cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Howard <cocoonge...@yahoo.com>
Subject SourceWritingTransformer Bug?
Date Tue, 03 Dec 2002 15:11:23 GMT
I tried to get someone on the users list to verify
this, but I'm pretty confident this is in fact a
problem.  I've looked into fixing it, with no success.

The short description is: source:write fails unless
you specify a source:path, even if the fragment is 
valid as a top level node.  In other words,

<source:write create="true"
xmlns:source="http://apache.org/cocoon/source/1.0">
  <source:source>foo.xml</source:source>
  <source:path></source:path>
  <source:fragment><foo>test</foo></source:fragment>
</source:write>

gives a DOM hierarchy exception at
SourceWritingTransformer line 709. (more detailed info
below)

Can anyone confirm this as a problem or have I missed
something?

Geoff Howard

-------------------------------------------------
SourceWritingTransformer fails in source:write with
empty path

This xml:
<source:write create="true"
xmlns:source="http://apache.org/cocoon/source/1.0">
  <source:source>anyExistingFile.xml</source:source>
  <source:path></source:path>
  <source:fragment><content>
<node>Well formed xml with only one top-level
node</node>
<othernode>for example</othernode>
</content></source:fragment>
</source:write>

produces:

<?xml version="1.0" encoding="UTF-8"?>
<sourceResult
xmlns:source="http://apache.org/cocoon/source/1.0">
<execution>failed</execution><message>There was a
problem manipulating your document:
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An
attempt was made to insert a node where it is not
permitted.</message>
<behaviour>write</behaviour><action>none</action><source>file:/accurate/path/to/file/anyExistingFile.xml</source>
</sourceResult>

Removing the source:path element has no effect, but
specifying a path causes the document to be written
successfully.  According to the design, comments in
the code and the docs, the correct behaviour is to
allow replacing the root node as long as the fragment
has only one top-level node.  

The logs show:

DEBUG   (2002-12-02) 16:46.57:647   [sitemap]
(/admin/content/save) HttpProcesso
r[8080][3]/SourceWritingTransformer: FAIL exception:
org.w3c.dom.DOMException: H
IERARCHY_REQUEST_ERR: An attempt was made to insert a
node where it is not permi
tted.
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An
attempt was made to insert a
 node where it is not permitted.
        at
org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java
:356)
        at
org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:320)
        at
org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.
java:444)
        at
org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:267)
        at
org.apache.cocoon.transformation.SourceWritingTransformer.insertFragm
ent(SourceWritingTransformer.java:709)

Note I'm using version 1.9 of this file, even though
the current cvs is 1.10.  The 
diff is here:
http://cvs.apache.org/viewcvs.cgi/xml-cocoon2/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java.diff?r1=1.9&r2=1.10&diff_format=h
 

I don't see anything there that could fix the problem,
though perhaps the new DOMUtil 
if used in this section would help.  I looked at
DOMUtil and was fairly certain it was 
the same code as XMLUtil, moved and renamed.

The source is :
Line 641:
 if ( exists == true && this.state == STATE_INSERT ) {
...
  Condition for source:insert with pre-existing file -
not relevant
...
>From Line 699:
 } 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); // <--- The
failing statement, line 709
        message = "entire source overwritten";

    } else {
        // get the node
        Node parent =
XMLUtil.selectSingleNode(resource, path);
        // add fragment
        parent.appendChild(importNode); 
        message = "content appended to: " + path;
    }

There are a couple weird things (mostly unrelated I
think) here 
that are either wrong or I don't fully understand
what's going on.
1) the "else if (create == true) " in line 699
excludes the condition
that source:write is acting on an existing file -
seems like it should be 
create == true || (exists == true && state ==
STATE_WRITE) or something to
that effect.
2) I'm not clear why parser.createDocument() is used
instead of 
XMLUtil.createDocument(), (now
DOMUtil.createDocument() ) though replacing it 
didn't seem to help. (it may have caused a different
problem with less feedback).

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message