diff options
Diffstat (limited to 'src/main/java/at/knowcenter/wag')
16 files changed, 85 insertions, 47 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index e2505ea..6fc7b84 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -28,6 +28,7 @@ import java.util.Vector; import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
import at.gv.egiz.pdfas.impl.input.DelimitedInputStream;
import at.gv.egiz.pdfas.impl.input.TextDataSourceImpl;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
@@ -1026,19 +1027,30 @@ public abstract class PdfAS // return extractNormalizedTextTextual(pdf, pdf.length);
// }
- public static String extractNormalizedTextTextual(InputStream pdfInputStream) throws PresentableException
+ public static String extractNormalizedTextTextual(PdfDataSource pdfDataSource) throws PresentableException
{
- String raw_document_text = TextualSignature.extractTextTextual(pdfInputStream);
+ String raw_document_text = TextualSignature.extractTextTextual(pdfDataSource);
String document_text = normalizeText(raw_document_text);
return document_text;
}
- public static String extractNormalizedTextTextual(InputStream pdfInputStream, int length) throws PresentableException
+ /**
+ @deprecated
+ */
+ public static String extractNormalizedTextTextual(byte [] pdf, int length) throws PresentableException
{
- DelimitedInputStream dis = new DelimitedInputStream(pdfInputStream, length);
- String raw_document_text = TextualSignature.extractTextTextual(dis);
+ ByteArrayPdfDataSourceImpl pdfDataSource = new ByteArrayPdfDataSourceImpl(pdf, length);
+ String raw_document_text = TextualSignature.extractTextTextual(pdfDataSource);
String document_text = normalizeText(raw_document_text);
return document_text;
}
+
+// public static String extractNormalizedTextTextual(InputStream pdfInputStream, int length) throws PresentableException
+// {
+// DelimitedInputStream dis = new DelimitedInputStream(pdfInputStream, length);
+// String raw_document_text = TextualSignature.extractTextTextual(dis);
+// String document_text = normalizeText(raw_document_text);
+// return document_text;
+// }
// /**
// * Extracts and normalizes the text from the pdf.
// *
@@ -1380,9 +1392,11 @@ public abstract class PdfAS {
try
{
- InputStream is = pdfDataSource.createInputStream();
- PdfReader reader = new PdfReader(is);
- is.close();
+ //InputStream is = pdfDataSource.createInputStream();
+ // PERF: byte array instead of stream
+ byte [] pdf_data = pdfDataSource.getAsByteArray();
+ PdfReader reader = new PdfReader(pdf_data);
+ //is.close();
return reader;
}
catch (IOException e)
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java index a158729..b7fcb96 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/cfg/SettingsReader.java @@ -284,7 +284,7 @@ public class SettingsReader implements Serializable if (logger_.isInfoEnabled())
{
File file = new File(settingsFile_);
- logger_.info("load Settings:" + file.getAbsolutePath());
+ logger_.debug("load Settings:" + file.getAbsolutePath());
// Properties sys_prop = System.getProperties();
// Enumeration prop_keys = sys_prop.propertyNames();
// while (prop_keys.hasMoreElements()) {
@@ -303,7 +303,7 @@ public class SettingsReader implements Serializable // load properties from current package!
// properties_.load(getClass().getResourceAsStream(settingsFile_));
Enumeration prop_keys = properties_.propertyNames();
-
+
while (prop_keys.hasMoreElements())
{
String key = (String) prop_keys.nextElement();
@@ -456,8 +456,7 @@ public class SettingsReader implements Serializable * the default value if the defaultKey is not found
* @return the value of the property key
*/
- public String getSetting(String primaryKey, String defaultKey,
- String defaultValue)
+ public String getSetting(String primaryKey, String defaultKey, String defaultValue)
{
String key = primaryKey;
String result = properties_.getProperty(key);
@@ -640,7 +639,7 @@ public class SettingsReader implements Serializable public static void clearTemporaryDirectory()
{
File temp_dir = assembleTemporaryDirectoryFile();
- logger_.info("Clearing temporary directory: " + temp_dir);
+ logger_.debug("Clearing temporary directory: " + temp_dir);
if (!temp_dir.exists())
{
@@ -650,7 +649,7 @@ public class SettingsReader implements Serializable File[] files = temp_dir.listFiles();
for (int i = 0; i < files.length; i++)
{
- logger_.info(" Clearing temporary file: " + files[i]);
+ logger_.debug(" Clearing temporary file: " + files[i]);
boolean delete_success = files[i].delete();
if (!delete_success)
{
@@ -662,7 +661,9 @@ public class SettingsReader implements Serializable /**
* Initializes the paths of the SettingsReader for web application usage.
*
- * @param base_dir The base directory of this web application. E.g. TOMCAT_HOME/webapps/pdf-as
+ * @param base_dir
+ * The base directory of this web application. E.g.
+ * TOMCAT_HOME/webapps/pdf-as
*/
public static void initializeForWeb(String base_dir)
{
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java index b0c7c30..72565d9 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/commandline/Main.java @@ -448,7 +448,7 @@ public abstract class Main {
carryOutVerify(input, connector, verify_which, messageOutput);
}
- messageOutput.close();
+ messageOutput.flush();
}
public static void carryOutSign(String input, String connector, String signature_mode, String signature_type, String pos_string, String user_name, String user_password, String output,
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/VerificationFilter.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/VerificationFilter.java index 2631028..6309ad4 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/VerificationFilter.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/VerificationFilter.java @@ -225,7 +225,7 @@ public class VerificationFilter logger_.debug("Incemental block" + prev_end + " and there are " + text_holders.size() + " text holders");
logger_.debug("Checking for older textual Signatures");
logger_.debug("Extracting text to " + bpr.next_index);
- rest_text = PdfAS.extractNormalizedTextTextual(new ByteArrayInputStream(pdf), bpr.next_index);
+ rest_text = PdfAS.extractNormalizedTextTextual(pdf, bpr.next_index);
}
List old_holders = PdfAS.extractSignatureHoldersTextual(rest_text, true);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedSignator_1_0_0.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedSignator_1_0_0.java index 4ef1e15..0728aae 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedSignator_1_0_0.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedSignator_1_0_0.java @@ -87,7 +87,7 @@ public class DetachedSignator_1_0_0 implements Signator iui.signature_type = signature_type;
iui.pos = pos;
- String document_text = PdfAS.extractNormalizedTextTextual(pdf.createInputStream());
+ String document_text = PdfAS.extractNormalizedTextTextual(pdf);
// logger_.debug("signed_text = " + document_text);
DataSource ds = new TextDataSourceImpl(document_text);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedfTextualSignator_1_0_0.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedfTextualSignator_1_0_0.java index d7c79ea..923d232 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedfTextualSignator_1_0_0.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedfTextualSignator_1_0_0.java @@ -95,7 +95,7 @@ public class DetachedfTextualSignator_1_0_0 implements Signator iui.signature_type = signature_type;
iui.pos = pos;
- String document_text = PdfAS.extractNormalizedTextTextual(pdf.createInputStream());
+ String document_text = PdfAS.extractNormalizedTextTextual(pdf);
// logger_.debug("signed_text = " + document_text);
DataSource ds = new TextDataSourceImpl(document_text);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/TextualSignator_1_0_0.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/TextualSignator_1_0_0.java index 33de15e..5ce21ce 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/TextualSignator_1_0_0.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/TextualSignator_1_0_0.java @@ -89,7 +89,7 @@ public class TextualSignator_1_0_0 implements Signator iui.signature_type = signature_type;
iui.pos = pos;
- String document_text = PdfAS.extractNormalizedTextTextual(pdf.createInputStream());
+ String document_text = PdfAS.extractNormalizedTextTextual(pdf);
// logger_.debug("signed_text = " + document_text);
DataSource ds = new TextDataSourceImpl(document_text);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_1_0_0.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_1_0_0.java index 176c0f0..1cd5930 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_1_0_0.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_1_0_0.java @@ -81,7 +81,7 @@ public class TextualVerificator_1_0_0 implements Verificator public List parseBlock(byte[] pdf, FooterParseResult block,
int start_of_whole_block) throws PresentableException
{
- String block_text = PdfAS.extractNormalizedTextTextual(new ByteArrayInputStream(pdf), block.next_index);
+ String block_text = PdfAS.extractNormalizedTextTextual(pdf, block.next_index);
logger_.debug("Scanning block:");
//List signature_holders = PdfAS.extractSignatureHoldersTextual(block_text, false);
@@ -100,7 +100,7 @@ public class TextualVerificator_1_0_0 implements Verificator {
text_holder_candidates = new ArrayList();
- String prev_text = PdfAS.extractNormalizedTextTextual(new ByteArrayInputStream(pdf), start_of_whole_block);
+ String prev_text = PdfAS.extractNormalizedTextTextual(pdf, start_of_whole_block);
logger_.debug("Scanning prev block:");
//List prev_signature_holders = PdfAS.extractSignatureHoldersTextual(prev_text, false);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_pdfasold.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_pdfasold.java index ea84e7e..85bc96c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_pdfasold.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/verificators/TextualVerificator_pdfasold.java @@ -61,7 +61,7 @@ public class TextualVerificator_pdfasold implements Verificator throw new PDFDocumentException(201, "The PDF-AS-old Verificator can only be applied on original documents.");
}
- String normalized_text = PdfAS.extractNormalizedTextTextual(new ByteArrayInputStream(pdf), block.next_index);
+ String normalized_text = PdfAS.extractNormalizedTextTextual(pdf, block.next_index);
logger_.debug("Scanning block:");
List signature_holders = PdfAS.extractSignatureHoldersTextual(normalized_text, true);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java index d253393..677990b 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java @@ -689,9 +689,10 @@ public abstract class BinarySignature // System.out.println("wprinz: STAMPING PDF");
- InputStream is = original_document.createInputStream();
- PdfReader reader = new PdfReader(is);
- is.close();
+ //InputStream is = original_document.createInputStream();
+ byte [] pdf_data = original_document.getAsByteArray();
+ PdfReader reader = new PdfReader(pdf_data);
+ //is.close();
OutputStream baos = written_pdf.createOutputStream("application/pdf");
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java index 8b8475c..b801706 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/EGIZDate.java @@ -134,9 +134,19 @@ public class EGIZDate { if (li >= 19) {
date_value = new StringBuffer(date_value).deleteCharAt(li).toString();
}
- if (date_value.endsWith("Z")) {
- date_value = date_value.substring(0, date_value.length()-2) + "UTC";
- }
+ // FIXME: @iaik: wenn man bei UTC+"Z" die letzten -2 Zeichen durch "UTC" ersetzt verliert die Zeit ihre Sekunden-Einerstelle!!!!!!!
+ // alter code:
+// if (date_value.endsWith("Z")) {
+// date_value = date_value.substring(0, date_value.length()-2) + "UTC";
+// }
+ // neuer code:
+ if (date_value.endsWith("ZZ")) {
+ date_value = date_value.substring(0, date_value.length()-2) + "UTC";
+ }
+ if (date_value.endsWith("Z")) {
+ date_value = date_value.substring(0, date_value.length()-1) + "UTC";
+ }
+
} else {
date_value += "UTC";
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java index e19c244..b40d129 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFUtilities.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.List;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl;
import org.pdfbox.pdfparser.PDFParser;
import org.pdfbox.pdmodel.PDDocument;
@@ -47,7 +48,7 @@ public abstract class PDFUtilities {
//ByteArrayInputStream original_bais = new ByteArrayInputStream(pdf);
//byte [] normalized_pdf = TextualSignature.normalizePDF(original_bais);
- byte [] normalized_pdf = TextualSignature.normalizePDF(pdfDataSource.createInputStream());
+ byte [] normalized_pdf = TextualSignature.normalizePDF(pdfDataSource);
// PERF: The whole PDF normalization process is costy
ByteArrayInputStream bais = new ByteArrayInputStream(normalized_pdf);
@@ -80,12 +81,20 @@ public abstract class PDFUtilities return calculatePageLength(pdpage, footer_line);
}
+ /**
+ * @deprecated
+ * @param pdf
+ * @param footer_line
+ * @return
+ * @throws PDFDocumentException
+ */
public static float calculateLastPageLength(final byte[] pdf, float footer_line) throws PDFDocumentException
{
try
{
- ByteArrayInputStream original_bais = new ByteArrayInputStream(pdf);
- byte [] normalized_pdf = TextualSignature.normalizePDF(original_bais);
+ //ByteArrayInputStream original_bais = new ByteArrayInputStream(pdf);
+ PdfDataSource dataSource = new ByteArrayPdfDataSourceImpl(pdf);
+ byte [] normalized_pdf = TextualSignature.normalizePDF(dataSource);
ByteArrayInputStream bais = new ByteArrayInputStream(normalized_pdf);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java index 668bbcb..04b96fc 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/TextualSignature.java @@ -25,6 +25,7 @@ import java.io.InputStream; import at.gv.egiz.pdfas.performance.PerformanceCounters;
import at.gv.egiz.pdfas.exceptions.pdf.TextExtractionException;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import org.apache.log4j.Logger;
import org.pdfbox.pdfparser.PDFParser;
@@ -64,7 +65,7 @@ public class TextualSignature * @throws PresentableException
* Forwarded exception.
*/
- public static String extractTextTextual(InputStream pdf_stream) throws TextExtractionException
+ public static String extractTextTextual(PdfDataSource pdfDataSource) throws TextExtractionException
{
PerformanceCounters.textExtractions.increment();
@@ -83,8 +84,9 @@ public class TextualSignature // byte[] bytes = normalizePDF(pdf_stream);
//iText
- PdfReader reader = new PdfReader(pdf_stream);
- pdf_stream.close();
+ byte [] pdf_data = pdfDataSource.getAsByteArray();
+ PdfReader reader = new PdfReader(pdf_data);
+ //pdf_stream.close();
// PERF: PDF normalization needs byte array - this is costy
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
@@ -202,11 +204,12 @@ public class TextualSignature * @throws IOException
* @throws DocumentException
*/
- public static byte[] normalizePDF(InputStream input_pdf) throws IOException, DocumentException
+ public static byte[] normalizePDF(PdfDataSource pdfDataSource) throws IOException, DocumentException
{
- //iText
- PdfReader reader = new PdfReader(input_pdf);
- input_pdf.close();
+ //iText
+ byte [] pdf_data = pdfDataSource.getAsByteArray();
+ PdfReader reader = new PdfReader(pdf_data);
+ //input_pdf.close();
// PERF: PDF Normalization needs byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java index 0c1a420..53ac7cf 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/tools/FileHelper.java @@ -58,9 +58,9 @@ public class FileHelper { }
reader.close();
} catch (FileNotFoundException e) {
- logger_.info("File not found:" + fileName);
+ logger_.debug("File not found:" + fileName);
} catch (IOException e) {
- logger_.info("File can not read:" + fileName);
+ logger_.debug("File can not read:" + fileName);
}
return file_string;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java index 2844c6d..ed4fc7a 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java @@ -17,6 +17,9 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import at.gv.egiz.pdfas.exceptions.framework.SignatorException;
import at.gv.egiz.pdfas.framework.SignatorFactory;
import at.gv.egiz.pdfas.framework.signator.Signator;
@@ -25,10 +28,6 @@ import at.gv.egiz.pdfas.web.VerifySessionInformation; import at.gv.egiz.pdfas.web.helper.SessionHelper;
import at.gv.egiz.pdfas.web.helper.SignServletHelper;
import at.gv.egiz.pdfas.web.helper.TempDirHelper;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import at.knowcenter.wag.egov.egiz.PdfASID;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
import at.knowcenter.wag.egov.egiz.exceptions.InvalidIDException;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java index 60b3431..04971c6 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java @@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletResponse; import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.exceptions.ErrorCodeHelper;
import at.gv.egiz.pdfas.exceptions.external.ExternalErrorException;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
import at.gv.egiz.pdfas.impl.input.FileBasedPdfDataSourceImpl;
import at.gv.egiz.pdfas.web.SignSessionInformation;
import at.gv.egiz.pdfas.web.helper.SignServletHelper;
@@ -427,7 +428,7 @@ public class SignServlet extends HttpServlet throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
}
- FileBasedPdfDataSourceImpl pdfDataSource = null;
+ PdfDataSource pdfDataSource = null;
try
{
pdfDataSource = TempDirHelper.placePdfIntoTempDir(file_upload_fi.getInputStream(), doc_file_name);
@@ -571,7 +572,7 @@ public class SignServlet extends HttpServlet protected String file_name = null;
- protected FileBasedPdfDataSourceImpl pdfDataSource = null;
+ protected PdfDataSource pdfDataSource = null;
// protected byte[] pdf = null;
}
}
\ No newline at end of file |