Thank you.

-----Original Message-----
From: Peter Harrison [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 08, 2005 3:54 PM
To: Velocity Users List
Subject: RE: non-HTML output - PDF and OpenOffice
Importance: Low

On Tue, 2005-02-08 at 14:46 -0500, Assia Aouat wrote:
> Do you have an example?

This is part of a class that deals with all kinds of output, but this
method is specifically for OpenOffice. fullPath is a class variable
representing the template name.

In answer to a previous question - no its not that difficult, however it
is astonishingly useful for creating documents. It is however limited,
as when editing the documents you can't put velocity between XML tags.
In some cases we have manually modified the content.xml in order to get
certain effects in velocity.


-------

        public void ooStyle( OutputStream out )
        {
                final int BUFSIZE = 4096;
                try {
                        ZipFile zipin = new ZipFile( fullPath );
                        ZipOutputStream zipout = new ZipOutputStream(
out );

                        Enumeration all = zipin.entries();

                        byte[] b = new byte[BUFSIZE];

                        while( all.hasMoreElements() ) {
                                ZipEntry entry = (ZipEntry)
all.nextElement();

                                // Copy from one to the other
                                ZipEntry newEntry = new ZipEntry(
entry.getName() );
                                zipout.putNextEntry( newEntry );
                                InputStream is = new
BufferedInputStream( zipin.getInputStream( entry ), BUFSIZE );

                                if( "content.xml".equals(
entry.getName() ) ) {
                                        // Velocity
                                        Reader reader = new
InputStreamReader( is );
                                        Writer writer = new
OutputStreamWriter( zipout, "ISO-8859-1" );
                                        try {
                                                Velocity.evaluate(
context, writer, "ERROR:", reader);
                                        } catch (
MethodInvocationException e ) {
                                                e.printStackTrace( );
                                        } catch ( ParseErrorException e
) {
                                                e.printStackTrace( );
                                        } catch (
ResourceNotFoundException e ) {
                                                e.printStackTrace( );
                                        }
                                        writer.flush();
                                } else {
                                        // Simple Copy - No Velocity
                                        int n=0;
                                        while ( (n = is.read(b)) > 0 ) {
                                                zipout.write( b, 0, n);
                                        }
                                }

                                zipout.closeEntry();
                        }
                        zipout.finish();
                } catch ( IOException e ) {
                        e.printStackTrace( );
                }
        }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to