You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Nicola Ken Barozzi <ni...@apache.org> on 2002/09/06 10:14:06 UTC
[Morphos] Re: Another API idea
How Fop can use Morphos:
Jeremias Maerki wrote:
> My head's smoking at the moment. After reading the InfoMover threads
> again and thinking about performance/tread-safety implications of
> various approaches I can't think clearly anymore.
Hehehe. It happened to me too, it's really hard.
> That's why I simply
> dump an idea on the API I've had 6 weeks ago for now. It's not related
> to Morphos and but rather orients itself on JAXP. Maybe it helps for
> this discussion.
>
> //Setup XSL transformation
> TransformerFactory tf = TransformerFactory.newInstance();
> Source xslt = new StreamSource(myStylesheetURL);
> Transformer t = tf.newTransformer(xslt);
> Source src = new StreamSource(File myxmlfile);
>
> //Setup FOP
> FOProcessorFactory fopFactory = new FOProcessorFactory();
> fopFactory.setOutputFormat("application/pdf");
> // or:
> // Properties outputProps = new Properties();
> // outputProps.put("compressed", "false");
> // fopFactory.setOutputFormat("application/pdf", Properties props);
> fopFactory.setProperty("baseURL", "file://D:/Temp");
>
> //Prepare Processor
> FOProcessor fop = fopFactory.newProcessor();
> Result pdfres = new StreamResult(File mypdffile);
> // for AWT: AWTResult
> fop.setResult(pdfres);
>
> //Start transformation
> t.transform(src, fop.getResultForJAXP());
>
> This possibility uses as much from JAXP as possible which means using
> almost the same patterns everyone is used to.
It's basically identical to the Morphos way, it seems we got to the same
conclusions from different paths, which is good :-)
// Create the Manager that gives me the morphers
MorpherFactory mfactory = new SimpleMorpherFactory(Hashtable confs);
// Get a jaxp Morpher by name
Morpher jaxpmorpher = mfactory.getMorpher("jaxp");
// Get a fop Morpher by name
Morpher fopmorpher = mfactory.getMorpher("fop");
// Get a Morpher that serializes an XML dom to a stream
Morpher streammorpher =
mfactory.getMorpher(
new DataType("text/xml", "object/dom"),
new DataType("text/xml", "stream/unix")
);
//Configure the Morphers
PropertyUtils.setSimpleProperty(jaxpmorpher,
"stylesheet",
"transform.xsl");
PropertyUtils.setSimpleProperty(foppmorpher,
"baseURL",
"file://D:/Temp");
//Chain the three:
MorpherPipeline mpipeline = new SimpleMorpherPipeline();
mpipeline.addStage(jaxpmorpher );
mpipeline.addStage(fopmorpher );
mpipeline.addStage(streammorpher );
// Now I have my pipeline. I can now morph many times I want
// (here once)
try{
SimpleErrorHandler simpleErrorInfo = new SimpleErrorHandler ();
Map runInfo = new HashMap();
runinfo.put("lenient", true);
mpipeline.morph(myDomObject, outputstream
simpleErrorInfo, runInfo );
}
catch(MorphException? ioe){
.....}
catch(OblectFlavorException? ofe){
.....}
System.out.println(simpleErrorInfo.getMessages());
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>