From 31ec3a99d0f45f928f850fbdad256684d4627a14 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Tue, 17 Mar 2009 14:36:28 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@969 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../higiene/relatorio/print/TestPrint.java | 91 ++++++++++++ .../higiene/relatorio/print/teste_input2.xml | 138 ++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java create mode 100644 trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/teste_input2.xml diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java new file mode 100644 index 00000000..142d542d --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/TestPrint.java @@ -0,0 +1,91 @@ +package siprp.higiene.relatorio.print; + +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import com.evolute.utils.fop.PDFCreator; +import com.evolute.utils.xml.XSLTransformer; + +public class TestPrint +{ + public static void main( String args[] ) + throws Exception + { + new TestPrint().test(); + } + + public void test() + throws Exception + { + FileOutputStream fos; + +// PlanoActuacaoDBInit.initDB(); +// PlanoActuacaoToPrint plano = PlanoActuacaoPrintDataProvider.getProvider().getPlanoToPrint( 6 ); + Element evoluteElement = new Element( "evolute" ); + Document foDoc = new Document( evoluteElement ); + Format pretty = Format.getPrettyFormat(); + pretty.setIndent("\t"); + XMLOutputter outputter = new XMLOutputter(pretty); + ByteArrayOutputStream foBaos = new ByteArrayOutputStream(); + outputter.output( foDoc, foBaos ); +// FileOutputStream fos = new FileOutputStream( "/home/fpalma/Desktop/in.xml" ); +// fos.write( foBaos.toByteArray() ); +// fos.close(); + + byte fo[] = applyTemplate( +// "siprp/planoactuacao/print/plano_actuacao.xsl", +// getClass().getClassLoader().getResourceAsStream( "siprp/higiene/relatorio/relatorio.xsl" ), + new FileInputStream( "/home/fpalma/projectos2/SIPRP/SIPRPSoft/src/siprp/higiene/relatorio/relatorio.xsl" ), +// "siprp/planoactuacao/print/teste_input.xml" ); + new FileInputStream( "/home/fpalma/projectos2/SIPRP/SIPRPSoft/src/siprp/higiene/relatorio/teste_input.xml" ) ); +// new ByteArrayInputStream( foBaos.toByteArray() ) ); +// new ByteArrayInputStream( "".getBytes() ) ); +// System.out.println( new String( fo ) ); + createPDFFile( fo, "/home/fpalma/Desktop/out.pdf" ); +// createPDFFile( fo, "c:/Documents and Settings/Frederico/Ambiente de Trabalho/out.pdf" ); + + fos = new FileOutputStream( "/home/fpalma/Desktop/out.xml" ); + fos.write( fo ); + fos.close(); + +// for( int n = 1; n <= 7; n++ ) +// { +// byte pdf[] = new PlanoActuacaoPDFCreator().createPDF( n, false ); +// FileOutputStream fos = new FileOutputStream( "/home/fpalma/Desktop/" + n + ".pdf" ); +// fos.write( pdf ); +// fos.close(); +// } + } + + public void createPDFFile( byte fo[], String path ) + throws Exception + { + byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( fo ); + FileOutputStream fos = new FileOutputStream( path ); + fos.write( pdf ); + fos.close(); + } + + public byte[] applyTemplate( String template, String data ) + throws Exception + { + InputStream xsl = getClass().getClassLoader().getResourceAsStream( template ); + InputStream xml = getClass().getClassLoader().getResourceAsStream( data ); + return( applyTemplate( xsl, xml ) ); + } + + public byte[] applyTemplate( InputStream xsl, InputStream dataStream ) + throws Exception + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XSLTransformer.getXSLTransformer().transform( dataStream, xsl, baos ); + return baos.toByteArray(); + } +} diff --git a/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/teste_input2.xml b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/teste_input2.xml new file mode 100644 index 00000000..d305826b --- /dev/null +++ b/trunk/SIPRPSoft/src/siprp/higiene/relatorio/print/teste_input2.xml @@ -0,0 +1,138 @@ + + + + + COMPANHIA PORTUGUESA DE HIPERMERCADOS + + ALVERCA + http://apdp/siprp/auchan_jumbo_lado.jpg + rua do estabelecimento + + + 2008 + 4 + Abril + 29 + + + 2008 + 3 + Março + 1 + + + + Lei nº 99/2003 de 27 de Agosto regulamentada pela Lei + nº 35/2004 de 29 de Julho – Aprova o novo Código + de Trabalho + + + Decreto-Lei n.º441/91 de 14 de Novembro, alterado pelo + Decreto-Lei n.º133/99 de 21 de Abril – Estabelece o + regime jurídico do enquadramento da segurança, + higiene e saúde do trabalho + + + Decreto-Lei n.º26/94, de 1 de Fevereiro, alterado pela + Lei n.º7/95 de 29 de Março e pelo Decreto-Lei + n.º109/2000 – Regime de Organização e + funcionamento dos serviços da segurança, higiene e + saúde do trabalho + + + + + Acidentes de Trabalho e Doenças Profissionais + + + + Lei nº 99/2003 de 27 de Agosto regulamentada pela + Lei nº 35/2004 de 29 de Julho – Aprova o novo + Código de Trabalho + + + Decreto-Lei n.º441/91 de 14 de Novembro, alterado + pelo Decreto-Lei n.º133/99 de 21 de Abril – + Estabelece o regime jurídico do enquadramento da + segurança, higiene e saúde do trabalho + + + Decreto-Lei n.º26/94, de 1 de Fevereiro, alterado + pela Lei n.º7/95 de 29 de Março e pelo + Decreto-Lei n.º109/2000 – Regime de + Organização e funcionamento dos serviços + da segurança, higiene e saúde do trabalho + + + + + + Área Administrativa + + Areas comerciais + + + Areas comerciais + + + Areas comerciais + + + Areas comerciais + + + Areas comerciais + + + Areas comerciais + + + Areas comerciais + + + + Risco de exposição a condições + inadequadas de iluminação + + 6 + + + + Melhorar as condições de iluminação para valores + mínimos de 500 na área focal de trabalho e 300 + lux no seu envolvimento + + + Areas comerciais + + + + Cartazista + + + Frederico Palma + lampadas + + 2008 + 5 + Maio + 1 + + + 2009 + 5 + Maio + 1 + + OK + OK + OK + + + + Área Comercial + + + 1 + 2 + \ No newline at end of file