git-svn-id: https://svn.coded.pt/svn/SIPRP@998 bb69d46d-e84e-40c8-a05a-06db0d633741

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
João Neto 17 years ago
parent 9e95aae1cc
commit 857c1f6a39

@ -0,0 +1,190 @@
/*
* PDFCreator.java
*
* Created on 19 de Abril de 2006, 18:20
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package siprp.fop;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.swing.JFileChooser;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Options;
import org.apache.fop.viewer.SecureResourceBundle;
import org.apache.fop.viewer.Translator;
import com.evolute.utils.fop.FOPCreator;
/**
* PDFCreator creates PDF's using FO.
*
* @author Frederico Palma
* @version %I%, %G%
*/
public class PDFCreator
{
private final Translator translator = new SecureResourceBundle( null );
private static final Object LOCK = new Object();
private static PDFCreator pdfCreator;
private static String userConfig;
public static PDFCreator getPDFCreator()
{
synchronized( LOCK )
{
if( pdfCreator == null )
{
pdfCreator = new PDFCreator();
}
}
return pdfCreator;
}
public static void setUserConfig(String string)
{
PDFCreator.userConfig = string;
}
public static void main( String arg[] )
throws Exception
{
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final FOPCreator creator = FOPCreator.getFOPCreator();
System.out.println( "Creating FO" );
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle( "Select XML data file:" );
int returnVal = chooser.showOpenDialog( null );
String dataFile = null;
if( returnVal == JFileChooser.APPROVE_OPTION )
{
dataFile = chooser.getSelectedFile().getAbsolutePath();
}
chooser.setDialogTitle( "Select XSL-FO template file:" );
returnVal = chooser.showOpenDialog( null );
String templateFile = null;
if( returnVal == JFileChooser.APPROVE_OPTION )
{
templateFile = chooser.getSelectedFile().getAbsolutePath();
System.out.println( chooser.getSelectedFile().getAbsolutePath() );
}
final String DATA = dataFile;
final String TEMPLATE = templateFile;
creator.createFOfromXML( new FileInputStream( DATA ),
new FileInputStream( TEMPLATE ), baos );
// Thread t = new Thread() {
// public void run()
// {
// try
// {
// creator.createFOfromXML( new FileInputStream( DATA ),
// new FileInputStream( TEMPLATE ), baos );
// System.out.println( "FO created" );
// }
// catch( Exception ex )
// {
// ex.printStackTrace();
// }
// } };
// t.start();
// Thread.currentThread().sleep( 2 );
System.out.println( "Starting to print" );
// options.put( FOP_DUPLEX_TYPE, javax.print.attribute.standard.Sides.TUMBLE );
byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( baos.toByteArray() );
// new FOPPrinter().printFO( new FileInputStream( "c:\\simplecol.fo" ), true, false );
File pdfFile = new File( "/home/fpalma/acss/teste.pdf" );
File foFile = new File( "/home/fpalma/Desktop/teste.fo" );
pdfFile.createNewFile();
foFile.createNewFile();
FileOutputStream fos = new FileOutputStream( pdfFile );
FileOutputStream fofos = new FileOutputStream( foFile );
fos.write( pdf );
fofos.write( baos.toByteArray() );
fos.close();
fofos.close();
System.out.println( "DONE" );
}
/** Creates a new instance of PDFCreator */
private PDFCreator()
{
}
/**
* Creates PDF content as an array of bytes, given FO content as an array of bytes.
*
* @param fo the byte[] with the FO content to convert
* @return the PDF content
* @throws Exception if the conversion fails
*
*/
public byte[]createPdfFromFo( byte []fo )
throws Exception
{
InputStream inputStreamConf = ClassLoader.getSystemClassLoader().getResourceAsStream("siprp/fop/fop.xml");
InputStream inputStreamDTD = ClassLoader.getSystemClassLoader().getResourceAsStream("siprp/fop/config.dtd");
/*************************/
File f = File.createTempFile("fop", "conf");
f.deleteOnExit();
writeFile(inputStreamConf, f);
System.out.println(f.getParentFile());
/*************************/
File dtd = new File(f.getParentFile(), "config.dtd");
writeFile(inputStreamDTD, dtd);
new Options(f);
ByteArrayOutputStream pdf = new ByteArrayOutputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource( new ByteArrayInputStream( fo ) );
Driver driver = new Driver();
driver.setLogger( new ConsoleLogger( ConsoleLogger.LEVEL_INFO ) );
driver.setRenderer( Driver.RENDER_PDF );
driver.setOutputStream( pdf );
Result res = new SAXResult( driver.getContentHandler() );
transformer.transform( src, res );
return pdf.toByteArray();
}
private void writeFile(InputStream inputStreamConf, File f)
throws FileNotFoundException, IOException {
OutputStream out = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while ((len = inputStreamConf.read(buf)) > 0)
out.write(buf, 0, len);
out.close();
inputStreamConf.close();
}
}

