You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Gaston Martini <hg...@ciudad.com.ar> on 2005/09/13 00:59:50 UTC

Java stream into pipeline?

Hi all

Our problem is this: we need to embed a dynamically generated SVG chart into an XHTML page (also dynamically generated).

THIS IS OUR APPROACH:
We have an SVG chart in a java stream generated by Batik. We need to insert it into a pipeline and serialize it.

In Java code:
	... create a JFreeChart ...
	JFreeChart chart = ChartFactory.create...
       Document document = GenericDOMImplementation.getDOMImplementation().createDocument(null, "svg", null);
       SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
       chart.draw(svgGenerator, new Rectangle2D.Double(0, 0, 400, 300), null);
	... create an output stream ...
       Writer out = new ...
       svgGenerator.stream(out, true); // now 'out' has the svg code we want
	...

In the XHTML page:
	...
        <object type="image/svg+xml" data="chart" ...> <!-- this object gets its data from the 'chart' pipeline -->
            ...
        </object>
	...

In the sitemap
	<map:match pattern="chart">
		???? how do we get the svg in here?
       	<map:serialize type="svgxml"/>
	</map:match>



AND THE QUESTION:
¿How can we get the stream into the pipeline? OR ¿is there a better way to do it?

Thanks in advance

Martín and Gastón

Re: Java stream into pipeline?

Posted by Jorg Heymans <jh...@domek.be>.
Jason Johnston wrote:
>>
>> ¿How can we get the stream into the pipeline? OR ¿is there a better
>> way to do it?
> 
> 

1.
> One possible approach might be to use the ModuleSource[1] in your
> map:generate to access the XML using an input module.  If you can get
> the InputStream onto the request as a request attribute then you can do
> something like:
> 
> <map:generate src="module:request-attr:requestAttributeName" />
> 

2.
> Or if you're coming from flowscript you can use the flow-attr: module. I
> use this technique quite a bit.
> 
> 

or 3:

If you're not using flow and are happy to stick this into a plain
generator :

public void generate() throws .... {
XMLReader parser =
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
parser.setContentHandler(this.contentHandler);
parser.parse(new InputSource(yourInputStreamHere);
}

Lots of possibilities really ;-)


HTH
Jorg


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


Re: Java stream into pipeline?

Posted by Jason Johnston <co...@lojjic.net>.
Gaston Martini wrote:
> Hi all
> 
> 
> Our problem is this: we need to embed a dynamically generated SVG chart 
> into an XHTML page (also dynamically generated).
> 
> 
> THIS IS OUR APPROACH:
> 
> We have an SVG chart in a java stream generated by Batik. We need to 
> insert it into a pipeline and serialize it.
> 
> 
> In Java code:

...

Where is this Java code executed?  In flow?  A sitemap action?  Elsewhere?

> 
> AND THE QUESTION:
> 
> ¿How can we get the stream into the pipeline? OR ¿is there a better way 
> to do it?

One possible approach might be to use the ModuleSource[1] in your 
map:generate to access the XML using an input module.  If you can get 
the InputStream onto the request as a request attribute then you can do 
something like:

<map:generate src="module:request-attr:requestAttributeName" />

Or if you're coming from flowscript you can use the flow-attr: module. I 
use this technique quite a bit.


[1] 
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/components/source/impl/ModuleSource.html

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