diff options
4 files changed, 151 insertions, 7 deletions
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 000e7c6..e1284ce 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 @@ -126,6 +126,11 @@ public abstract class Main * The application mode verify
*/
public static final String VALUE_SIGNATURE_MODE_DETACHED = "detached";
+
+ /**
+ * The application mode verify
+ */
+ public static final String VALUE_SIGNATURE_MODE_DETACHED_TEXt = "detachedtextual";
/**
* The logger definition.
@@ -723,7 +728,8 @@ public abstract class Main writer.println(" " + PARAMETER_SIGNATURE_MODE + " <" + VALUE_SIGNATURE_MODE_BINARY + "|" + VALUE_SIGNATURE_MODE_TEXTUAL + ">");
writer.println(" " + VALUE_SIGNATURE_MODE_BINARY + " ... signs the complete binary document");
writer.println(" " + VALUE_SIGNATURE_MODE_TEXTUAL + " ... signs only the textual portion of the document");
- writer.println(" " + VALUE_SIGNATURE_MODE_DETACHED + " ... signs the document and returns the xml signature of it.");
+ writer.println(" " + VALUE_SIGNATURE_MODE_DETACHED + " ... signs the document using the binary mode and returns the xml signature of it.");
+ writer.println(" " + VALUE_SIGNATURE_MODE_DETACHED_TEXt + " ... signs the document using the textual mode and returns the xml signature of it.");
writer.print(" " + PARAMETER_SIGNATURE_TYPE + " <");
SignatureTypes sig_types = SignatureTypes.getInstance();
@@ -800,7 +806,7 @@ public abstract class Main */
protected static boolean checkSignatureMode(String signature_mode)
{
- return signature_mode.equals(VALUE_SIGNATURE_MODE_BINARY) || signature_mode.equals(VALUE_SIGNATURE_MODE_TEXTUAL) || signature_mode.equals(VALUE_SIGNATURE_MODE_DETACHED);
+ return signature_mode.equals(VALUE_SIGNATURE_MODE_BINARY) || signature_mode.equals(VALUE_SIGNATURE_MODE_TEXTUAL) || signature_mode.equals(VALUE_SIGNATURE_MODE_DETACHED) || signature_mode.equals(VALUE_SIGNATURE_MODE_DETACHED_TEXt);
}
/**
@@ -861,6 +867,10 @@ public abstract class Main {
return SignatorFactory.MOST_RECENT_DETACHED_SIGNATOR_ID;
}
+ if (signature_mode.equals(VALUE_SIGNATURE_MODE_DETACHED_TEXt))
+ {
+ return SignatorFactory.MOST_RECENT_DETACHEDTEXT_SIGNATOR_ID;
+ }
return null;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/framework/SignatorFactory.java b/src/main/java/at/knowcenter/wag/egov/egiz/framework/SignatorFactory.java index fbba7dc..a9bc144 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/framework/SignatorFactory.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/SignatorFactory.java @@ -21,6 +21,7 @@ import at.knowcenter.wag.egov.egiz.PdfASID; import at.knowcenter.wag.egov.egiz.exceptions.SignatorFactoryException;
import at.knowcenter.wag.egov.egiz.framework.signators.BinarySignator_1_0_0;
import at.knowcenter.wag.egov.egiz.framework.signators.DetachedSignator_1_0_0;
+import at.knowcenter.wag.egov.egiz.framework.signators.DetachedfTextualSignator_1_0_0;
import at.knowcenter.wag.egov.egiz.framework.signators.TextualSignator_1_0_0;
/**
@@ -50,6 +51,11 @@ public abstract class SignatorFactory * This signator is only for testing the framework.
*/
public static final String TYPE_TEST = "testalgo";
+
+ /**
+ * This signator is only for testing the framework.
+ */
+ public static final String TYPE_DETACHED_TEXTUAL = "detachedtext";
/**
* This application's current algorithm versions.
@@ -72,6 +78,12 @@ public abstract class SignatorFactory public static final PdfASID MOST_RECENT_DETACHED_SIGNATOR_ID = DetachedSignator_1_0_0.MY_ID;
/**
+ * The most recent test algorithm this application provides.
+ */
+ public static final PdfASID MOST_RECENT_DETACHEDTEXT_SIGNATOR_ID = DetachedfTextualSignator_1_0_0.MY_ID;
+
+
+ /**
* Creates a Signator for the given ID.
*
* @param id
@@ -116,6 +128,16 @@ public abstract class SignatorFactory throw new SignatorFactoryException("The version '" + id.getVersion() + "' of type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')");
}
+
+ if (id.getType().equals(TYPE_DETACHED_TEXTUAL))
+ {
+ if (id.getVersion().equals(VERSION_1_0_0))
+ {
+ return new DetachedfTextualSignator_1_0_0();
+ }
+
+ throw new SignatorFactoryException("The version '" + id.getVersion() + "' of type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')");
+ }
throw new SignatorFactoryException("The type '" + id.getType() + "' is not supported by this SignatorFactory. (id='" + id + "')");
}
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 new file mode 100644 index 0000000..0de4bc4 --- /dev/null +++ b/src/main/java/at/knowcenter/wag/egov/egiz/framework/signators/DetachedfTextualSignator_1_0_0.java @@ -0,0 +1,112 @@ +/**
+ * <copyright> Copyright (c) 2006 by Know-Center, Graz, Austria </copyright>
+ *
+ * This software is the confidential and proprietary information of Know-Center,
+ * Graz, Austria. You shall not disclose such Confidential Information and shall
+ * use it only in accordance with the terms of the license agreement you entered
+ * into with Know-Center.
+ *
+ * KNOW-CENTER MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
+ * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
+ * NON-INFRINGEMENT. KNOW-CENTER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
+ * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
+ * DERIVATIVES.
+ *
+ * $Id: TextualSignator_1_0_0.java,v 1.3 2006/10/31 08:07:50 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz.framework.signators;
+
+import java.io.UnsupportedEncodingException;
+
+import at.knowcenter.wag.egov.egiz.PdfAS;
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
+import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
+import at.knowcenter.wag.egov.egiz.framework.SignResult;
+import at.knowcenter.wag.egov.egiz.framework.Signator;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.pdf.BinarySignature;
+import at.knowcenter.wag.egov.egiz.pdf.IncrementalUpdateInformation;
+import at.knowcenter.wag.egov.egiz.pdf.PositioningInstruction;
+import at.knowcenter.wag.egov.egiz.pdf.TablePos;
+
+import com.lowagie.text.pdf.PdfPTable;
+
+/**
+ * Signs a document textually.
+ *
+ * <p>
+ * In prepareSign, the document text is extracted and normalized.
+ * </p>
+ * <p>
+ * In finishSign, the signed SignatureObject is transformed into a Signature
+ * block, which is then written as an Incremental Update.
+ * </p>
+ *
+ * @author wprinz
+ */
+public class DetachedfTextualSignator_1_0_0 implements Signator
+{
+ /**
+ * The Mime Type.
+ */
+ public static final String MIME_TYPE = "text/xml";
+
+ /**
+ * The Pdf-AS ID of this Signator.
+ */
+ public static final PdfASID MY_ID = new PdfASID(SignatorFactory.VENDOR, SignatorFactory.TYPE_DETACHED_TEXTUAL, SignatorFactory.VERSION_1_0_0);
+
+ /**
+ * Default constructor.
+ */
+ public DetachedfTextualSignator_1_0_0()
+ {
+ // Default constructor.
+ }
+
+ /**
+ * <p>
+ * The parameter has_SIG_ID is not used by this Signator because it doesn't
+ * pre-format the signature block.
+ * </p>
+ *
+ * @see at.knowcenter.wag.egov.egiz.framework.Signator#prepareSign(byte[],
+ * String, TablePos, boolean)
+ */
+ public IncrementalUpdateInformation prepareSign(byte[] pdf,
+ String signature_type, TablePos pos, boolean has_SIG_ID) throws PresentableException
+ {
+ IncrementalUpdateInformation iui = new IncrementalUpdateInformation();
+ iui.original_document = pdf;
+ iui.signature_type = signature_type;
+ iui.pos = pos;
+
+ iui.document_text = PdfAS.extractNormalizedTextTextual(pdf);
+ // logger_.debug("signed_text = " + document_text);
+
+ return iui;
+ }
+
+ /**
+ * @see at.knowcenter.wag.egov.egiz.framework.Signator#finishSign(at.knowcenter.wag.egov.egiz.pdf.IncrementalUpdateInformation)
+ */
+ public SignResult finishSign(IncrementalUpdateInformation iui) throws PresentableException
+ {
+ try
+ {
+ String response = iui.signed_signature_object.getRawSignatureResponse();
+ byte[] response_bytes = response.getBytes("UTF-8");
+
+ SignResult sign_result = new SignResult(MIME_TYPE, response_bytes);
+ return sign_result;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ e.printStackTrace();
+ throw new PDFDocumentException(300, e);
+ }
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Placeholder.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Placeholder.java index 62050d3..000b3c2 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Placeholder.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/Placeholder.java @@ -283,16 +283,16 @@ public abstract class Placeholder // text = URLDecoder.decode(text);
// }
- text = text.replace("\\)", ")");
- text = text.replace("\\(", "(");
- text = text.replace("\\\\", "\\");
+// text = text.replace("\\)", ")");
+// text = text.replace("\\(", "(");
+// text = text.replace("\\\\", "\\");
// TODO: replace jdk1.5-code with jdf1.4-code (should be tested)
- /*
+ /* */
text = text.replaceAll("\\\\\\)", ")");
text = text.replaceAll("\\\\\\(", "(");
text = text.replaceAll("\\\\\\\\", "\\\\");
- */
+
return text;
}
|