You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jonas Lundberg <my...@gmail.com> on 2006/03/28 18:37:55 UTC
Best way to launch external applications as generators?
I have been looking around for word .doc -> xml converters for a while.
The docvert approach seems promising (
http://holloway.co.nz/docvert/index.html ).
It uses openOffice batch conversion to achieve the transformation. It
does so by invoking:
"C:\Program Files\OpenOffice.org 2.0\program\soffice.exe" %1
macro://macros/Standard.convert.toOasisOpenDocumentFormat(%2,%3)
Let's say I wanted to do this in Cocoon, as a Generator, giving a file
as parameter.
What would the best approach then be? Any ideas?
Regards
Hans
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Best way to launch external applications as generators?
Posted by Jonas Lundberg <my...@gmail.com>.
Hi Simone,
thank's for the advice!
Best regards
Hans
On 3/28/06, Simone Gianni <s....@thebug.it> wrote:
> Hi Jonas,
> I don't know of an existing "ExecuteGenerator", so i think you should
> implement a new generator in java.
>
> AFAIK the oo macros will save the output file, so knowing the input file
> you can specify or desume an output file. If that's the case, you have
> to stream this second file down the pipeline, right?
>
> Inside your new generator you can use a java.lang.Runtime.exec call to
> run the external process. It will return a Process object on which you
> can call the waitFor mathod to wait until it finishes processing, then
> you can get the output (now XML) file and stream SAX events for the
> pipeline, and then eventually delete the output file if you don't need
> it anymore.
>
> If you have a look at the FileGenerator
> (cocoon-2.1.X/src/java/org/apache/cocoon/generation/FileGenerator.java)
> it does generate SAX events from a file. So I think subclassing it could
> be a good choice. You should need to override only the "setup" and
> "generate" methods. In the setup you receive the src="..." from the
> sitemap, which i suppose will contain your .doc document, so put it in a
> field, calculate the resulting output XML file name, and use this as a
> src for the super.setup() call. In the "generate" method, simply run the
> external soffice.exe, wait for it to finish, the call super.generate()
> and have the FileGenerator stream the resulting file for you. Then
> eventually delete it.
>
> If properly configured in the sitemap, you can have cocoon cache the
> result for you, so that soffice.exe isn't called too often.
>
> It's not the easier task, but I hope this helps.
>
> Simone
>
> Jonas Lundberg wrote:
>
> >I have been looking around for word .doc -> xml converters for a while.
> >The docvert approach seems promising (
> >http://holloway.co.nz/docvert/index.html ).
> >It uses openOffice batch conversion to achieve the transformation. It
> >does so by invoking:
> >"C:\Program Files\OpenOffice.org 2.0\program\soffice.exe" %1
> >macro://macros/Standard.convert.toOasisOpenDocumentFormat(%2,%3)
> >
> >Let's say I wanted to do this in Cocoon, as a Generator, giving a file
> >as parameter.
> >What would the best approach then be? Any ideas?
> >
> >Regards
> >Hans
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> >For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
> >
> --
> Simone Gianni
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: Best way to launch external applications as generators?
Posted by Simone Gianni <s....@thebug.it>.
Hi Jonas,
I don't know of an existing "ExecuteGenerator", so i think you should
implement a new generator in java.
AFAIK the oo macros will save the output file, so knowing the input file
you can specify or desume an output file. If that's the case, you have
to stream this second file down the pipeline, right?
Inside your new generator you can use a java.lang.Runtime.exec call to
run the external process. It will return a Process object on which you
can call the waitFor mathod to wait until it finishes processing, then
you can get the output (now XML) file and stream SAX events for the
pipeline, and then eventually delete the output file if you don't need
it anymore.
If you have a look at the FileGenerator
(cocoon-2.1.X/src/java/org/apache/cocoon/generation/FileGenerator.java)
it does generate SAX events from a file. So I think subclassing it could
be a good choice. You should need to override only the "setup" and
"generate" methods. In the setup you receive the src="..." from the
sitemap, which i suppose will contain your .doc document, so put it in a
field, calculate the resulting output XML file name, and use this as a
src for the super.setup() call. In the "generate" method, simply run the
external soffice.exe, wait for it to finish, the call super.generate()
and have the FileGenerator stream the resulting file for you. Then
eventually delete it.
If properly configured in the sitemap, you can have cocoon cache the
result for you, so that soffice.exe isn't called too often.
It's not the easier task, but I hope this helps.
Simone
Jonas Lundberg wrote:
>I have been looking around for word .doc -> xml converters for a while.
>The docvert approach seems promising (
>http://holloway.co.nz/docvert/index.html ).
>It uses openOffice batch conversion to achieve the transformation. It
>does so by invoking:
>"C:\Program Files\OpenOffice.org 2.0\program\soffice.exe" %1
>macro://macros/Standard.convert.toOasisOpenDocumentFormat(%2,%3)
>
>Let's say I wanted to do this in Cocoon, as a Generator, giving a file
>as parameter.
>What would the best approach then be? Any ideas?
>
>Regards
>Hans
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
--
Simone Gianni
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org