cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Re: XObjects / document fragments
Date Thu, 21 Sep 2000 09:04:43 GMT
At 16:27 +0200 20/09/00, Echoes wrote:
>  Hello,
>
> I'm trying to insert in the output tree the
>value of some attributes from a java object.
>I can do this in the xsp page with this kind of
>code :
>
>
><xsp:content><tag_name><xsp:expr>myObject.getName()</xsp:expr></xsp:content>
>
> It's alright when there is only a few fields, but becomes a nightmare
>with complex objects.
>
> I heard about document fragments and XObjects that can do the job in
>a cleaner way, but I can't find any description, or better a small
>example.


I have been using XObject for implementing TagLibs, this is an untested and
trivial example of the general technique.



in your xsp:

<xsp:expr>new myObject()</xsp:expr>





myObject.java

import org.apache.cocoon.framework.XObject;
import org.w3c.dom.*;
import org.xml.sax.*;

public class myObject() implements XObject {

	String message = new String("you got me Geeza!");

	public myObject() {
		// set me up
	}

	public void toDOM(Node node) {
		// this is used by C1
		Document doc = node.getOwnerDocument();
		node.appendChild(doc.createTextNode(message));
	}

	public void toSAX(DocumentHandler handler) {
		// this is used by C2
		// and I do not know how to write it yet :)
	}

	public String toString() {
		// used by <xsp:attribute name="blah">new myObject()</xsp:attribute>
		return message;
	}

}


Hope this helps.

regards Jeremy

-- 
   ___________________________________________________________________

   Jeremy Quinn                                           Karma Divers
                                                       webSpace Design
                                            HyperMedia Research Centre

   <mailto:sharkbait@mac.com>     		 <http://www.media.demon.co.uk>
    <phone:+44.[0].20.7737.6831>        <pager:jermq@sms.genie.co.uk>

Mime
View raw message