@ -0,0 +1,22 @@
<!ELEMENT configuration (entry*, fonts?)>
<!ELEMENT entry (key,(value | list))>
<!ATTLIST entry
role CDATA #IMPLIED
>
<!ELEMENT key (#PCDATA)>
<!ELEMENT value (#PCDATA)>
<!ELEMENT list (value+ | subentry+)>
<!ELEMENT subentry (key,value+)>
<!ELEMENT fonts (font*)>
<!ELEMENT font (font-triplet+)>
<!ATTLIST font
metrics-file CDATA #REQUIRED
kerning CDATA #IMPLIED
embed-file CDATA #REQUIRED
>
<!ELEMENT font-triplet EMPTY>
<!ATTLIST font-triplet
name CDATA #REQUIRED
style CDATA #REQUIRED
weight CDATA #REQUIRED
>

@ -0,0 +1,89 @@
<!DOCTYPE configuration SYSTEM "config.dtd">
<!--
this file contains templates which allow an user easy
configuration of Fop. Actually normally you don't need this configuration
file, but if you need to change configuration, you should
always use this file and *not* config.xml.
Usage: java org.apache.fop.apps.Fop -c userconfig.xml -fo fo-file -pdf pdf-file
-->
<configuration>
<!-- NOT IMPLEMENTED
basedir: normally the base directory is the directory where the fo file is
located. if you want to specify your own, uncomment this entry
-->
<!--
<entry>
<key>baseDir</key>
<value></value>
</entry>
-->
<!--
************************************************************************
HYPHENATION
************************************************************************
-->
<!--
hyphenation directory
if you want to specify your own directory with hyphenation pattern
then uncomment the next entry and add the directory name
-->
<!--
<entry>
<key>hyphenation-dir</key>
<value>/java/xml-fop/hyph</value>
</entry>
-->
<!--
************************************************************************
Add fonts here
************************************************************************
-->
<fonts>
<!-- example -->
<!--
<font metrics-file="arial.xml" kerning="yes" embed-file="arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<font-triplet name="ArialMT" style="normal" weight="normal"/>
</font>
<font metrics-file="arialb.xml" kerning="yes" embed-file="arialb.ttf">
<font-triplet name="Arial" style="normal" weight="bold"/>
<font-triplet name="ArialMT" style="normal" weight="bold"/>
</font>
<font metrics-file="ariali.xml" kerning="yes" embed-file="ariali.ttf">
<font-triplet name="Arial" style="italic" weight="normal"/>
<font-triplet name="ArialMT" style="italic" weight="normal"/>
</font>
<font metrics-file="arialbi.xml" kerning="yes" embed-file="arialbi.ttf">
<font-triplet name="Arial" style="italic" weight="bold"/>
<font-triplet name="ArialMT" style="italic" weight="bold"/>
</font>
-->
<!-- Example Japanese fonts
<font metrics-file="msgothic.xml" embed-file="D:\winnt\font\msgothic.ttc" kerning="yes">
<font-triplet name="Gothic" style="normal" weight="normal"/>
<font-triplet name="Gothic" style="normal" weight="bold"/>
<font-triplet name="Gothic" style="italic" weight="normal"/>
<font-triplet name="Gothic" style="italic" weight="bold"/>
</font>
<font metrics-file="msmincho.xml" embed-file="Cyberbit.ttf" kerning="yes">
<font-triplet name="Mincho" style="normal" weight="normal"/>
<font-triplet name="Mincho" style="normal" weight="bold"/>
<font-triplet name="Mincho" style="italic" weight="normal"/>
<font-triplet name="Mincho" style="italic" weight="bold"/>
</font>
-->
</fonts>
</configuration>

@ -2,12 +2,17 @@ package siprp.higiene.relatorio.print;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.jdom.Document;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import com.evolute.utils.fop.PDFCreator;
import siprp.fop.PDFCreator;
import com.evolute.utils.xml.XSLTransformer;
public class RelatorioPDFCreator
@ -17,9 +22,12 @@ public class RelatorioPDFCreator
{
RelatorioToPrint relatorio = RelatorioPrintDataProvider.getProvider().getRelatorioToPrint( relatorioId );
Document foDoc = new Document( relatorio.toJdomElement() );
XMLOutputter outputter = new XMLOutputter();
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
ByteArrayOutputStream foBaos = new ByteArrayOutputStream();
// FileOutputStream fofos = new FileOutputStream("/home/jneto/Desktop/a.xml");
outputter.output( foDoc, foBaos );
// outputter.output( foDoc, fofos );
// System.out.println( new String( foBaos.toByteArray() ) );
byte fo[] =
applyTemplate(
@ -27,7 +35,11 @@ public class RelatorioPDFCreator
"siprp/higiene/relatorio/print/relatorio.xsl" ),
new ByteArrayInputStream( foBaos.toByteArray() ) );
// System.out.println( new String( fo ) );
byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( fo );
//FIXME: VERSAO PDFCREATOR HACKADA. FAZER UPGRADE PARA 0.20
PDFCreator pdfCreator = PDFCreator.getPDFCreator();
byte pdf[] = pdfCreator.createPdfFromFo( fo );
return pdf;
}

@ -1,5 +1,7 @@
package siprp.higiene.relatorio.print;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Vector;
@ -22,6 +24,8 @@ import com.evolute.utils.sql.Select2;
public class RelatorioPrintDataProvider
{
private static final Object LOCK = new Object();
protected static final Object CONTROLLED = "Controlado";
protected static final Object INDETERMINATE = "Indeterminado";
private static RelatorioPrintDataProvider instance = null;
protected final Executer EXECUTER;
@ -394,7 +398,7 @@ public class RelatorioPrintDataProvider
Select select =
new Select2(
new String[]{ "hs_relatorio_risco", "hs_relatorio_posto_risco", "hs_relatorio_risco_valor_qualitativo" },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER },
new Expression[]{
new Field( "hs_relatorio_risco.id" ).isEqual( new Field( "hs_relatorio_posto_risco.risco_id" ) ),
new Field( "hs_relatorio_posto_risco.valor_qualitativo_id" ).isEqual( new Field( "hs_relatorio_risco_valor_qualitativo.id" ) )
@ -405,8 +409,11 @@ public class RelatorioPrintDataProvider
"hs_relatorio_posto_risco.severidade",
"hs_relatorio_risco_valor_qualitativo.description" },
new Field( "hs_relatorio_posto_risco.posto_id" ).isEqual( postoId ).and(
new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ),
new String[]{ "hs_relatorio_risco.id" },
new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ).and(
new Field("hs_relatorio_posto_risco.probabilidade").isDifferent(null).or(
new Field("hs_relatorio_posto_risco.severidade").isDifferent(null).or(
new Field("hs_relatorio_posto_risco.valor_qualitativo_id").isDifferent(null)))) ),
new String[]{ "hs_relatorio_posto_risco.probabilidade*hs_relatorio_posto_risco.severidade DESC" },
null,
null,
null );
@ -429,6 +436,44 @@ public class RelatorioPrintDataProvider
getMedidasToPrintByRiscoId( id ) ) );
}
Collections.sort(riscos, new Comparator<RiscoToPrint>(){
@Override
public int compare(RiscoToPrint o1, RiscoToPrint o2) {
int comparevalue = 0;
if (o1.probabilidade != null && o1.severidade != null
&& o2.probabilidade != null && o2.severidade != null){
Integer o1Value = o1.probabilidade*o1.severidade;
Integer o2Value = o2.probabilidade*o2.severidade;
comparevalue = 0-o1Value.compareTo(o2Value);
} else if (o1.valorQualitativo != null
&& o1.valorQualitativo.length() > 0
&& o2.valorQualitativo != null
&& o2.valorQualitativo.length() > 0) {
if(o1.valorQualitativo.equals(CONTROLLED)){
comparevalue = -1;
}else if(o1.valorQualitativo.equals(INDETERMINATE)){
comparevalue = 1;
}else{
if(o2.valorQualitativo.equals(CONTROLLED)){
comparevalue = 1;
}else{
comparevalue = -1;
}
}
}else{
if(o1.valorQualitativo!=null){
comparevalue = 1;
}else{
comparevalue = -1;
}
}
return comparevalue;
}
});
return riscos;
}

