cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke Studley <>
Subject RE: Inserting / Comining XML data
Date Wed, 05 Dec 2001 15:38:13 GMT
Thanks Karl.

Glad to know somebody has had similar thoughts/needs.

I will try this. You're right this doesn't replace generators - but it does
allow you to quite easily implement some sort of "Pull MVC" model a opposed
to the generator push model - and will allow me to use my existing
stylesheets mostly unchanged.



-----Original Message-----
From: Karl Øie [] 
Sent: 05 December 2001 12:49
Subject: RE: Inserting / Comining XML data 

> 3. Maybe I could use some sort of custom URL protocol manager like the
> cocoon:/ and resource:/? Is it possible to supply new instances of these?
> 4. Or I could use my URI resolvers again? Is it possible to set Custom URI
> solvers in C2

i have found two ways to accomplish this, but it took some time to find out,
mostly because this is not very well documented yet... ok here we go:

in the "cocoon.xconf" file there is a "source-handler" entry, you can create
own protocols here:

	<protocol name="cool"

then you will have to create two classes called
"org.apache.cocoon.components.source.CoolSourceFactory" and
"org.apache.cocoon.components.source.CoolSource". they will have to
implement "org.apache.cocoon.components.source.SourceFactory" and
"org.apache.cocoon.environment.Source". Where the "CoolSourceFactory"
resolves urls with cool:/some/thing.xml and creates a "CoolSource" for it.
now you can refere to "cool:/some/thing.xml" many places in your project.

BUT this didn't work for me because the
"org.apache.cocoon.environment.Source" interface expects a
org.xml.sax.InputSource and it delivers a characterstream or bytestream
back, and i had a sax/dom source and i didn't want to serialize it to text
to get it parsed again... so i snooped around some more and found this:

again in your "cocoon.xconf" there is an entry for your default transformer.
i hacked mine like this:

	<parameter name="use-store" value="true"/>
	<parameter name="incremental-processing" value="false"/>

then i created a class "called
org.apache.cocoon.components.xslt.KarlsXSLTProcessorImpl" containing this
(please not that i had to create it in the org.apache.cocoon.components.xslt
package to be allowed to extend XSLTProcessorImpl) :

public class XonataXSLTProcessorImpl extends XSLTProcessorImpl {
	public javax.xml.transform.Source resolve(String href, String base)
TransformerException {
		if (!href.startsWith("karl:")) {
			return super.resolve(href,base);
		else {
			SAXSource source = new SAXSource( ... );
			DOMSource source = new DOMSource( ... );
			StreamSource source = new StreamSource( ... );
			return source;

this way i can respond and create any SAX/DOM/Stream source for any protocol
for the transformer, and i can use "document('rmi://myserver/mydatachunk')"
in my xsl documents. this does not replace a generator thou....

i would be happy if anyone could tell me if there is an easier way to create
protocol handlers that can deliver SAX or DOM and not only Stream.

mvh karl øie

Please check that your question has not already been answered in the
FAQ before posting. <>

To unsubscribe, e-mail: <>
For additional commands, e-mail: <>

Please check that your question has not already been answered in the
FAQ before posting. <>

To unsubscribe, e-mail: <>
For additional commands, e-mail: <>

View raw message