aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java210
1 files changed, 210 insertions, 0 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
new file mode 100644
index 0000000..6331a54
--- /dev/null
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/FormFields.java
@@ -0,0 +1,210 @@
+/**
+ * <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: FormFields.java,v 1.4 2006/10/11 07:39:13 wprinz Exp $
+ */
+package at.knowcenter.wag.egov.egiz.web;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.servlet.ServletException;
+
+import at.knowcenter.wag.egov.egiz.PdfASID;
+import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorFactoryException;
+import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
+import at.knowcenter.wag.egov.egiz.framework.SignatorFactory;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorFactory;
+import at.knowcenter.wag.egov.egiz.sig.ConnectorInformation;
+import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
+
+/**
+ * Helper class that provides methods and constants for creating and dealing
+ * with the various form fields.
+ *
+ * @author wprinz
+ */
+public abstract class FormFields
+{
+ public static final String PARAMETER_FREE_TEXT_ENTRY = "freetext";
+
+ public static final String FIELD_UPLOAD = "upload";
+
+ public static final String FIELD_CONNECTOR = "connector";
+
+ public static final String FIELD_MODE = "mode";
+
+ public static final String FIELD_PREVIEW = "preview";
+
+ public static final String FIELD_RAW_DOCUMENT_TEXT = "raw_document_text";
+
+ public static final String FIELD_SIGNATURE_TYPE = "sig_type";
+
+ public static final String FIELD_VERIFY_WHICH = "verify_which";
+
+ public static final String FIELD_DOWNLOAD = "download";
+
+ public static final String VALUE_TRUE = "true";
+
+ public static final String VALUE_FALSE = "false";
+
+ public static final String VALUE_MODE_BINARY = "binary";
+
+ public static final String VALUE_MODE_TEXTUAL = "textual";
+
+ public static final String VALUE_MODE_DETACHED = "detached";
+
+ public static final String VALUE_VERIFY_WHICH_ALL = "all";
+
+ public static final String VALUE_DOWNLOAD_INLINE = "inline";
+
+ public static final String VALUE_DOWNLOAD_ATTACHMENT = "attachment";
+
+ protected static final String STYLE_CLASS_FIELD = "field";
+
+ /**
+ * Translates the form field to a PDF-AS-ID.
+ *
+ * @param signature_mode
+ * The signator mode form field.
+ * @return Returns the corresponding PDFASID.
+ */
+ protected static PdfASID translateSignatureModeToPdfASID(String signature_mode)
+ {
+ if (signature_mode.equals(VALUE_MODE_BINARY))
+ {
+ return SignatorFactory.MOST_RECENT_BINARY_SIGNATOR_ID;
+ }
+ if (signature_mode.equals(VALUE_MODE_TEXTUAL))
+ {
+ return SignatorFactory.MOST_RECENT_TEXTUAL_SIGNATOR_ID;
+ }
+ if (signature_mode.equals(VALUE_MODE_DETACHED))
+ {
+ return SignatorFactory.MOST_RECENT_DETACHED_SIGNATOR_ID;
+ }
+ return null;
+ }
+
+ /**
+ * Generates the HTML snippet of a FIELD_CONNECTOR select box that allows to
+ * choose a connector.
+ *
+ * @return Returns the HTML snippet.
+ * @throws SettingsException
+ * Forwarded exception.
+ * @throws ConnectorFactoryException
+ * Forwarded exception.
+ */
+ public static String generateConnectorSelectBox() throws SettingsException, ConnectorFactoryException
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+
+ writer.println("<select name=\"" + FIELD_CONNECTOR + "\" class=\"" + STYLE_CLASS_FIELD + "\">");
+
+ SettingsReader settings = SettingsReader.getInstance();
+ String default_connector = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE);
+
+ ConnectorInformation ci[] = ConnectorFactory.getConnectorInformationArray();
+
+ for (int i = 0; i < ci.length; i++)
+ {
+ String id = ci[i].getIdentifier();
+ if (!ConnectorFactory.isAvailableForWeb(id))
+ {
+ continue;
+ }
+
+ writer.print("<option value=\"" + id + "\"");
+ if (id.equals(default_connector))
+ {
+ writer.print(" selected=\"selected\"");
+ }
+ writer.println(">" + ci[i].getDescription() + "</option>");
+ }
+
+ writer.println("</select>");
+
+ return sw.toString();
+ }
+
+ /**
+ * Generates a HTML snippet of a FIELD_SIGNATURE_TYPE select box that allows
+ * to choose the signature type.
+ *
+ * @return Returns the HTML snippet.
+ * @throws ServletException
+ * Forwarded exception.
+ */
+ public static String generateTypeSelectBox() throws ServletException
+ {
+ try
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter writer = new PrintWriter(sw);
+
+ SettingsReader settings = SettingsReader.getInstance();
+ SignatureTypes sig_types = SignatureTypes.getInstance();
+
+ // SettingsReader settings = null;
+ // SignatureTypes sig_types = null;
+ // try
+ // {
+ // settings = SettingsReader.getInstance();
+ // sig_types = SignatureTypes.getInstance();
+ // }
+ // catch (IOException e)
+ // {
+ // String log_message = "Can not load signature settings. Cause:\n" +
+ // e.getMessage();
+ // logger_.error(log_message);
+ // req.setAttribute("error", "Das System konnte nicht gestartet werden.");
+ // req.setAttribute("cause", "Die Konfiguration ist fehlerhaft oder konnte
+ // nicht geladen werden.");
+ // dispatch(req, res, "/jsp/error.jsp");
+ // }
+
+ ArrayList types_array = sig_types.getSignatureTypes();
+ Iterator type_it = types_array.iterator();
+
+ String default_type = settings.getValueFromKey(SignatureTypes.DEFAULT_TYPE);
+
+ writer.println("<select class=\"" + STYLE_CLASS_FIELD + "\" name=\"" + FIELD_SIGNATURE_TYPE + "\">");
+
+ while (type_it.hasNext())
+ {
+ String type = (String) type_it.next();
+ String descr_key = SignatureTypes.SIG_OBJ + type + "." + SignatureTypes.SIG_DESCR;
+ String type_descr = settings.getValueFromKey(descr_key);
+
+ writer.println("<option value=\"" + type + "\" " + (type.equals(default_type) ? "selected=\"selected\"" : "") + ">" + type_descr + "</option>");
+
+ }
+
+ writer.println("</select>");
+
+ return sw.toString();
+ }
+ catch (Exception e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+}