@ -37,7 +37,7 @@ public class RiscoToPrint
Element probabilidadeElement = new Element( "probabilidade" );
probabilidadeElement.setText( probabilidade != null ? probabilidade.toString() : " " );
riscoElement.addContent( probabilidadeElement );
Element valorElement = new Element( "valor" );
Element valorElement = new Element( "valor-numerico" );
valorElement.setText( ( severidade != null && probabilidade != null ) ? "" + ( severidade * probabilidade ) : " " );
riscoElement.addContent( valorElement );
Element valorQualitativoElement = new Element( "valor-qualitativo" );

@ -3809,10 +3809,9 @@
<fo:table-row>
<fo:table-cell display-align="after">
<fo:block font-size="13pt"
text-align="left">
text-align="left" >
<fo:external-graphic
src="url('http://www.evolute.pt/~siprp/planoactuacao/siprp_logo.jpg')"
height="2cm" />
src="url('http://www.evolute.pt/~siprp/planoactuacao/siprp_logo.jpg')" height="2cm"/>
</fo:block>
</fo:table-cell>
<fo:table-cell display-align="after">
@ -3823,7 +3822,7 @@
<xsl:variable name="logotipo"
select="../../../empresa/logotipo" />
<fo:external-graphic
src="url('{$logotipo}')" height="2cm" />
src="url('{$logotipo}')" height="2cm"/>
</xsl:if>
</fo:block>
</fo:table-cell>
@ -4110,14 +4109,18 @@
writing-mode="lr-tb" padding="2pt">
<fo:block font-size="11pt"
font-weight="bold" margin-right="-0.0146in" text-indent="0in"
text-align="left" margin-left="0in">
text-align="left" margin-left="0.1in">
<fo:block>
<fo:leader/>
</fo:block>
<xsl:value-of
select="descricao" />
</fo:block>
<xsl:for-each select="medida">
<fo:block font-size="11pt"
margin-right="-0.0146in" text-indent="0in"
text-align="justify" margin-left="0.2in"
<fo:block font-size="12pt"
font-family="Arial"
margin-right="0.2in" text-indent="0in"
text-align="justify" margin-left="0.25in"
space-before="4pt">
-
<xsl:value-of
@ -4133,6 +4136,9 @@
</xsl:choose>
</fo:block>
</xsl:for-each>
<fo:block>
<fo:leader/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>

Loading…
Cancel
Save