Return-Path: Mailing-List: contact cocoon-users-help@xml.apache.org; run by ezmlm Delivered-To: mailing list cocoon-users@xml.apache.org Received: (qmail 67572 invoked from network); 15 Oct 2000 21:30:37 -0000 Received: from p3e9c203d.dip.t-dialin.net (HELO cdserver.imkenberg.de) (root@62.156.32.61) by locus.apache.org with SMTP; 15 Oct 2000 21:30:37 -0000 Received: from mx.imkenberg.de (imkedvpdc [10.0.1.1]) by cdserver.imkenberg.de (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) with ESMTP id WAA01702 for ; Sun, 15 Oct 2000 22:35:09 +0200 Received: by imkedv_pdc with Internet Mail Service (5.5.2650.21) id <4M4SVH7L>; Sun, 15 Oct 2000 23:26:40 +0200 Message-ID: From: Thorsten Mauch To: "'cocoon-users@xml.apache.org'" Subject: RE: How to intgrate existing XML-Doc in XSP Date: Sun, 15 Oct 2000 23:26:38 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N 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=20 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=20 instead ? -----Urspr=FCngliche 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 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: > > > > > language=3D"java" > xmlns:xsp=3D"http://www.apache.org/1999/XSP/Core"> > > > com.imkenberg.bo.Customer customer =3D >com.imkenberg.bo.Customers.getCustomer(1223); > try{ > document=3D 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=20 lets you throw anything, so just get rid of the try and the catch! If = you=20 want to hide the gritty details of errors from your end users, disable=20 handle.errors.internally in cocoon.properties instead - then you can = flip=20 debugging on and off by changing one line, instead of laboriously = changing=20 various bits of code (imagine if you have 100s of empty catch clauses = in a=20 complex system, and you don't know where the problem is - pain eh?) > > > > >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=20 in the generated code, but that's a REALLY bad hack and if you're going = to=20 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=20 distinguishes between page-generating code (which goes in the page root = element) and declarations (which go outside). Workaround: put the logic inside a dummy element which will be=20 overwritten. Or, better, mandate that all documents will have as = their root, then it won't be quite so confusing. 2. You can't just reassign the document variable - in Java parameters = are=20 passed, in informal terms, "by value" (in this case the value of the=20 reference to the document object), so the reassignment would only have = an=20 effect inside the populateDocument method, but Cocoon would actually = still=20 use the original document (which would be empty and probably invalid) = after=20 that had returned. Workaround: Document doc2 =3D myBean.getDocument (); // overwrite dummy root element document.replaceChild (xspCurrentNode, doc2.getFirstChild ().clone = (true));=20 // do a deep clone If you wrote a producer or producers instead you wouldn't have either = of=20 these inconveniences, but then the invocation would be different=20 (myfile.xml?producer=3Dmyproducer, which isn't ideal). This messy = invocation=20 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=20 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