cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorsten Mauch <ma...@imkenberg.de>
Subject RE: How to intgrate existing XML-Doc in XSP
Date Sun, 15 Oct 2000 21:26:38 GMT
Thank you for the detailed answer. My first approachwas to
write a producer an this solution i like very much. Because
I'am a Java Developer who is responsible for the business objects
it's easier for me to deal with the producer Interface instead
dealing with the hybrid language is the XSP. Besides this my 
business objects alrady have the method getXMLDoc() witch returns
a org.w3c.Document not a String.
But I have read the the programming Model will change in Cocoon 2,
so it's recommended to write XSP instead of producers.
But maybe it's a better soulution to write a processor 
instead ?


-----Urspr√ľngliche Nachricht-----
Von: Robin Green [mailto:greenrd@hotmail.com]
Gesendet: Sonntag, 15. Oktober 2000 23:31
An: cocoon-users@xml.apache.org
Betreff: Re: How to intgrate existing XML-Doc in XSP


Thorsten Mauch <mauch@imkenberg.de> wrote:
>I have already classes that produce XML-Documents but
>I don't know how to integrate them into the XSP. I tried the
>following code:
>
><?xml version="1.0"?>
><?cocoon-process type="xsp"?>
>
><xsp:page
>   language="java"
>   xmlns:xsp="http://www.apache.org/1999/XSP/Core">
>
><xsp:logic>
>     com.imkenberg.bo.Customer customer   =
>com.imkenberg.bo.Customers.getCustomer(1223);
>     try{
>       document= customer.getXMLDoc();
>     }
>     catch(Exception ex){}

I'll answer your question in a second, but first this -

Note: This blank catch clause is bad practice - it hinders debugging. XSP 
lets you throw anything, so just get rid of the try and the catch! If you 
want to hide the gritty details of errors from your end users, disable 
handle.errors.internally in cocoon.properties instead - then you can flip 
debugging on and off by changing one line, instead of laboriously changing 
various bits of code (imagine if you have 100s of empty catch clauses in a 
complex system, and you don't know where the problem is - pain eh?)

>
></xsp:logic>
></xsp:page>
>
>but if I inspect the generated Producer the code appear in
>the declaration section. But what i want is to override the
>populateDocument() method.

You can't do this, basically, because XSP always generates one and you can't

override a method in the same class. Well you could try and comment it out 
in the generated code, but that's a REALLY bad hack and if you're going to 
go that far it would be easier to write a Producer anyway!

>How can I archive this ?

There are two problems here.

1. All XSP pages require an explicit root element - this is how it 
distinguishes between page-generating code (which goes in the page root 
element) and declarations (which go outside).

Workaround: put the logic inside a dummy <page> element which will be 
overwritten. Or, better, mandate that all documents will have <page> as 
their root, then it won't be quite so confusing.

2. You can't just reassign the document variable - in Java parameters  are 
passed, in informal terms, "by value" (in this case the value of the 
reference to the document object), so the reassignment would only have an 
effect inside the populateDocument method, but Cocoon would actually still 
use the original document (which would be empty and probably invalid) after 
that had returned.

Workaround:

<xsp:logic>
Document doc2 = myBean.getDocument ();
// overwrite dummy root <page> element
document.replaceChild (xspCurrentNode, doc2.getFirstChild ().clone (true)); 
// do a deep clone
</xsp:logic>

If you wrote a producer or producers instead you wouldn't have either of 
these inconveniences, but then the invocation would be different 
(myfile.xml?producer=myproducer, which isn't ideal). This messy invocation 
will go away in Cocoon 2 by the way.

Also, you are generating an org.w3c.Document, right, not a String? :-)



_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.


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

Mime
View raw message