cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ricardo Rocha <rica...@apache.org>
Subject Re: cocoon and XMLGen
Date Thu, 06 Apr 2000 06:05:58 GMT
On Wed, 05 Apr 2000, Andrew Atkinson wrote:
> I have written java code into the xml page that makes a call to our
> API, this in turn makes a call to our database that returns an XML
> document (using Oracle XMLGen). However when we try and render it
> (using <xsp:expr>) all the < and > have become &lt; and &gt;. This
is
> no longer an xml document and cannot be styled. Is there a way to
> prevent cocoon from doing this?

The reason for this problem is that method

  String Forum.readForums(String)

returns a String instead of a DOM Node.

When a String is passed to <xsp:expr>, it's treated as _text_,
not as markup.

If you want to embed markup in your XSP document, you must
pass an org.w3c.dom.Node to <xsp:expr>.

[
  Mea culpa: in replying to this request I detected and fixed
  a bug in XSPPage.xspExpr(Object, Document) that didn't
  ensure the node was created by the current document
  instance. Download the latest version from the CVS
  repository for workaround 2 (explained below) to work
  correctly.
]

For your particular case you may want to do one of the
following:

1) Revise your API so that method "readForums" has the
    following signature:

      Element Forum.readForums(String forum)

    or

      Element Forum.readForums(String forum, Document factory)

    where "factory" is actually the XSP-supplied "document"
    variable and must be used to create nodes that can be safely
    inserted into the current document position.

2) Convert your String to Node by using the XSP-provided
    "xspParser" parser to parse the String


If it's too late (or your developers are too lazy, :-)) to change your
API, workaround (2) may look like:

    <xsp:logic>
      Forum forum = new
      Forum("100110000037972710211999191652","102110000048260010251999120317");
      String fList=forum.readForums("1");
      // START WORKAROUND
      StringBufferInputStream sbis = new StringBufferInputStream(fList);
      InputSource is = new InputSource(sbis);
      Element forumList = this.xspParser.parse(is).getDocumentElement();
      // END WORKAROUND
    </xsp:logic>
    <!-- Use returned element instead -->
    <xsp:expr>forumList</xsp:expr>

If you don't have access to the latest bug fix mentioned above, then this
workaround should read:

    <xsp:logic>
      Forum forum = new
      Forum("100110000037972710211999191652","102110000048260010251999120317");
      String fList=forum.readForums("1");
      // START WORKAROUND
      StringBufferInputStream sbis = new StringBufferInputStream(fList);
      InputSource is = new InputSource(sbis);
      Element forumList = this.xspParser.parse(is).getDocumentElement();
      // END WORKAROUND
    </xsp:logic>
    <!-- Clone returned element instead -->
    <xsp:expr>
      XSPUtil.cloneNode(forumList, document)
    </xsp:expr>


Hope this helps,

Ricardo
==========================================================================

