From dd00674f8da4fc2afc82496bdbc7cc91bd3d6009 Mon Sep 17 00:00:00 2001 From: netconomy Date: Fri, 17 Aug 2007 06:18:39 +0000 Subject: deprecated code git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@168 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../knowcenter/wag/egov/egiz/test/AbsTexTest.java | 235 ++++++++++----------- .../wag/egov/egiz/test/ExtractTextTextual.java | 58 +++-- 2 files changed, 135 insertions(+), 158 deletions(-) (limited to 'src/main/java/at/knowcenter') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/test/AbsTexTest.java b/src/main/java/at/knowcenter/wag/egov/egiz/test/AbsTexTest.java index 22b20ee..7788a2a 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/test/AbsTexTest.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/test/AbsTexTest.java @@ -3,139 +3,122 @@ */ package at.knowcenter.wag.egov.egiz.test; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.util.List; - -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; - -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.cfg.ConfigLogger; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; -import at.knowcenter.wag.egov.egiz.pdf.AbsoluteTextSignature; -import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; -import at.knowcenter.wag.egov.egiz.pdf.TextualSignature; -import at.knowcenter.wag.egov.egiz.sig.SignatureResponse; /** * Test file for testing the absolute text signature. + * + * @deprectated outdated * @author wprinz */ public class AbsTexTest { - /** - * The logger definition. - */ - private static final Logger logger = ConfigLogger.getLogger(AbsTexTest.class); - - /** - * @param args - * @throws IOException - * @throws PresentableException - */ - public static void main(String[] args) throws IOException, PresentableException - { - SettingsReader.initializeForCommandLine(); - PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties"); - - File BASE_DIR = new File("C:\\wprinz\\Filer\\egiz\\docs\\abstexsig"); - File original_file = new File(BASE_DIR, "AbsTexSig.pdf"); - File signed_file = new File(BASE_DIR, "AbsTexSig.pdf_out.pdf"); - File signed_signed_file = new File(BASE_DIR, "AbsTexSig.pdf_out.pdf_out.pdf"); - - File in = new File("C:\\wprinz\\Filer\\egiz\\docs\\Abnahmetests\\tests\\commandline\\alte_sig\\document4.pdf_asimoaold.pdf_out.pdf"); - byte[] pdf = readInFile(in); - - ByteArrayInputStream bais = new ByteArrayInputStream(pdf, 0, pdf.length); - String raw_text = TextualSignature.extractTextTextual(bais); - - String text = PdfAS.extractNormalizedTextTextual(pdf, pdf.length); - - writeTextToFile(raw_text, new File(BASE_DIR, "raw_text.utf8.txt")); - writeTextToFile(text, new File(BASE_DIR, "text.utf8.txt")); - - if (true) - { - return; - } - - String[] texts = new String[3]; - - byte[] original = readInFile(original_file); - byte[] signed = readInFile(signed_file); - byte[] signed2 = readInFile(signed_signed_file); - - texts[0] = PdfAS.extractNormalizedTextTextual(original, original.length); - texts[1] = PdfAS.extractNormalizedTextTextual(signed, signed.length); - texts[2] = PdfAS.extractNormalizedTextTextual(signed2, signed2.length); - - writeTextToFile(texts[0], new File(BASE_DIR, "original.utf8.txt")); - writeTextToFile(texts[1], new File(BASE_DIR, "signed.utf8.txt")); - writeTextToFile(texts[2], new File(BASE_DIR, "signed_signed.utf8.txt")); - - // String text = texts[2]; - - List holders = AbsoluteTextSignature.extractSignatureHoldersFromText(text); - logger.debug("extracted " + holders.size() + " holders:"); - for (int i = 0; i < holders.size(); i++) - { - SignatureHolder holder = (SignatureHolder) holders.get(i); - - logger.debug(" #" + i + ": " + holder.getSignatureObject().getSignationDate() + ", " + holder.getSignatureObject().getSignatureTypeDefinition().getType()); - } - - SignatureHolder sh_latest = (SignatureHolder) holders.get(1); - - SignatureHolder sh_earlier = (SignatureHolder) holders.get(0); - - writeTextToFile(sh_latest.getSignedText(), new File(BASE_DIR, "reconstructed_latest.utf8.txt")); - writeTextToFile(sh_earlier.getSignedText(), new File(BASE_DIR, "reconstructed.utf8.txt")); - - verifyReconstruction(sh_latest.getSignedText(), texts[1]); - verifyReconstruction(sh_earlier.getSignedText(), texts[0]); - - SignatureResponse sr = PdfAS.verify(sh_latest, "moa"); - System.out.println(sr); - sr = PdfAS.verify(sh_earlier, "moa"); - System.out.println(sr); - - } - - public static byte[] readInFile(File file) throws IOException - { - FileInputStream fis = new FileInputStream(file); - byte[] ba = new byte[(int) file.length()]; - fis.read(ba); - fis.close(); - return ba; - } - - public static void writeTextToFile(String text, File file) throws IOException - { - FileOutputStream fos = new FileOutputStream(file); - OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); - osw.write(text); - osw.close(); - } - - public static void verifyReconstruction(String reconstructed_text, - String expected_text) - { - if (reconstructed_text.equals(expected_text)) - { - System.out.println("TEXT MATCHED OK!"); - } - else - { - System.err.println("TEXT DIDN'T MATCH!!!!!!!"); - } - } +// /** +// * The logger definition. +// */ +// private static final Logger logger = ConfigLogger.getLogger(AbsTexTest.class); +// +// /** +// * @param args +// * @throws IOException +// * @throws PresentableException +// */ +// public static void main(String[] args) throws IOException, PresentableException +// { +// SettingsReader.initializeForCommandLine(); +// PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties"); +// +// File BASE_DIR = new File("C:\\wprinz\\Filer\\egiz\\docs\\abstexsig"); +// File original_file = new File(BASE_DIR, "AbsTexSig.pdf"); +// File signed_file = new File(BASE_DIR, "AbsTexSig.pdf_out.pdf"); +// File signed_signed_file = new File(BASE_DIR, "AbsTexSig.pdf_out.pdf_out.pdf"); +// +// File in = new File("C:\\wprinz\\Filer\\egiz\\docs\\Abnahmetests\\tests\\commandline\\alte_sig\\document4.pdf_asimoaold.pdf_out.pdf"); +// byte[] pdf = readInFile(in); +// +// ByteArrayInputStream bais = new ByteArrayInputStream(pdf, 0, pdf.length); +// String raw_text = TextualSignature.extractTextTextual(bais); +// +// String text = PdfAS.extractNormalizedTextTextual(pdf, pdf.length); +// +// writeTextToFile(raw_text, new File(BASE_DIR, "raw_text.utf8.txt")); +// writeTextToFile(text, new File(BASE_DIR, "text.utf8.txt")); +// +// if (true) +// { +// return; +// } +// +// String[] texts = new String[3]; +// +// byte[] original = readInFile(original_file); +// byte[] signed = readInFile(signed_file); +// byte[] signed2 = readInFile(signed_signed_file); +// +// texts[0] = PdfAS.extractNormalizedTextTextual(original, original.length); +// texts[1] = PdfAS.extractNormalizedTextTextual(signed, signed.length); +// texts[2] = PdfAS.extractNormalizedTextTextual(signed2, signed2.length); +// +// writeTextToFile(texts[0], new File(BASE_DIR, "original.utf8.txt")); +// writeTextToFile(texts[1], new File(BASE_DIR, "signed.utf8.txt")); +// writeTextToFile(texts[2], new File(BASE_DIR, "signed_signed.utf8.txt")); +// +// // String text = texts[2]; +// +// List holders = AbsoluteTextSignature.extractSignatureHoldersFromText(text); +// logger.debug("extracted " + holders.size() + " holders:"); +// for (int i = 0; i < holders.size(); i++) +// { +// SignatureHolder holder = (SignatureHolder) holders.get(i); +// +// logger.debug(" #" + i + ": " + holder.getSignatureObject().getSignationDate() + ", " + holder.getSignatureObject().getSignatureTypeDefinition().getType()); +// } +// +// SignatureHolder sh_latest = (SignatureHolder) holders.get(1); +// +// SignatureHolder sh_earlier = (SignatureHolder) holders.get(0); +// +// writeTextToFile(sh_latest.getSignedText(), new File(BASE_DIR, "reconstructed_latest.utf8.txt")); +// writeTextToFile(sh_earlier.getSignedText(), new File(BASE_DIR, "reconstructed.utf8.txt")); +// +// verifyReconstruction(sh_latest.getSignedText(), texts[1]); +// verifyReconstruction(sh_earlier.getSignedText(), texts[0]); +// +// SignatureResponse sr = PdfAS.verify(sh_latest, "moa"); +// System.out.println(sr); +// sr = PdfAS.verify(sh_earlier, "moa"); +// System.out.println(sr); +// +// } +// +// public static byte[] readInFile(File file) throws IOException +// { +// FileInputStream fis = new FileInputStream(file); +// byte[] ba = new byte[(int) file.length()]; +// fis.read(ba); +// fis.close(); +// return ba; +// } +// +// public static void writeTextToFile(String text, File file) throws IOException +// { +// FileOutputStream fos = new FileOutputStream(file); +// OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); +// osw.write(text); +// osw.close(); +// } +// +// public static void verifyReconstruction(String reconstructed_text, +// String expected_text) +// { +// if (reconstructed_text.equals(expected_text)) +// { +// System.out.println("TEXT MATCHED OK!"); +// } +// else +// { +// System.err.println("TEXT DIDN'T MATCH!!!!!!!"); +// } +// } } diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/test/ExtractTextTextual.java b/src/main/java/at/knowcenter/wag/egov/egiz/test/ExtractTextTextual.java index e2433b0..b79c6f3 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/test/ExtractTextTextual.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/test/ExtractTextTextual.java @@ -17,46 +17,40 @@ */ package at.knowcenter.wag.egov.egiz.test; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import at.knowcenter.wag.egov.egiz.PdfAS; -import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; -import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; /** * Test. * + * @deprecated outdated + * * @author wprinz */ public class ExtractTextTextual { - /** - * @param args - * @throws IOException - * @throws PresentableException - */ - public static void main(String[] args) throws IOException, PresentableException - { - SettingsReader.initializeForCommandLine(); - - File in = new File(args[0]); - FileInputStream fis = new FileInputStream(in); - byte[] pdf = new byte[(int) in.length()]; - fis.read(pdf); - fis.close(); - - String text = PdfAS.extractNormalizedTextTextual(pdf, pdf.length); - - File out = new File(args[0] + ".txt"); - FileOutputStream fos = new FileOutputStream(out); - fos.write(text.getBytes("UTF-8")); - fos.close(); - - System.out.println("finished. written to " + out.getAbsolutePath()); - } +// /** +// * @param args +// * @throws IOException +// * @throws PresentableException +// */ +// public static void main(String[] args) throws IOException, PresentableException +// { +// SettingsReader.initializeForCommandLine(); +// +// File in = new File(args[0]); +// FileInputStream fis = new FileInputStream(in); +// byte[] pdf = new byte[(int) in.length()]; +// fis.read(pdf); +// fis.close(); +// +// String text = PdfAS.extractNormalizedTextTextual(pdf, pdf.length); +// +// File out = new File(args[0] + ".txt"); +// FileOutputStream fos = new FileOutputStream(out); +// fos.write(text.getBytes("UTF-8")); +// fos.close(); +// +// System.out.println("finished. written to " + out.getAbsolutePath()); +// } } -- cgit v1.2.3