aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-as-web')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java596
1 files changed, 407 insertions, 189 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
index bedb1b1..5e6ee03 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SignServlet.java
@@ -23,6 +23,7 @@
*
* $Id: Sign.java,v 1.7 2006/10/11 07:39:13 wprinz Exp $
*/
+
package at.gv.egiz.pdfas.web.servlets;
import java.io.BufferedInputStream;
@@ -51,6 +52,7 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.api.commons.Constants;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.io.DataSource;
import at.gv.egiz.pdfas.api.io.TextBased;
@@ -95,7 +97,24 @@ public class SignServlet extends HttpServlet
*/
private static Log log = LogFactory.getLog(SignServlet.class);
private static Log statLog = LogFactory.getLog("statistic");
-
+
+ public static final String SUBMITFORM_SIGNATURE_TYPE_KEY = "signupload.jsp:signatureType";
+ public static final String SUBMITFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode";
+ public static final String SUBMITFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey";
+ public static final String SUBMITFORM_PDFA_KEY = "signupload.jsp:pdfaKey";
+ public static final String SUBMITFORM_SOURCE_KEY = "signupload.jsp:sourceKey";
+ public static final String SUBMITFORM_FREETEXT_KEY = "signupload.jsp:freeTextKey";
+ public static final String SUBMITFORM_NOTE_KEY = "signupload.jsp:noteKey";
+ public static final String SUBMITFORM_FILE_KEY = "signupload.jsp:fileKey";
+ public static final String SUBMITFORM_FILENAME_KEY = "signupload.jsp:filenameKey";
+ public static final String SUBMITFORM_PREVIEW = "signupload.jsp:previewKey";
+
+ //Added by rpiazzi to know if an error occured within IFrame because this calls for
+ //a different display of the error
+ public static final String ERROR_WITHIN_IFRAME = "error_within_iframe";
+ //Added by rpiazzi to know the height of the div's in further jsp's
+ public static final String HEIGHT_SIGN_DIV = "height_sign_div";
+
protected void dispatch(HttpServletRequest request, HttpServletResponse response, String resource) throws ServletException, IOException
{
dispatch(request, response, resource, getServletContext());
@@ -131,7 +150,6 @@ public class SignServlet extends HttpServlet
// check if pdf-as has been called by external webapp
if (request.getParameter(FormFields.FIELD_PDF_URL) != null)
{
-
String preview = (String) request.getParameter(FormFields.FIELD_PREVIEW);
String sig_type = (String) request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
String sig_app = (String) request.getParameter(FormFields.FIELD_CONNECTOR);
@@ -139,7 +157,6 @@ public class SignServlet extends HttpServlet
String filename = (String) request.getParameter(FormFields.FIELD_FILENAME);
String pdf_url = (String) request.getParameter(FormFields.FIELD_PDF_URL);
String pdf_id = (String) request.getParameter(FormFields.FIELD_PDF_ID);
- String pdf_length = (String) request.getParameter(FormFields.FIELD_FILE_LENGTH);
String invoke_url = (String) request.getParameter(FormFields.FIELD_INVOKE_APP_URL);
String invoke_error_url = (String) request.getParameter(FormFields.FIELD_INVOKE_APP_ERROR_URL);
String session_id = (String) request.getParameter(FormFields.FIELD_SESSION_ID);
@@ -163,7 +180,8 @@ public class SignServlet extends HttpServlet
// fixed by tknall: if we already have parameters "&" must be used instead of "?"
String paramSeparator = (pdf_url.indexOf("?") != -1) ? "&" : "?";
String query = pdf_url + paramSeparator + FormFields.FIELD_PDF_ID + "=" + pdf_id;
-
+ query = pdf_url;
+
// wprinz: rem: this allocation is useless
// byte[] extern_pdf = new byte[Integer.parseInt(pdf_length)];
URL source_url = new URL(query);
@@ -182,9 +200,13 @@ public class SignServlet extends HttpServlet
ud_extern.sig_mode = sig_mode;
ud_extern.sig_type = sig_type;
+ ud_extern.note = true;
+ ud_extern.pdfa = false;
+
ud = ud_extern;
exappinf = new ExternAppInformation(invoke_url, pdf_id, session_id, invoke_error_url);
+
}
else
{
@@ -197,15 +219,67 @@ public class SignServlet extends HttpServlet
// end modify
}
- catch (Exception e)
+ catch (PdfAsException e)
{
- log.error(e);
- request.setAttribute("error", "signservlet.error");
- request.setAttribute("cause", "signservlet.cause");
- request.setAttribute("resourcebundle", Boolean.TRUE);
+ log.error(e);
+
+ //Added by rpiazzi to know if error happened when request was within iframe
+ //In this case the visualization of the error has to be done differently
+ HttpSession session = request.getSession();
+ if (((String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY)).equals(Constants.SIGNATURE_DEVICE_BKU)) {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "no");
+ }
+ else {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "yes");
+ }
+ //end added
+
+ prepareDispatchToErrorPage(e, request);
dispatch(request, response, "/jsp/error.jsp");
+
+
+
+
return;
}
+ catch (FileUploadException e) {
+ log.error(e);
+
+ //Added by rpiazzi to know if error happened when request was within iframe
+ //In this case the visualization of the error has to be done differently
+ HttpSession session = request.getSession();
+ if (((String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY)).equals(Constants.SIGNATURE_DEVICE_BKU)) {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "no");
+ }
+ else {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "yes");
+ }
+ //end added
+
+ request.setAttribute("error", e.getMessage());
+ request.setAttribute("cause", e.getCause());
+ request.setAttribute("resourcebundle", Boolean.TRUE);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
+ catch (IOException e) {
+ log.error(e);
+
+ //Added by rpiazzi to know if error happened when request was within iframe
+ //In this case the visualization of the error has to be done differently
+ HttpSession session = request.getSession();
+ if (((String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY)).equals(Constants.SIGNATURE_DEVICE_BKU)) {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "no");
+ }
+ else {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "yes");
+ }
+ //end added
+
+ request.setAttribute("error", e.getMessage());
+ request.setAttribute("cause", e.getCause());
+ request.setAttribute("resourcebundle", Boolean.TRUE);
+ dispatch(request, response, "/jsp/error.jsp");
+ }
}
try
{
@@ -219,9 +293,12 @@ public class SignServlet extends HttpServlet
si.mode = ud.sig_mode;
si.pdfDataSource = ud.pdfDataSource;
si.type = ud.sig_type;
+
si.filename = formatFileName(ud.file_name);
+
si.download_inline = ud.download_inline;
si.pdfa = ud.pdfa;
+ si.note = ud.note;
// added tzefferer:
si.exappinf = exappinf;
@@ -229,6 +306,20 @@ public class SignServlet extends HttpServlet
// end add
HttpSession session = request.getSession();
+
+ //added by rpiazzi to change signature block with/without note
+ if (si.note) {
+ if (si.type.equals(FormFields.VALUE_SIGNATURE_TYPE_DE)) {
+ si.type = "SIGNATURBLOCK_DE_NOTE";
+ session.setAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY, si.type);
+ }
+ else {
+ si.type = "SIGNATURBLOCK_EN_NOTE";
+ session.setAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY, si.type);
+ }
+ }
+ //End added
+
log.info("Putting signature data into session " + session.getId());
session.setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, si);
@@ -241,7 +332,8 @@ public class SignServlet extends HttpServlet
SignServletHelper.prepareSign(ApiHelper.getPdfAsFromContext(getServletContext()), si);
- if (ud.preview)
+ //comment out by rpiazzi because preview has now its own Servlet
+ /*if (ud.preview)
{
String submit_url = response.encodeURL(request.getContextPath() + "/SignPreview");
String signature_data_url = response.encodeURL(WebUtils.buildRetrieveSignatureDataURL(request, response));
@@ -255,7 +347,8 @@ public class SignServlet extends HttpServlet
dispatch(request, response, "/jsp/signpreview.jsp");
return;
- }
+ }*/
+
SignServletHelper.finishSign(si, request, response, getServletContext());
@@ -284,11 +377,12 @@ public class SignServlet extends HttpServlet
// tzefferer:added
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- doPost(request, response);
+ HttpSession session = request.getSession();
+ doPost(request, response);
}
// end add
- protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException
+ protected UploadedData retrieveUploadedDataFromRequest(HttpServletRequest request) throws ServletException, UnsupportedEncodingException, FileUploadException, PDFDocumentException, IOException
{
DiskFileItemFactory fif = new DiskFileItemFactory();
fif.setRepository(WebSettingsReader.getTemporaryDirectory());
@@ -296,183 +390,301 @@ public class SignServlet extends HttpServlet
List items = sfu.parseRequest(request);
- FileItem preview_fi = null;
- FileItem sig_type_fi = null;
- FileItem sig_app_fi = null;
+ //FileItem preview_fi = null;
FileItem mode_fi = null;
FileItem file_upload_fi = null;
- FileItem download_fi = null;
- FileItem freeText = null;
- FileItem pdfa = null;
-
+ //FileItem download_fi = null;
+ FileItem freeText_fi = null;
+ FileItem source_fi = null;
+ FileItem sig_type_fi = null;
+ FileItem sig_app_fi = null;
+
+ boolean pdfaEnabled=false;
+ boolean noteEnabled=false;
+ String sig_type="";
+ String sig_app="";
+ String mode="";
+ String doc_file_name;
+ DataSource pdfDataSource;
+
+
Iterator it = items.iterator();
HttpSession session = request.getSession();
- while (it.hasNext())
- {
- FileItem item = (FileItem) it.next();
- log.debug("item = " + item.getFieldName()); //$NON-NLS-1$
-
- if (log.isDebugEnabled())
- {
- if (item.isFormField())
- {
- String item_string = item.getString("UTF-8"); //$NON-NLS-1$
- log.debug(" form field string = " + item_string); //$NON-NLS-1$
- }
- else
- {
- log.debug(" filename = " + item.getName()); //$NON-NLS-1$
- log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$
- }
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_PREVIEW))
- {
- preview_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
- {
- sig_type_fi = item;
- session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY, sig_type_fi.getString("UTF-8"));
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR))
- {
- sig_app_fi = item;
- session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8"));
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_MODE))
- {
- mode_fi = item;
- session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode_fi.getString("UTF-8"));
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_UPLOAD))
- {
- file_upload_fi = item;
- continue;
- }
-
- if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD))
- {
- download_fi = item;
- continue;
- }
-
- if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) {
- pdfa = item;
- session.setAttribute(UpdateFormServlet.UPLOADFORM_PDFA_KEY, pdfa.getString("UTF-8"));
- continue;
- }
-
- if (FormFields.FIELD_FREETEXT.equals(item.getFieldName())) {
- freeText = item;
- String value = freeText.getString("UTF-8");
- if (value != null) {
- session.setAttribute(UpdateFormServlet.UPLOADFORM_FREETEXT_KEY, value);
- }
- continue;
- }
-
- if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) {
- session.setAttribute(UpdateFormServlet.UPLOADFORM_SOURCE_KEY, item.getString("UTF-8"));
- continue;
- }
-
- throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$
-
- }
-
- if (preview_fi == null || sig_type_fi == null || sig_app_fi == null || (file_upload_fi == null && freeText== null) || download_fi == null)
- {
- throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$
- }
-
- String mode = mode_fi.getString("UTF-8"); //$NON-NLS-1$
- if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL) && !mode.equals(FormFields.VALUE_MODE_DETACHED))
- {
- throw new ServletException("The mode '" + mode + "' is unrecognized."); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- String preview_str = preview_fi.getString("UTF-8"); //$NON-NLS-1$
- boolean preview = false;
- if (preview_str.equals("true")) //$NON-NLS-1$
- {
- preview = true;
+
+
+
+ //Added by rpiazzi. If servlet was called for preview data was already written into
+ //session.
+ //Now commented out because the preview function is no more supported
+ /*if ((((FileItem)items.get(0)).getFieldName().equals(SignServlet.SUBMITFORM_PREVIEW))) {
+ FileItem fi = (FileItem)items.get(1);
+
+ sig_app_fi = fi;
+ session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, sig_app_fi.getString("UTF-8"));
+
+ if (((String)session.getAttribute(SUBMITFORM_PDFA_KEY))!=null) {
+ if (((String)session.getAttribute(SUBMITFORM_PDFA_KEY)).equals("on")) {
+ pdfaEnabled = true;
+ }
+ }
+ if (((String)session.getAttribute(SUBMITFORM_NOTE_KEY))!=null) {
+ if (((String)session.getAttribute(SUBMITFORM_NOTE_KEY)).equals("on")) {
+ noteEnabled = true;
+ }
+ }
+
+ sig_type = (String)session.getAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY);
+ sig_app = sig_app_fi.getString("UTF-8");
+
+ mode = (String)session.getAttribute(SUBMITFORM_SIGNATURE_MODE_KEY);
+ doc_file_name = (String)session.getAttribute(SUBMITFORM_FILENAME_KEY);
+ pdfDataSource = (DataSource)session.getAttribute(SUBMITFORM_FILE_KEY);
+
}
+ //end added
+ else {*/
- boolean pdfaEnabled = pdfa != null && "true".equalsIgnoreCase(pdfa.getString());
-
-
- boolean download_inline = true;
- if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT)) //$NON-NLS-1$
- {
- download_inline = false;
+ //Added by rpiazzi to check wheter local bku button was hit. In this case the parameters
+ //were already put into session because before local bku, online bku has to be called
+ //and therefore this servlet was already called.
+ //First check if one submitted parameter is the local bku button.
+ boolean localFound = false;
+ int positionLocal = 0;
+ while (it.hasNext()) {
+ if (((FileItem)it.next()).getFieldName().equals(FormFields.FIELD_CONNECTOR_LOCALBKU)) {
+ localFound = true;
+ break;
+ }
+ positionLocal++;
}
-
- String sig_type = sig_type_fi.getString("UTF-8"); //$NON-NLS-1$
- String sig_app = sig_app_fi.getString("UTF-8"); //$NON-NLS-1$
-
- DataSource pdfDataSource;
- String doc_file_name = "nofilename";
- // distinguish between file and freetext
- if (file_upload_fi != null) {
- log.debug("Processing file.");
- File f = new File(file_upload_fi.getName());
- doc_file_name = f.getName();
- log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
-
- String extension = VerifyServlet.extractExtension(doc_file_name);
- if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
- {
- throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- if (file_upload_fi.getSize() <= 0)
- {
- throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
- }
-
- try
- {
- pdfDataSource = new ByteArrayPdfDataSource(IOUtils.toByteArray(file_upload_fi.getInputStream()));
- }
- catch (IOException e)
- {
- throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
- }
- } else {
- log.debug("Processing free text.");
- try {
- byte[] freeTextPDF = IText.createPDF(freeText.getString("UTF-8"), pdfaEnabled);
-
- pdfDataSource = new ByteArrayPdfDataSource(freeTextPDF);
- doc_file_name = IText.DEFAULT_FILENAME;
- } catch (DocumentException e) {
- throw new PDFDocumentException(201, "Unable to create PDF document.", e);
- } catch (IOException e) {
- throw new PDFDocumentException(201, "Unable to create PDF document.", e);
- }
-
+
+ if (localFound) {
+ session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
+ pdfaEnabled = "on".equalsIgnoreCase((String)session.getAttribute(SUBMITFORM_PDFA_KEY));
+ sig_type = (String)session.getAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY);
+ noteEnabled = "on".equalsIgnoreCase((String)session.getAttribute(SUBMITFORM_NOTE_KEY));
+
+ session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, "bku");
+ sig_app = "bku";
+ session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "no");
+
+
+ mode = (String)session.getAttribute(SUBMITFORM_SIGNATURE_MODE_KEY);
+ doc_file_name = (String)session.getAttribute(SUBMITFORM_FILENAME_KEY);
+ pdfDataSource = (DataSource)session.getAttribute(SUBMITFORM_FILE_KEY);
+ }
+ //end added
+ //else get settings from form fields
+ else {
+ session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, "yes");
+ it = items.iterator();
+ while (it.hasNext())
+ {
+ FileItem item = (FileItem) it.next();
+ log.debug("item = " + item.getFieldName()); //$NON-NLS-1$
+
+ if (log.isDebugEnabled())
+ {
+ if (item.isFormField())
+ {
+ String item_string = item.getString("UTF-8"); //$NON-NLS-1$
+ log.debug(" form field string = " + item_string); //$NON-NLS-1$
+ }
+ else
+ {
+ log.debug(" filename = " + item.getName()); //$NON-NLS-1$
+ log.debug(" filesize = " + item.getSize()); //$NON-NLS-1$
+ }
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_SIGNATURE_TYPE))
+ {
+ sig_type_fi = item;
+ session.setAttribute(SUBMITFORM_SIGNATURE_TYPE_KEY, item.getString("UTF-8"));
+ sig_type=item.getString("UTF-8");
+ continue;
+ }
+
+ if ((item.getFieldName().equals(FormFields.FIELD_CONNECTOR_SMARTCARD)) || (item.getFieldName().equals(FormFields.FIELD_CONNECTOR_MOBILE))) {
+ if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR_SMARTCARD)) {
+ session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, "moc");
+ sig_app = "moc";
+ }
+ if (item.getFieldName().equals(FormFields.FIELD_CONNECTOR_MOBILE)) {
+ session.setAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY, "mobile");
+ sig_app = "mobile";
+ }
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_MODE))
+ {
+ mode_fi = item;
+ session.setAttribute(SUBMITFORM_SIGNATURE_MODE_KEY, mode_fi.getString("UTF-8"));
+ continue;
+ }
+
+ if (item.getFieldName().equals(FormFields.FIELD_SOURCE_FILE))
+ {
+ //changed by rpiazzi
+ //Item always contains something as it is just hidden by javascript
+ // because of this just set the value if not empty
+ if (item!=null) {
+ file_upload_fi = item;
+ }
+ continue;
+
+ }
+
+ //Added by rpiazzi to ignore the form fields for the inactive mode
+ //but not more needed
+ /*if (item.getFieldName().equals(FormFields.FIELD_MODE_INACTIVE)) {
+ continue;
+ }*/
+ //end added
+
+ /*Commented out by rpiazzi because not more needed
+ * if (item.getFieldName().equals(FormFields.FIELD_DOWNLOAD))
+ {
+ download_fi = item;
+ continue;
+ }*/
+
+ if (FormFields.FIELD_PDFA_ENABLED.equals(item.getFieldName())) {
+ if (item.getString("UTF-8")!=null) {
+ session.setAttribute(SUBMITFORM_PDFA_KEY, "on");
+ pdfaEnabled=true;
+ }
+ else {
+ session.setAttribute(SUBMITFORM_PDFA_KEY, "off");
+ pdfaEnabled=false;
+ }
+ continue;
+ }
+
+ if (FormFields.FIELD_SOURCE_FREETEXT.equals(item.getFieldName())) {
+ freeText_fi = item;
+ String value = freeText_fi.getString("UTF-8");
+ if (value != null) {
+ session.setAttribute(SUBMITFORM_FREETEXT_KEY, value);
+ }
+ continue;
+ }
+
+ if (FormFields.FIELD_SOURCE.equals(item.getFieldName())) {
+ source_fi = item;
+ session.setAttribute(SUBMITFORM_SOURCE_KEY, item.getString("UTF-8"));
+ continue;
+ }
+
+ //Added by rpiazzi. Feature added for inserting note into signature block
+ if (FormFields.FIELD_NOTE_ENABLED.equals(item.getFieldName())) {
+ if (item.getString("UTF-8")!=null) {
+ session.setAttribute(SUBMITFORM_NOTE_KEY, "on");
+ noteEnabled=true;
+ }
+ else {
+ session.setAttribute(SUBMITFORM_NOTE_KEY, "off");
+ noteEnabled=false;
+ }
+ continue;
+ }
+ //end added
+
+ //Added by rpiazzi to let later jsp's know the height of the div elements
+ if (FormFields.FIELD_HEIGHT_SIGNDIV.equals(item.getFieldName())) {
+ session.setAttribute(HEIGHT_SIGN_DIV, item.getString("UTF-8"));
+ continue;
+ }
+ //end added
+
+ throw new ServletException("Unrecognized POST data."); //$NON-NLS-1$
+
+ }
+
+ if (sig_type_fi == null || (file_upload_fi == null && freeText_fi== null))
+ {
+ throw new ServletException("Insufficient data provided in request"); //$NON-NLS-1$
+ }
+
+ mode = mode_fi.getString("UTF-8"); //$NON-NLS-1$
+ if (!mode.equals(FormFields.VALUE_MODE_BINARY) && !mode.equals(FormFields.VALUE_MODE_TEXTUAL) && !mode.equals(FormFields.VALUE_MODE_DETACHED))
+ {
+ throw new ServletException("The mode '" + mode + "' is unrecognized."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ //Commented out by rpiazzi because not more needed
+ /*boolean download_inline = true;
+ if (download_fi.getString("UTF-8").equals(FormFields.VALUE_DOWNLOAD_ATTACHMENT)) //$NON-NLS-1$
+ {
+ download_inline = false;
+ }*/
+
+
+ // distinguish between file and freetext
+ if (source_fi.getString("UTF-8").equals(FormFields.VALUE_SOURCE_FILE)) {
+ log.debug("Processing file.");
+ File f = new File(file_upload_fi.getName());
+ doc_file_name = f.getName();
+ log.debug("file content type =" + file_upload_fi.getContentType()); //$NON-NLS-1$
+
+ String extension = VerifyServlet.extractExtension(doc_file_name);
+ if (extension != null && !extension.equals("pdf")) //$NON-NLS-1$
+ {
+ throw new PDFDocumentException(201, "The provided file '" + doc_file_name + "' doesn't have the PDF extension (.pdf)."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ if (file_upload_fi.getSize() <= 0)
+ {
+ throw new PDFDocumentException(250, "The document is empty."); //$NON-NLS-1$
+ }
+
+ try
+ {
+ pdfDataSource = new ByteArrayPdfDataSource(IOUtils.toByteArray(file_upload_fi.getInputStream()));
+ session.setAttribute(SUBMITFORM_FILE_KEY, pdfDataSource);
+ session.setAttribute(SUBMITFORM_FILENAME_KEY, doc_file_name);
+ }
+ catch (IOException e)
+ {
+ throw new PDFDocumentException(201, "Couldn't store the file in the temp dir.", e);
+ }
+ } else {
+ log.debug("Processing free text.");
+ try {
+ byte[] freeTextPDF = IText.createPDF(freeText_fi.getString("UTF-8"), pdfaEnabled);
+ pdfDataSource = new ByteArrayPdfDataSource(freeTextPDF);
+ doc_file_name = IText.DEFAULT_FILENAME;
+ session.setAttribute(SUBMITFORM_FILE_KEY, pdfDataSource);
+ session.setAttribute(SUBMITFORM_FILENAME_KEY, doc_file_name);
+ } catch (DocumentException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ } catch (IOException e) {
+ throw new PDFDocumentException(201, "Unable to create PDF document.", e);
+ }
+
+ }
+ // byte[] pdf = file_upload_fi.get();
+ //}
}
- // byte[] pdf = file_upload_fi.get();
+
+
+
+
+
UploadedData ud = new UploadedData();
- ud.preview = preview;
+ ud.preview = false;
ud.pdfa = pdfaEnabled;
- ud.download_inline = download_inline;
+ ud.download_inline = false;
ud.sig_type = sig_type;
ud.sig_app = sig_app;
ud.sig_mode = mode;
ud.file_name = doc_file_name;
ud.pdfDataSource = pdfDataSource;
+ ud.note = noteEnabled;
return ud;
}
@@ -511,6 +723,19 @@ public class SignServlet extends HttpServlet
request.setAttribute("cause", "Der Platzhalter des Feldes " + phe.getField() + " ist um " + phe.getMissing() + " Bytes zu kurz. " + cause);
}
+
+ //Added by rpiazzi to know if error happened when request was within iframe
+ //In this case the visualization of the error has to be done differently
+ HttpSession session = request.getSession();
+ if (((String)session.getAttribute(SUBMITFORM_SIGNATURE_DEVICE_KEY)).equals(Constants.SIGNATURE_DEVICE_BKU)) {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "no");
+ }
+ else {
+ request.setAttribute(ERROR_WITHIN_IFRAME, "yes");
+ }
+ //end added
+
+
// }
// else
// {
@@ -519,19 +744,7 @@ public class SignServlet extends HttpServlet
// }
}
- public void dispatchToPreview(String document_text, String connector, String mode, String signature_type, String submit_url, HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException
- {
- request.setAttribute("document_text", document_text);
- request.setAttribute("connector", connector);
- request.setAttribute("mode", mode);
- request.setAttribute("signature_type", signature_type);
- request.setAttribute("submit_url", submit_url);
-
- dispatch(request, response, "/jsp/signpreview.jsp");
- }
-
- /**
+ /**
* Formats the file name so that it is suitable for content disposition.
*
* @param file_name
@@ -540,7 +753,7 @@ public class SignServlet extends HttpServlet
*/
public static String formatFileName(String file_name)
{
- File file = new File(file_name);
+ File file = new File(file_name);
String file_name_only = file.getName();
// the file_name contains \\ ==> remove them so Internet Explorer works
// correctly.
@@ -582,7 +795,7 @@ public class SignServlet extends HttpServlet
}
// end add
-
+
protected static class UploadedData
{
protected boolean preview = false;
@@ -600,6 +813,11 @@ public class SignServlet extends HttpServlet
protected String file_name = null;
protected DataSource pdfDataSource = null;
+
+ //added by rpiazzi
+ protected boolean note = false;
// protected byte[] pdf = null;
}
-} \ No newline at end of file
+
+}
+