You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Dave Neary <da...@palamon.ie> on 2001/10/01 13:30:13 UTC
Passing document, request & resonse to other methods
Hi all,
Yet again, this may come across as a silly question, but it's kind of a
question on "best practice" - is it considered acceptable to pass
document & request to methods like I've done below? If it is, is it
better to return an element, or append that element to document
directly? Here's the example code (just a hello world).
Apologies if these posts seem silly, I just want to make sure I'm not
abusing xsp at this stage, so that later on my code will look a bit
better & be easier to maintain (hopefully).
<xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<xsp:logic>
Node hello1(Document document, HttpServletRequest request)
{
Node n = document.createTextNode("Hello, world!\n");
return n;
}
void hello2(Document document, HttpServletRequest request)
{
Node n = document.createTextNode("Hello, world!\n");
document.getDocumentElement().appendChild(n);
return;
}
</xsp:logic>
<page>
<!-- One of these two is better... or are they both equally bad? -->
<xsp:logic>hello2(document, request);</xsp:logic>
<xsp:expr>hello1(document, request)</xsp:expr>
</page>
</xsp:page>
Cheers,
Dave.
--
David Neary, E-Mail dave.neary@palamon.ie
Palamon Technologies Ltd. Phone +353-1-634-5059
---------------------------------------------------------------------
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: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: Passing document, request & resonse to other methods
Posted by Dave Neary <da...@palamon.ie>.
Adrian Geissel wrote:
>
> Hi Dave,
>
> why not just let the XSP processor create the DOM nodes - and use the
> <xsp:logic/> and <xsp:expr/> tags to embed functionality in the output.
> If you need to control the addition of elements to the DOM in your own code,
> then use the <xsp:element/>, <xsp:attribute/> and <xsp:content/> tags -
> they'll be properly resolved, less coding and fewer errors as a result (and
> C2 SAX-based compatibility for free!).
The issue was merging XML from outside sources (database) into the
document - and apparrently the best way to do that is with the context
node (xspParentNode, xspCurrentNode), rather than doing stuff directly
with the document (which makes sense).
An example of what I was trying to do is...
<xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<xsp:structure>
<xsp:include>my.personal.sql.wrapper.package.*</xsp:include>
</xsp:structure>
<xsp:logic>
void insertNode(Document doc, Node current, int object_id)
{
SQLQuery sqlq = new SQLQuery();
Node my_xml = sqlq.getObjectById(object_id);
doc.importNode(my_xml);
current.appendChild(my_xml);
// Or something similar... this is a rough sketch
}
</xsp:logic>
<page>
<xsp:logic>
String []objstrings= request.getParameterValues("object_id");
int object_id = Integer.valueOf(objstrings[0]);
insertNode(document, xspCurrentNode, object_id);
</xsp:logic>
</page>
</xsp:page>
Thanks for the help,
Dave.
--
David Neary, E-Mail dave.neary@palamon.ie
Palamon Technologies Ltd. Phone +353-1-634-5059
---------------------------------------------------------------------
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: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>
Re: Passing document, request & resonse to other methods
Posted by Adrian Geissel <ag...@zenark.com>.
Hi Dave,
why not just let the XSP processor create the DOM nodes - and use the
<xsp:logic/> and <xsp:expr/> tags to embed functionality in the output.
If you need to control the addition of elements to the DOM in your own code,
then use the <xsp:element/>, <xsp:attribute/> and <xsp:content/> tags -
they'll be properly resolved, less coding and fewer errors as a result (and
C2 SAX-based compatibility for free!).
eg.
<xsp:page language="java"
xmlns:xsp="http://www.apache.org/1999/XSP/Core">
<page>
<xsp:content>Hello World!</xsp:content>
<my-new-element>Some more text</my-new-element>
</page>
</xsp:page>
----- Original Message -----
From: Dave Neary <da...@palamon.ie>
To: <co...@xml.apache.org>
Sent: Monday, October 01, 2001 12:30 PM
Subject: Passing document, request & resonse to other methods
>
> Hi all,
>
> Yet again, this may come across as a silly question, but it's kind of a
> question on "best practice" - is it considered acceptable to pass
> document & request to methods like I've done below? If it is, is it
> better to return an element, or append that element to document
> directly? Here's the example code (just a hello world).
>
> Apologies if these posts seem silly, I just want to make sure I'm not
> abusing xsp at this stage, so that later on my code will look a bit
> better & be easier to maintain (hopefully).
>
> <xsp:page language="java"
> xmlns:xsp="http://www.apache.org/1999/XSP/Core">
>
> <xsp:logic>
> Node hello1(Document document, HttpServletRequest request)
> {
> Node n = document.createTextNode("Hello, world!\n");
>
> return n;
> }
>
> void hello2(Document document, HttpServletRequest request)
> {
> Node n = document.createTextNode("Hello, world!\n");
> document.getDocumentElement().appendChild(n);
>
> return;
> }
> </xsp:logic>
>
> <page>
> <!-- One of these two is better... or are they both equally bad? -->
> <xsp:logic>hello2(document, request);</xsp:logic>
> <xsp:expr>hello1(document, request)</xsp:expr>
> </page>
> </xsp:page>
>
> Cheers,
> Dave.
>
> --
> David Neary, E-Mail dave.neary@palamon.ie
> Palamon Technologies Ltd. Phone +353-1-634-5059
>
> ---------------------------------------------------------------------
> 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: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>
>
>
---------------------------------------------------------------------
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: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>