Añado los fuentes de java

This commit is contained in:
2025-06-09 13:37:06 +02:00
parent d6c990e5d5
commit a97a6350ee
226 changed files with 57246 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
package com.tarisan.util;
public class Base64 {
private static final String base64code = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz" + "0123456789" + "+/";
private static final int splitLinesAt = 76;
public static byte[] zeroPad(int length, byte[] bytes) {
byte[] padded = new byte[length];
System.arraycopy(bytes, 0, padded, 0, bytes.length);
return padded;
}
public static String encode(String string) {
String encoded = "";
byte[] stringArray;
try {
stringArray = string.getBytes("UTF-8");
} catch (Exception ignored) {
stringArray = string.getBytes();
}
int paddingCount = (3 - (stringArray.length % 3)) % 3;
stringArray = zeroPad(stringArray.length + paddingCount, stringArray);
for (int i = 0; i < stringArray.length; i += 3) {
int j = ((stringArray[i] & 0xff) << 16) +
((stringArray[i + 1] & 0xff) << 8) +
(stringArray[i + 2] & 0xff);
encoded = encoded + base64code.charAt((j >> 18) & 0x3f) +
base64code.charAt((j >> 12) & 0x3f) +
base64code.charAt((j >> 6) & 0x3f) +
base64code.charAt(j & 0x3f);
}
return splitLines(encoded.substring(0, encoded.length() -
paddingCount) + "==".substring(0, paddingCount));
}
public static String splitLines(String string) {
String lines = "";
for (int i = 0; i < string.length(); i += splitLinesAt) {
lines += string.substring(i, Math.min(string.length(), i + splitLinesAt));
lines += "\r\n";
}
return lines;
}
}
+102
View File
@@ -0,0 +1,102 @@
/* Clase que encripta y desencripta un string utilizando una semilla */
package com.tarisan.util;
import java.security.*;
import java.util.Base64;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import javax.crypto.*;
import javax.crypto.spec.*;
//import sun.misc.CEStreamExhausted;
//import sun.misc.CharacterEncoder;
//import sun.misc.HexDumpEncoder;
import java.io.*;
public class DES {
Cipher ecipher;
Cipher dcipher;
// 8-byte Salt
byte[] salt = {
(byte)0xA9, (byte)0x9B, (byte)0xC8, (byte)0x32,
(byte)0x56, (byte)0x35, (byte)0xE3, (byte)0x03
};
// Iteration count
int iterationCount = 19;
public DES(String passPhrase) {
try {
// Create the key
KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount);
SecretKey key = SecretKeyFactory.getInstance(
"PBEWithMD5AndDES").generateSecret(keySpec);
ecipher = Cipher.getInstance(key.getAlgorithm());
dcipher = Cipher.getInstance(key.getAlgorithm());
// Prepare the parameter to the ciphers
AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
// Create the ciphers
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
} catch (java.security.InvalidAlgorithmParameterException e) {
} catch (java.security.spec.InvalidKeySpecException e) {
} catch (javax.crypto.NoSuchPaddingException e) {
} catch (java.security.NoSuchAlgorithmException e) {
} catch (java.security.InvalidKeyException e) {
}
}
public String encrypt(String str) {
try {
// Encode the string into bytes using utf-8
byte[] utf8 = str.getBytes("UTF8");
// Encrypt
byte[] enc = ecipher.doFinal(utf8);
// Encode bytes to base64 to get a string
//return new sun.misc.BASE64Encoder().encode(enc);
// Encode bytes to base64 using java8 basic base64:
String encodedString = Base64.getEncoder().encodeToString(enc);
return encodedString;
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
}
return null;
}
public String decrypt(String str) {
try {
// Decode base64 to get bytes
//byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
// Decode base64 to get bytes using java8 basic base64:
byte[] dec = Base64.getDecoder().decode(str);
// Decrypt
byte[] utf8 = dcipher.doFinal(dec);
// Decode using utf-8
return new String(utf8, "UTF8");
} catch (javax.crypto.BadPaddingException e) {
} catch (IllegalBlockSizeException e) {
} catch (UnsupportedEncodingException e) {
} catch (java.io.IOException e) {
}
return null;
}
}
+142
View File
@@ -0,0 +1,142 @@
/**
*
*/
package com.tarisan.util;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.tarisan.log.LogTarisan;
import com.tarisan.log.NivelLog;
import com.tarisan.persistencia.OracleParametros;
import com.tarisan.servlets.*;
import com.tarisan.control.ParametrosConfiguracion;
/**
* @author csm_jjripaper
*
*/
public class Generar_pdfs {
/**
* @param Llamaremos a esta clase una vez al día, por ejemplo a las 6:00 am para que genere los pdf de las peticiones que se realizaron ayer
*
*/
public static void main(String[] args) {
// Hay que definir la consulta para que nos devuelva los request id de las peticiones
// que se hicieron ayer
String peticion_izasa = new String();
String peticion_his = new String();
String strSql = new String();
try
{
/* Con esta consulta obtengo todos los request_id de izasa y los num_peti de novahis para las peticiones
* del pagador IMQ que tienen resultados finalizados en izasa, en los últimos seis meses
*
* select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL
from mg.request, NHGP_PETICION_CAB pet
where to_date(mg.request.requestdate, 'dd/mm/yyyy') > to_date(sysdate-180, 'dd/mm/yyyy')
and MG.REQUEST.ISCOMPLETE = 'Y'
and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL)
and pet.NHGP_PETC_TACT = 2
and pet.nhgp_petc_pag = 120
order by MG.REQUEST.REQUESTDATE
*/
//strSql = "select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL from mg.request, NHGP_PETICION_CAB pet where to_date(mg.request.requestdate, 'dd/mm/yyyy') > to_date(sysdate-180, 'dd/mm/yyyy') and MG.REQUEST.ISCOMPLETE = 'Y' and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL) and pet.NHGP_PETC_TACT = 2 and pet.nhgp_petc_pag = 120 and nhgp_petc_ambito = 2 order by MG.REQUEST.REQUESTDATE";
strSql = "select mg.request.requestid, MG.REQUEST.ISCOMPLETE, MG.REQUEST.REQUESTDATE, MG.REQUEST.REQUESTLABEL from mg.request, novahis.NHGP_PETICION_CAB pet where mg.request.requestdate > sysdate-180 and MG.REQUEST.ISCOMPLETE = 'Y' and to_number(pet.NHGP_PETC_ID) = to_number(MG.REQUEST.REQUESTLABEL) and pet.NHGP_PETC_TACT = 2 and pet.nhgp_petc_pag = 120 and nhgp_petc_ambito = 2 order by MG.REQUEST.REQUESTDATE";
//strSql = "select requestid, requestlabel from mg.request where requestlabel = 00109755";
ParametrosConfiguracion.cargarPropiedades();
//Connection conexion_izasa = Parametros
//Class.forName(OracleParametros.driverJdbc);
String url = "";
StringBuffer cadenaConexion = new StringBuffer();
cadenaConexion.append("jdbc:oracle:thin:");
cadenaConexion.append(ParametrosConfiguracion.dbhis_usuario);
cadenaConexion.append("/");
cadenaConexion.append(ParametrosConfiguracion.dbhis_password);
cadenaConexion.append("@");
cadenaConexion.append(ParametrosConfiguracion.dbhis_maquina);
cadenaConexion.append(":");
cadenaConexion.append(ParametrosConfiguracion.dbhis_puerto);
cadenaConexion.append(":");
cadenaConexion.append(ParametrosConfiguracion.dbhis_instancia);
LogTarisan.logger.log(NivelLog.INFO,cadenaConexion.toString());
url = cadenaConexion.toString();
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conexion_izasa = DriverManager.getConnection(url);
//conexion_izasa = DriverManager.getConnection("jdbc:oracle:thin:novahis/novahis@192.168.2.205:1521:csmreal");
Statement st = conexion_izasa.prepareStatement(strSql);
System.out.println("Se ha abierto la conexión bbdd->"+st.toString());
ResultSet rs = st.executeQuery(strSql);
System.out.println("Se ha ejecutado la consulta" + strSql);
while(rs.next())
{
System.out.println("La consulta ha devuelto resultados.");
peticion_izasa = rs.getString("requestid");
peticion_his = rs.getString("requestlabel");
System.out.println("requestid izasa = " + rs.getString("requestid"));
System.out.println("peticion_izasa.length() = " + peticion_izasa.length());
if(peticion_izasa.length()>0)
{
//para cada request_id
//String ruta = LogTarisan.getPathFichero();
System.out.println("La ruta es: " + WorkingDirectory.get());
String sisop = System.getProperty("os.name");
String slash = "\\";
if(sisop.contains("indows"))
{
slash = "\\";
}
else{
slash = "/";
}
//String ruta = "C:" + slash + "temp"+ slash +"resultados";
String ruta = WorkingDirectory.get().getAbsolutePath();
System.out.println("Vamos a generar el pdf en :" + ruta);
File pdf = new File(ruta + slash + ".." + slash + "resultados" + slash + peticion_his +".pdf");
System.out.println("Creamos el fichero pdf");
if(!pdf.exists())
{
System.out.println("Como no existe vamos a parsear el xml al pdf");
resultados_analisis.conexionPOST("https://192.168.2.102/modulab/servlet/GetXMLRequestServlet?username=admin&password=service&requestID=" + peticion_izasa, "HTTPS", ruta);
System.out.println("Obtenido XML");
System.out.println("el xml es: " + peticion_izasa + ".xml");
File xml = new File(ruta + slash + ".." + slash + "resultados" + slash + peticion_izasa +".xml");
if(xml.exists())
{
System.out.println("El xml se ha guardado en: " + ruta + slash + peticion_izasa +".xml");
}
else
{
System.out.println("No ha podido guardar el xml en: " + ruta + slash + peticion_izasa +".xml");
}
XML2PDF.transformar(peticion_izasa + ".xml", "resultados_izasa.xsl", peticion_his + ".pdf", ruta);
System.out.println("Transformado a pdf");
}
}
}
System.out.println("Final de la conexión...");
rs.close();
conexion_izasa.close();
}
catch(Exception e)
{
System.out.println("Error al obtener el requestid de izasa: "+strSql);
e.printStackTrace();
}
}
}
+928
View File
@@ -0,0 +1,928 @@
/*
* Created on 17-nov-2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.tarisan.util;
import java.awt.Color;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Vector;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.tarisan.log.LogTarisan;
import com.tarisan.log.NivelLog;
import com.tarisan.control.ParametrosConfiguracion;
import com.tarisan.data.Paciente;
import com.tarisan.data.Tarjeta;
import com.tarisan.data.Usuario;
import com.tarisan.data.VTamovextTaclient;
import com.tarisan.persistencia.PersistenciaParametros;
/**
* @author Roumen
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Print {
//The 14 standard fonts in PDF
private static Font fonts0 = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.NORMAL);
private static Font fonts1 = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.ITALIC);
private static Font fonts2 = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.BOLD);
private static Font fonts3 = FontFactory.getFont(FontFactory.COURIER, Font.DEFAULTSIZE, Font.BOLD | Font.ITALIC);
private static Font fonts4 = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.NORMAL);
private static Font fonts5 = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.ITALIC);
private static Font fonts6 = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD);
private static Font fonts7 = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLDITALIC);
private static Font fonts8 = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.NORMAL);
private static Font fonts9 = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.ITALIC);
private static Font fonts10 = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLD);
private static Font fonts11 = FontFactory.getFont(FontFactory.TIMES_ROMAN, Font.DEFAULTSIZE, Font.BOLDITALIC);
private static Font fonts12 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLD);
private static Font fonts13 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL);
private static Font fonts14 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD);
private static Font fonts15 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD);
private static Font fonts16 = FontFactory.getFont(FontFactory.SYMBOL, Font.DEFAULTSIZE, Font.NORMAL);
private static Font fonts17 = FontFactory.getFont(FontFactory.ZAPFDINGBATS, Font.DEFAULTSIZE, Font.NORMAL);
public Document pruebaPDF(int medico) throws DocumentException, IOException{
//Creamos el documento
Document document = new Document();
//Fijamos Márgenes
document.setMargins(40, 40, 5, 5);
String strTexto = "";
// we create a writer that listens to the document
String strFile = "";
strFile = ParametrosConfiguracion.ruta_pdf_peticiones_recetas + medico + ".pdf";
FileOutputStream foStream = new FileOutputStream(strFile);
PdfWriter writer = PdfWriter.getInstance(document,foStream);
document.open();
PdfPTable table = new PdfPTable(2); //Numero de columnas
//Fijar anchura de la tabla
table.setWidthPercentage(100);
//Creamos el objeto generador de PDF
Print print = new Print();
strTexto = "Impresión Recetas";
PdfPCell cell = null;
cell = new PdfPCell(new Paragraph(strTexto, fonts15));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
//AÑADIR TABLA
table.setHorizontalAlignment(Element.ALIGN_CENTER);
document.add(table);
// draw helper lines
PdfContentByte cb = writer.getDirectContent();
cb.stroke();
// draw text
String text = "Probando texto";
BaseFont bf = BaseFont.createFont();
cb.beginText();
cb.setFontAndSize(bf, 12);
cb.setTextMatrix(50, 800);
cb.showText(text);
cb.endText();
//CERRAR DOCUMENTO
// step 5: we close the document
document.close();
return document;
}
public PdfPTable anadirCabecera(PdfPTable table, String strTexto) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirCabecera().INI");
try {
//Inserción de la imagen de cabecera
//Image jpgImage = Image.getInstance("../webapps/tarisan/img/logo_03_40p.jpg");
//Image jpgImage = Image.getInstance("webapps/tarisan/img/logo_imq_.jpg");
PdfPCell cell = null;
/* if (jpgImage != null) {
cell = new PdfPCell(jpgImage);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
} else { */
cell = new PdfPCell(new Paragraph(" "));// Parrafo en blanco
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(" "));// Parrafo en blanco
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
LogTarisan.logger.log(NivelLog.INFO, "Imagen nula");
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
// }
cell = new PdfPCell(new Paragraph(strTexto, fonts15));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
//LogTarisan.logger.log(NivelLog.INFO, "No se inserta imagen");
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirCabecera().FIN");
return table;
}
public Document anadirLogotipo(Document document,int intMedico, int x, int y) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirLogotipo().INI");
try {
File imagenJPG = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".jpg");
File imagenPNG = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".png");
File imagenGIF = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".gif");
File imagenBMP = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".bmp");
if(imagenJPG.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".jpg");
imagen.setAbsolutePosition(x, y);
document.add(imagen);
}else if(imagenPNG.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".png");
imagen.setAbsolutePosition(x, y);
document.add(imagen);
}
else if(imagenGIF.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".gif");
imagen.setAbsolutePosition(x, y);
document.add(imagen);
}
else if(imagenBMP.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".bmp");
imagen.setAbsolutePosition(x, y);
document.add(imagen);
}else{
}
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirLogotipo().FIN");
return document;
}
/*public Document anadirLogotipo(Document document,int intMedico) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirLogotipo().INI");
try {
File imagenJPG = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".jpg");
File imagenPNG = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".png");
File imagenGIF = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".gif");
File imagenBMP = new File(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".bmp");
if(imagenJPG.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".jpg");
imagen.setAbsolutePosition(45f, 780f);
document.add(imagen);
}else if(imagenPNG.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".png");
imagen.setAbsolutePosition(45f, 780f);
document.add(imagen);
}
else if(imagenGIF.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".gif");
imagen.setAbsolutePosition(45f, 780f);
document.add(imagen);
}
else if(imagenBMP.exists())
{
Image imagen = Image.getInstance(ParametrosConfiguracion.ruta_logotipos+"/"+intMedico+".bmp");
imagen.setAbsolutePosition(45f, 780f);
document.add(imagen);
}else{
}
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirLogotipo().FIN");
return document;
}*/
public PdfPTable anadirCabeceraDetalle(PdfPTable table, String strTexto, String strFecha) throws Exception
{
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirCabeceraDetalle().INI");
try {
PdfPCell cell = new PdfPCell(new Paragraph(strTexto, fonts15));
//cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(3);
table.addCell(cell);
/*
//Inserción de la imagen de cabecera
Image jpgImage = Image.getInstance("../webapps/tarisan/img/logo_03_40p.jpg");
if (jpgImage != null) {
cell = new PdfPCell(jpgImage);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
} else {
LogTarisan.logger.log(NivelLog.INFO, "Imagen nula");
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
}
*/
LogTarisan.logger.log(NivelLog.INFO, "No se inserta imagen");
/*
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
*/
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("--- RELACIÓN ACTOS MÉDICOS REALIZADOS ---",fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("FECHA: " + strFecha,fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(3);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("NOMBRE PACIENTE",fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("ACTO REALIZADO",fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("IMPORTE",fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(3);
table.addCell(cell);
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirCabeceraDetalle().FIN");
return table;
}
public PdfPTable anadirDetallePaciente(PdfPTable table, Vector vSeleccion) throws Exception
{
PdfPCell cell = null;
VTamovextTaclient vTamovextTaclient = null;
double dblImporteTotal = 0;
for(int i = 0; i < vSeleccion.size(); i++)
{
vTamovextTaclient = (VTamovextTaclient)vSeleccion.elementAt(i);
dblImporteTotal += vTamovextTaclient.getPrecioActoMedico();
cell = new PdfPCell(new Paragraph(vTamovextTaclient.getNombre() + " " + vTamovextTaclient.getApellidos(),fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(vTamovextTaclient.getDescripcionActoMedico(),fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(Utilidades.formatearDouble(vTamovextTaclient.getPrecioActoMedico(),PersistenciaParametros.decimales),fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
}
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(3);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("IMPORTE...",fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(Utilidades.formatearDouble(dblImporteTotal,PersistenciaParametros.decimales),fonts13));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
table.addCell(cell);
return table;
}
public PdfPTable anadirInforme(PdfPTable table, String strInformeCabecera, String strInforme) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirCabecera().INI");
try {
PdfPCell cell = new PdfPCell(new Paragraph(strInformeCabecera, fonts14));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
if (strInforme != null && strInforme.length() > 0) {
cell = new PdfPCell(new Paragraph(strInforme, fonts13));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirInforme().FIN");
return table;
}
public PdfPTable anadirMedicoPrescriptor (PdfPTable table, String strMedico,
String strDireccion, String strEspecialidad, String strPoblacion,
String strNumColegiado, String strTelefono)
{
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirMedicoPrescriptor().INI");
try {
PdfPCell cell = new PdfPCell();
cell = new PdfPCell(new Paragraph(" "));// Parrafo en blanco
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(" "));// Parrafo en blanco
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Medico: ", fonts14));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
if (strMedico != null && strMedico.length() > 0) {
cell = new PdfPCell(new Paragraph(strMedico, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
if (strDireccion != null && strDireccion.length() > 0) {
cell = new PdfPCell(new Paragraph(strDireccion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
if (strEspecialidad != null && strEspecialidad.length() > 0) {
cell = new PdfPCell(new Paragraph(strEspecialidad, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
if (strPoblacion != null && strPoblacion.length() > 0) {
cell = new PdfPCell(new Paragraph(strPoblacion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
if (strNumColegiado != null && strNumColegiado.length() > 0) {
cell = new PdfPCell(new Paragraph(strNumColegiado, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
if (strTelefono != null && strTelefono.length() > 0) {
cell = new PdfPCell(new Paragraph(strTelefono, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
}
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirMedicoPrescriptor().FIN");
return table;
}
public PdfPTable anadirAnalisis(PdfPTable table, ArrayList arrayListaElementosPrescripcion, String strTexto) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirAnalisis().INI");
try {
PdfPCell cell = new PdfPCell();
cell = new PdfPCell(new Paragraph(strTexto, fonts14));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
cell.setBackgroundColor(new BaseColor(210, 210, 210));
table.addCell(cell);
/*
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
*/
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
//Búcle Determinaciones
String determinacion = "";
int contador = 0;
for (int i=0;i<arrayListaElementosPrescripcion.size();i++) {
contador = i;
if (arrayListaElementosPrescripcion.get(i) != null) {
determinacion = (String)arrayListaElementosPrescripcion.get(i);
}
if (determinacion.length() > 0) {
cell = new PdfPCell(new Paragraph(determinacion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
//cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
}
int resto = contador % 2;
if ( resto == 0 ) {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
//cell.setColspan(2);
table.addCell(cell);
}
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
/*
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
*/
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} catch (Exception ex) {
LogTarisan.logger.log(NivelLog.INFO, ex);
}
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirAnalisis().FIN");
return table;
}
public PdfPTable anadirPaciente(PdfPTable table, String strNomPaciente,
String strPoliza, String strAutorizacion, String strPoblacion) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirPaciente().INI");
PdfPCell cell = new PdfPCell();
cell = new PdfPCell(new Paragraph("Paciente: ", fonts14));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
if (strNomPaciente != null && strNomPaciente.length() > 0) {
cell = new PdfPCell(new Paragraph(strNomPaciente, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strPoliza != null && strPoliza.length() > 0) {
cell = new PdfPCell(new Paragraph(strPoliza, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strAutorizacion != null && strAutorizacion.length() > 0) {
cell = new PdfPCell(new Paragraph(strAutorizacion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strPoblacion != null && strPoblacion.length() > 0) {
cell = new PdfPCell(new Paragraph(strPoblacion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirPaciente().FIN");
return table;
}
public PdfPTable anadirPacienteFact(PdfPTable table, String strNomPaciente,
String strPoliza, String strPoblacion, String strfecnac, String nif) {
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirPaciente().INI");
PdfPCell cell = new PdfPCell();
cell = new PdfPCell(new Paragraph("Paciente: ", fonts14));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(2);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
if (strNomPaciente != null && strNomPaciente.length() > 0) {
cell = new PdfPCell(new Paragraph(strNomPaciente, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strPoliza != null && strPoliza.length() > 0) {
cell = new PdfPCell(new Paragraph(strPoliza, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strPoblacion != null && strPoblacion.length() > 0) {
cell = new PdfPCell(new Paragraph(strPoblacion, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (strfecnac != null && strfecnac.length() > 0) {
cell = new PdfPCell(new Paragraph("Fecha Nacimiento: "+strfecnac, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
if (nif != null && nif.length() > 0) {
cell = new PdfPCell(new Paragraph("Nif: "+nif, fonts13));
cell.setHorizontalAlignment(Element.ALIGN_LEFT);
cell.setBorderColor(new BaseColor(255, 255, 255));
table.addCell(cell);
} else {
cell = new PdfPCell(new Paragraph(" "));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setColspan(2);
table.addCell(cell);
}
cell = new PdfPCell(new Paragraph(""));
cell.setBorderColor(new BaseColor(255, 255, 255));
cell.setBackgroundColor(new BaseColor(210, 210, 210));
cell.setColspan(2);
table.addCell(cell);
LogTarisan.logger.log(NivelLog.INFO, "Print.anadirPaciente().FIN");
return table;
}
}
+120
View File
@@ -0,0 +1,120 @@
/*
* Created on 22-nov-2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.tarisan.util;
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
/**
* @author Roumen
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Prueba {
public void print() {
System.out.println("Dentro de print");
String strPdfName = "CSM.pdf";
String path = "C:\\Tomcat\\webapps\\tarisan\\peticiones";
strPdfName = path + "/" + strPdfName;
String osName = System.getProperty("os.name" );
try {
//FOR WINDOWS 95 AND 98 USE COMMAND.COM
if(osName.equals("Windows 95") || osName.equals("Windows 98")){
System.out.println("Dentro del IF");
Runtime.getRuntime().exec("command.com /C start acrord32 /p " + strPdfName);
}
//FOR WINDOWS NT/XP/2000 USE CMD.EXE
else {
System.out.println("Dentro de else");
Runtime.getRuntime().exec("cmd.exe start /C acrord32 /p " + strPdfName);
//String cadena = "c:\\windows\\system32\\cmd";
/*
Runtime rt = Runtime.getRuntime();
String cadena = "cmd";
System.out.println("cadena2: " + cadena);
Process proc = rt.exec(cadena);
int exitVal = proc.waitFor();
*/
}
} catch (Exception ex) {
System.out.println(ex);
}
}
public void print1() {
/* Use the pre-defined flavor for a GIF from an InputStream */
//DocFlavor flavor = new DocFlavor("text/plain","java.io.InputStream");
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
System.out.println("1");
/* Create a set which specifies how the job is to be printed */
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
aset.add(new Copies(1));
System.out.println("2");
/* Locate print services which can print a GIF in the manner specified */
//PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);
PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("3");
if (pservice != null) {
/* Create a Print Job */
System.out.println("Found a suitable printers: " + pservice);
DocPrintJob printJob = pservice.createPrintJob();
/* Create a Doc implementation to pass the print data */
//FileInputStream textSt;
//File printFile = new File("C:/Tomcat/webapps/tarisan/peticiones/CSM.PDF");
File printFile = new File("C:/tarisan/indices.txt");
FileInputStream textSt;
try {
textSt = new FileInputStream(printFile);
byte[] bytesLeidos = new byte[10];
textSt.read(bytesLeidos);
for (int i=0;i<bytesLeidos.length;i++)
System.out.println(bytesLeidos[i]);
Doc doc = new SimpleDoc(textSt, flavor, null);
//Doc doc = new SimpleDoc
try {
printJob.print(doc, aset);
} catch (PrintException e) {
System.out.println(e);
System.out.println(e.getMessage());
System.out.println("");
System.out.println("--------------------------------");
e.printStackTrace();
}
} catch (FileNotFoundException ex) {
System.out.print("file not found outor");
} catch (Exception ex) {
System.out.println(ex);
}
/* Print the doc as specified */
} else {
System.out.println("No suitable printers");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,46 @@
package com.tarisan.util;
import java.io.File;
import java.net.URL;
public class WorkingDirectory {
private static File WORKING_DIRECTORY;
public static File get() {
String Recurso = WorkingDirectory.class.getSimpleName() + ".class";
if (WORKING_DIRECTORY == null) {
try {
URL url = WorkingDirectory.class.getResource(Recurso);
System.out.println(url);
if (url.getProtocol().equals("file")) {
File f = new File(url.toURI());
do {
f = f.getParentFile();
} while (!f.isDirectory());
WORKING_DIRECTORY = f;
} else if (url.getProtocol().equals("jar")) {
String expected = "!/" + Recurso;
String s = url.toString();
s = s.substring(4);
s = s.substring(0, s.length() - expected.length());
File f = new File(new URL(s).toURI());
do {
f = f.getParentFile();
} while (!f.isDirectory());
WORKING_DIRECTORY = f;
}
} catch (Exception e) {
WORKING_DIRECTORY = new File(".");
}
}
return WORKING_DIRECTORY;
}
}
+245
View File
@@ -0,0 +1,245 @@
package com.tarisan.util;
import java.io.File;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
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.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import com.tarisan.log.LogTarisan;
import com.tarisan.log.NivelLog;
public class XML2PDF {
public static void transformar(String ruta_xml, String ruta_xsl, String ruta_pdf) {
try {
/*El xml lo dejaremos en una ruta temporal para borrarlo al terminar
* El xsl está dentro de la carpeta css
* El jpg está dentro de la carpeta img
* El pdf lo dejaremos en la carpeta resultados
*/
LogTarisan.logger.log(NivelLog.INFO, "FOP XML2PDF");
//System.out.println("Preparando...");
LogTarisan.logger.log(NivelLog.INFO, "Preparando...");
//ServletContext sc = null;
//System.out.println("La ruta al xls es: " + sc.getRealPath("/"));
String ruta = WorkingDirectory.get().getAbsolutePath();
String sisop = System.getProperty("os.name");
String slash = "\\";
if(sisop.contains("indows"))
{
slash = "\\";
}
else{
slash = "/";
}
File baseDir = new File(ruta + slash);
File xslDir = new File(ruta + slash + ".." + slash + "css" + slash);
//File outDir = baseDir;
//outDir.mkdirs();
File xmlfile = new File(baseDir + ".." + slash + "resultados" + slash, ruta_xml);
File xsltfile = new File(xslDir, ruta_xsl);
File pdffile = new File(baseDir + ".." + slash + "resultados" + slash, ruta_pdf);
//System.out.println("XML de entrada: XML (" + xmlfile + ")");
LogTarisan.logger.log(NivelLog.INFO, "XML de entrada: XML (" + xmlfile + ")");
//System.out.println("Hoja de estilos xslt: " + xsltfile);
LogTarisan.logger.log(NivelLog.INFO, "Hoja de estilos xslt: " + xsltfile);
//System.out.println("PDF salida: (" + pdffile + ")");
LogTarisan.logger.log(NivelLog.INFO, "PDF salida: (" + pdffile + ")");
//System.out.println("Ejecutando...");
LogTarisan.logger.log(NivelLog.INFO, "Ejecutando...");
FopFactory fopFactory = FopFactory.newInstance();
//LogTarisan.logger.log(NivelLog.INFO, "Creamos la instancia FopFactory");
//FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
//LogTarisan.logger.log(NivelLog.INFO, "Creamos FOUserAgent");
OutputStream out = new java.io.FileOutputStream(pdffile);
//LogTarisan.logger.log(NivelLog.INFO, "Creando outputstream");
out = new java.io.BufferedOutputStream(out);
try {
Fop fop = fopFactory.newFop("text");
// .newFop("application/pdf", foUserAgent, out);
//LogTarisan.logger.log(NivelLog.INFO, "Creando Fop");
LogTarisan.setNivel("INFO");
TransformerFactory factory = TransformerFactory.newInstance();
//LogTarisan.logger.log(NivelLog.INFO, "Creando TransformerFactory");
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
//LogTarisan.logger.log(NivelLog.INFO, "Le pasamos el xsl al transformer");
transformer.setParameter("versionParam", "1.0");
Date fecha = new Date();
SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
String cadenaFecha = formato.format(fecha);
transformer.setParameter("fecha", cadenaFecha);
//LogTarisan.logger.log(NivelLog.INFO, "Establecemos un parametro para el xsl");
Source src = new StreamSource(xmlfile);
//LogTarisan.logger.log(NivelLog.INFO, "Establecemos un nuevo origen con el xml");
Result res = new SAXResult(fop.getDefaultHandler());
//LogTarisan.logger.log(NivelLog.INFO, "Creamos el Result");
transformer.transform(src, res);
//LogTarisan.logger.log(NivelLog.INFO, "Ejecutamos el transformer.transform");
} finally {
out.close();
}
LogTarisan.logger.log(NivelLog.INFO, "Conversion realizada con éxito");
//System.out.println("Bien!");
LogTarisan.setNivel("ALL");
if(xmlfile.delete())
{
LogTarisan.logger.log(NivelLog.INFO,"Fichero xml eliminado correctamente");
}
else
{
LogTarisan.logger.log(NivelLog.WARN, "No se ha podido borrar el xml de la carpeta resultados.");
}
} catch (Exception e) {
LogTarisan.logger.log(NivelLog.ERROR, "Error al convertir xml a pdf: " + e.toString());
}
}
public static void transformar(String ruta_xml, String ruta_xsl, String ruta_pdf, String ruta) {
try {
/*El xml lo dejaremos en una ruta temporal para borrarlo al terminar
* El xsl está dentro de la carpeta css
* El jpg está dentro de la carpeta img
* El pdf lo dejaremos en la carpeta resultados
*/
System.out.println("Preparando...");
//ServletContext sc = null;
//System.out.println("La ruta al xls es: " + sc.getRealPath("/"));
String sisop = System.getProperty("os.name");
String slash = "\\";
if(sisop.contains("indows"))
{
slash = "\\";
}
else{
slash = "/";
}
File xslDir = new File(ruta + slash + ".." + slash + "css" + slash);
File resDir = new File(ruta + slash + ".." + slash + "resultados" + slash);
//File outDir = baseDir;
//outDir.mkdirs();
File xmlfile = new File(resDir, ruta_xml);
File xsltfile = new File(xslDir, ruta_xsl);
File pdffile = new File(resDir, ruta_pdf);
System.out.println("XML de entrada: XML (" + xmlfile + ")");
//LogTarisan.logger.log(NivelLog.INFO, "XML de entrada: XML (" + xmlfile + ")");
System.out.println("Hoja de estilos xslt: " + xsltfile);
//LogTarisan.logger.log(NivelLog.INFO, "Hoja de estilos xslt: " + xsltfile);
System.out.println("PDF salida: (" + pdffile + ")");
//LogTarisan.logger.log(NivelLog.INFO, "PDF salida: (" + pdffile + ")");
System.out.println("Ejecutando...");
//LogTarisan.logger.log(NivelLog.INFO, "Ejecutando...");
FopFactory fopFactory = FopFactory.newInstance();
////LogTarisan.logger.log(NivelLog.INFO, "Creamos la instancia FopFactory");
//FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
//LogTarisan.logger.log(NivelLog.INFO, "Creamos FOUserAgent");
OutputStream out = new java.io.FileOutputStream(pdffile);
//LogTarisan.logger.log(NivelLog.INFO, "Creando outputstream");
out = new java.io.BufferedOutputStream(out);
try {
Fop fop = fopFactory.newFop("text");
//LogTarisan.logger.log(NivelLog.INFO, "Creando Fop");
//LogTarisan.setNivel("INFO");
TransformerFactory factory = TransformerFactory.newInstance();
//LogTarisan.logger.log(NivelLog.INFO, "Creando TransformerFactory");
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
//LogTarisan.logger.log(NivelLog.INFO, "Le pasamos el xsl al transformer");
transformer.setParameter("versionParam", "1.0");
Date fecha = new Date();
SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
String cadenaFecha = formato.format(fecha);
transformer.setParameter("fecha", cadenaFecha);
//LogTarisan.logger.log(NivelLog.INFO, "Establecemos un parametro para el xsl");
Source src = new StreamSource(xmlfile);
//LogTarisan.logger.log(NivelLog.INFO, "Establecemos un nuevo origen con el xml");
Result res = new SAXResult(fop.getDefaultHandler());
//LogTarisan.logger.log(NivelLog.INFO, "Creamos el Result");
transformer.transform(src, res);
//LogTarisan.logger.log(NivelLog.INFO, "Ejecutamos el transformer.transform");
} finally {
out.close();
}
//LogTarisan.logger.log(NivelLog.INFO, "Conversion realizada con éxito");
System.out.println("Bien!");
//LogTarisan.setNivel("ALL");
if(xmlfile.delete())
{
//LogTarisan.logger.log(NivelLog.INFO,"Fichero xml eliminado correctamente");
System.out.println("Fichero xml eliminado correctamente");
}
else
{
//LogTarisan.logger.log(NivelLog.WARN, "No se ha podido borrar el xml de la carpeta resultados.");
System.out.println("No se ha podido borrar el xml de la carpeta resultados.");
}
} catch (Exception e) {
e.printStackTrace();
//LogTarisan.logger.log(NivelLog.ERROR, "Error al convertir xml a pdf: " + e.toString());
}
}
}
@@ -0,0 +1,24 @@
package com.tarisan.util;
import java.io.ByteArrayInputStream;
public class conversiones {
public static String toHexadecimal(String sData){
byte [] datos = sData.getBytes();
String resultado="";
ByteArrayInputStream input = new ByteArrayInputStream(datos);
String cadAux;
int leido = input.read();
while(leido != -1){
cadAux = Integer.toHexString(leido);
if(cadAux.length()<2){
resultado += "0";
}
resultado += cadAux;
leido = input.read();
}
return resultado.toUpperCase();
}
}