Hi There.

It is exactly this sort of problem that got me started on the other thread.
I differ slightly with your method though in that I tend to prefer pulling
in the data as required at the transformation stage rather than assembling
it all pre-packed at the Server Page stage.

<< Just saw your second post ;-) Glad it is solved - interesting for me too
>>

However I am still hoping it is going to be possible to create Request aware
URIResolvers that will be able to be called from document(). Haven't tried
it yet - but will in the next couple of days. 

If the worst really came to the worst you could create a threadsafe "static
store" in which to store the object model (request, session etc.) and pass a
unique key from your XSP page that could be picked up in the XSLT stage and
used by the resolver to retrieve the context, etc.

Ah well, so much to learn so little time.

Luke



-----Original Message-----
From: Lai, Harry [mailto:[EMAIL PROTECTED]] 
Sent: 06 December 2001 23:58
To: 'CocoonUsers'
Subject: Inserting dynamic XML at request time

Hi all,
 
I have a question that's related to the "Inserting / Comining XML data"
thread, but which I believe is slightly different.  Here's the situation.
 
SCENARIO
-----------------
We are using Cocoon 2, and we would like to use an XSP doc as a "shell" that
aggregates XML data from one or more Java objects (the objects would
actually output XML strings).  These Java objects (possibly EJB's) would
need access to the Request object in order to do their processing.  So,
here's what we originally tried (most of you will probably see the flaw
pretty quickly).
 
PROBLEM
----------------
We have a Java object like this (this sample is a simplified version of what
we're actually planning to do, but it illustrates the problem we're running
into):
 
    public class Foo {
        public getXML(Request req) {
            return "<foo>This is a foo tag.</foo>";
        }
    }
 
And we have this XSP doc:
 
    <xsp:page language="java" xmlns:xsp=" http://apache.org/xsp
<http://apache.org/xsp> ">
        <xsp:structure>
            <xsp:include>com.coremetrics.test.Foo</xsp:include>
        </xsp:structure>
        <xsp:logic>
            Foo f = new Foo();
        </xsp:logic>
    
        <page>
            <xsp:expr>f.getXML(request)</xsp:expr>
        </page>
    </xsp:page>
 
Unfortunately, <xsp:expr> renders the return value as a text node, so we got
the text content "&lt;foo%gt;..." as the content of our page node in the
resulting xml.  SO...
 
We considered using the document() function with the custom URI handlers (as
discussed in the aforementioned thread), but while we could render the
request parameters out as string args for the URI, we would lose any other
info on the request (such as cookies, attributes, etc.).
 
PROPOSED SOLUTION
-----------------------------------
So we're thinking about modifying cocoon as follows:
 
1) Define a new xsp tag "xsp:exprXml" that operates like xsp:expr but treats
its content as xml.
2) Define a new method (or set of methods) in XSPObjectHelper.  This method
will take a ContentHandler
    and an xml String.  It will either instantiate or get a SAX parser
(maybe a pool), and set the parser's
    content handler to the ContentHandler passed in.  It will then use the
SAX parser to parse the String.
3) Add a template for xsp:exprXml in xsp.xsl, and have it use the new
XSPObjectHelper method.
 
My question is, does this approach sound right?  Are there better ways we
can do this?  Are there ways we can do this without modifying cocoon?  I'm a
cocoon newbie, so any advice would be much appreciated.  Thanks!
 
Harry

-------------- 
Harry Lai 
[EMAIL PROTECTED] 
512.342.2623 x2170 

 

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to