On Wed, 05 Apr 2000, Andrew Atkinson wrote:
> I have written java code into the xml page that makes a call to our
> API, this in turn makes a call to our database that returns an XML
> document (using Oracle XMLGen). However when we try and render it
> (using <xsp:expr>) all the < and > have become &lt; and &gt;. This
is
> no longer an xml document and cannot be styled. Is there a way to
> prevent cocoon from doing this?
> 
> This is the test program we have
> 
> <?xml version="1.0"?>
> 
> <!-- Author: Andrew Atkinson "andrew@wellengaged.com" -->
> 
> <?cocoon-process type="xsp"?>
> <?cocoon-process type="xslt"?>
> <?xml-stylesheet href="forumlist.xsl" type="text/xsl"?>
> <xsp:page language="java"
> xmlns:xsp="http://www.apache.org/1999/XSP/Core">
> <xsp:structure>
>    <xsp:include>com.wellengaged.application.*</xsp:include>
>    <xsp:include>com.wellengaged.components.*</xsp:include>
>    <xsp:include>com.wellengaged.persistence.*</xsp:include>
>    <xsp:include>com.wellengaged.util.*</xsp:include>
>    <xsp:include>javax.swing.tree.*</xsp:include>
>   </xsp:structure>
>  <page>
>   <xsp:logic>
>     Forum forum = new
> Forum("100110000037972710211999191652","102110000048260010251999120317");
> 
>     String fList=forum.readForums("1");
>  </xsp:logic>
>   <xsp:expr>fList</xsp:expr>
>  </page>
> </xsp:page>
> 
> This is what we get
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
>                       "http://www.w3.org/TR/REC-html40/strict.dtd">
> <page>
> 
> 
>   &lt;?xml version=&quot;1.0&quot;?&gt;&lt;FORUMLIST
> number=&quot;1&quot; count=&quot;1&quot;&gt;
>  &lt;FORUM num=&quot;1&quot;&gt;
>   &lt;FORUMID&gt;100110000037972910211999191652&lt;/FORUMID&gt;
>   &lt;NAME&gt;COMMUNITY&lt;/NAME&gt;
>   &lt;SHORTNAME&gt;COMMUNITY&lt;/SHORTNAME&gt;
>   &lt;DESCRIPTION&gt;This is the community forum for community
> EDMUNDS&lt;/DESCRIPTION&gt;
>   &lt;SHARED&gt;0&lt;/SHARED&gt;
>   &lt;MODERATED&gt;0&lt;/MODERATED&gt;
>   &lt;READONLY&gt;0&lt;/READONLY&gt;
>   &lt;CREATIONTIME&gt;1999-10-21 19:16:52&lt;/CREATIONTIME&gt;
>   &lt;NEWINDICATOR&gt;0&lt;/NEWINDICATOR&gt;
>  &lt;/FORUM&gt;
>  &lt;FORUM num=&quot;2&quot;&gt;
>   &lt;FORUMID&gt;100110000037972810211999191652&lt;/FORUMID&gt;
>   &lt;NAME&gt;PERSONALFORUMROOT&lt;/NAME&gt;
>   &lt;SHORTNAME&gt;PERSONALFORUMROOT&lt;/SHORTNAME&gt;
>   &lt;DESCRIPTION&gt;This is the root personal forum for community
> EDMUNDS&lt;/DESCRIPTION&gt;
>   &lt;SHARED&gt;0&lt;/SHARED&gt;
>   &lt;MODERATED&gt;0&lt;/MODERATED&gt;
>   &lt;READONLY&gt;0&lt;/READONLY&gt;
>   &lt;CREATIONTIME&gt;1999-10-21 19:16:52&lt;/CREATIONTIME&gt;
>   &lt;NEWINDICATOR&gt;0&lt;/NEWINDICATOR&gt;
>  &lt;/FORUM&gt;
>  &lt;FORUM num=&quot;3&quot;&gt;
>   &lt;FORUMID&gt;100110000037973010211999191652&lt;/FORUMID&gt;
>   &lt;NAME&gt;TRASHCAN&lt;/NAME&gt;
>   &lt;SHORTNAME&gt;TRASHCAN&lt;/SHORTNAME&gt;
>   &lt;DESCRIPTION&gt;This is the trashcan forum for community
> EDMUNDS&lt;/DESCRIPTION&gt;
>   &lt;SHARED&gt;0&lt;/SHARED&gt;
>   &lt;MODERATED&gt;0&lt;/MODERATED&gt;
>   &lt;READONLY&gt;0&lt;/READONLY&gt;
>   &lt;CREATIONTIME&gt;1999-10-21 19:16:52&lt;/CREATIONTIME&gt;
>   &lt;NEWINDICATOR&gt;0&lt;/NEWINDICATOR&gt;
>  &lt;/FORUM&gt;
> &lt;/FORUMLIST&gt;
>  </page>
> 
> and this is what we want
> 
> <?xml version="1.0"?>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
>                       "http://www.w3.org/TR/REC-html40/strict.dtd">
> <page>
>   <FORUMLIST number="1" count="1">
>  <FORUM num="1">
>   <FORUMID>100110000037972910211999191652</FORUMID>
>   <NAME>COMMUNITY</NAME>
>   <SHORTNAME>COMMUNITY</SHORTNAME>
>   <DESCRIPTION>This is the community forum for community
> EDMUNDS</DESCRIPTION>
>   <SHARED>0</SHARED>
>   <MODERATED>0</MODERATED>
>   <READONLY>0</READONLY>
>   <CREATIONTIME>1999-10-21 19:16:52</CREATIONTIME>
>   <NEWINDICATOR>0</NEWINDICATOR>
>  </FORUM>
>  <FORUM num="2">
>   <FORUMID>100110000037972810211999191652</FORUMID>
>   <NAME>PERSONALFORUMROOT</NAME>
>   <SHORTNAME>PERSONALFORUMROOT</SHORTNAME>
>   <DESCRIPTION>This is the root personal forum for community
> EDMUNDS</DESCRIPTION>
>   <SHARED>0</SHARED>
>   <MODERATED>0</MODERATED>
>   <READONLY>0</READONLY>
>   <CREATIONTIME>1999-10-21 19:16:52</CREATIONTIME>
>   <NEWINDICATOR>0</NEWINDICATOR>
>  </FORUM>
>  <FORUM num="3">
>   <FORUMID>100110000037973010211999191652</FORUMID>
>   <NAME>TRASHCAN</NAME>
>   <SHORTNAME>TRASHCAN</SHORTNAME>
>   <DESCRIPTION>This is the trashcan forum for community
> EDMUNDS</DESCRIPTION>
>   <SHARED>0</SHARED>
>   <MODERATED>0</MODERATED>
>   <READONLY>0</READONLY>
>   <CREATIONTIME>1999-10-21 19:16:52</CREATIONTIME>
>   <NEWINDICATOR>0</NEWINDICATOR>
>  </FORUM>
> </FORUMLIST>
>  </page>

Mime
View raw message