You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Luke Studley <Lu...@cerillion.com> on 2001/12/04 19:31:53 UTC
Inserting / Comining XML data
Hiya - Newbie question again,
I'm looking for some advice on the best way to include some dynamically
generated XML data in C2.
I'm new to this, but can see there are a plethora of ways, but I can't yet
see the best way for me.
In my original system I used XSL stylesheets and Custom URIResolvers to
'pull' data in to a stylesheet using the document() function - e.g.
document('rmi://myserver/mydatachunk') sort of thing.
How is this sort of thing accomplished with C2?
1. Using XSP seems to be a good way to insert some small strings - but I
couldn't see any examples (or if it is possible) to insert whole XML
documents in situ in the target doc. And besides to choose which data to
insert at this level seems to break the MVC paradigm - as I need to know
about the view I am catering for.
2. Aggregating - this again seems like a push method whereby you have to
have the data already in memory or on disk somewhere in order to combine it.
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
resolvers in C2
5. I haven't had much to do with actions yet? Could they be used to load the
XML data chunk and stick it in some sort of context that could then be fed
into the Transformer layer.
Please tell me what you think / flame me etc. as I'm all in a muddle.
Yours, slightly frustrated but very keen and impressed newbie C2 user
Luke Studley
---------------------------------------------------------------------
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: Inserting / Comining XML data
Posted by Karl Øie <ka...@gan.no>.
> 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:
<source-handler>
<protocol name="cool"
class="org.apache.cocoon.components.source.CoolSourceFactory"/>
</source-handler>
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:
<xslt-processor
class="org.apache.cocoon.components.xslt.KarlsXSLTProcessorImpl"
logger="root.xslt">
<parameter name="use-store" value="true"/>
<parameter name="incremental-processing" value="false"/>
</xslt-processor>
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) throws
TransformerException {
if (!href.startsWith("karl:")) {
return super.resolve(href,base);
}
else {
SAXSource source = new SAXSource( ... );
or
DOMSource source = new DOMSource( ... );
or
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. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>