aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java54
-rw-r--r--src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java22
-rw-r--r--src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java99
-rw-r--r--src/main/java/at/gv/egiz/pdfas/commandline/Main.java37
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java35
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java176
-rw-r--r--src/main/java/at/gv/egiz/pdfas/utils/StreamUtils.java1
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java1
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java2
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java66
10 files changed, 451 insertions, 42 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java b/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java
index bc6f89d..6ec16f1 100644
--- a/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java
+++ b/src/main/java/at/gv/egiz/pdfas/PdfAsFactory.java
@@ -8,6 +8,7 @@ import java.io.File;
import at.gv.egiz.pdfas.api.PdfAs;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.impl.api.PdfAsObject;
+import at.knowcenter.wag.egov.egiz.PdfAS;
/**
* Main factory for creating a PDF-AS API Instance (PdfAs Interface).
@@ -18,22 +19,41 @@ import at.gv.egiz.pdfas.impl.api.PdfAsObject;
*/
public class PdfAsFactory
{
- /**
- * Creates a PDF-AS API instance for the given work directory.
- *
- * @param workDirectory
- * The work directory.
- *
- * @return Returns an instance of the PDF-AS API.
- * @throws IllegalArgumentException
- * Thrown, if the workDirectory doesn't exist.
- * @throws PdfAsException
- * Thrown, if the work directory does not meet its requirements, or
- * if the config file is invalid.
- */
- public static PdfAs createPdfAs(File workDirectory) throws PdfAsException
- {
- return new PdfAsObject(workDirectory);
- }
+ /**
+ * Creates a PDF-AS API instance for the given work directory.
+ *
+ * @param workDirectory
+ * The work directory. If <code>null</code> the configuration is assumed to be located
+ * within the user's home directory.
+ *
+ * @return Returns an instance of the PDF-AS API.
+ * @throws IllegalArgumentException
+ * Thrown, if the workDirectory doesn't exist.
+ * @throws PdfAsException
+ * Thrown, if the work directory does not meet its requirements, or
+ * if the config file is invalid.
+ * @see PdfAS#USERHOME_CONFIG_FOLDER
+ */
+ public static PdfAs createPdfAs(File workDirectory) throws PdfAsException
+ {
+ return new PdfAsObject(workDirectory);
+ }
+
+ /**
+ * Creates a PDF-AS API instance assuming that the configuration is located within the user's
+ * home directory.
+ *
+ * @return Returns an instance of the PDF-AS API.
+ * @throws IllegalArgumentException
+ * Thrown, if the work directory doesn't exist within the user's home directory.
+ * @throws PdfAsException
+ * Thrown, if the work directory does not meet its requirements, or
+ * if the config file is invalid.
+ * @see PdfAS#USERHOME_CONFIG_FOLDER
+ */
+ public static PdfAs createPdfAs() throws PdfAsException
+ {
+ return createPdfAs(null);
+ }
}
diff --git a/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java b/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java
index e8ebc16..33a418e 100644
--- a/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java
+++ b/src/main/java/at/gv/egiz/pdfas/api/commons/Constants.java
@@ -74,4 +74,26 @@ public final class Constants
* All signatures are verified.
*/
public static int VERIFY_ALL = -1;
+
+ /**
+ * The system property that may be used to declare the pdf-as configuration folder.
+ */
+ public final static String CONFIG_SYSTEM_PROPERTY = "pdf-as.work-dir";
+
+ /**
+ * The zip file containing the default configuration.
+ */
+ public final static String DEFAULT_CONFIGURATION_ZIP_RESOURCE = "DefaultConfiguration.zip";
+
+ /**
+ * The configuration folder for pdf-as within the user's home folder.
+ */
+ public static final String USERHOME_CONFIG_FOLDER = "PDF-AS";
+
+ /**
+ * The name of the directory, where temporary files are stored.
+ */
+ public final static String TEMP_DIR_NAME = "pdfastmp";
+
}
+
diff --git a/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java b/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java
new file mode 100644
index 0000000..d4feedd
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/api/exceptions/ConfigUtilsException.java
@@ -0,0 +1,99 @@
+package at.gv.egiz.pdfas.api.exceptions;
+
+/**
+ * @author <a href="mailto:thomas.knall@egiz.gv.at">Thomas Knall</a>
+ */
+public class ConfigUtilsException extends Exception {
+
+ /**
+ * Marker for serialization.
+ */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The underlying exception.
+ */
+ private Exception wrappedException;
+
+ /**
+ * Returns the underlying exception.
+ *
+ * @return The underlying exception.
+ */
+ public Exception getException() {
+ return this.wrappedException;
+ }
+
+ /**
+ * Returns the message of the wrapped exception.
+ *
+ * @return The message of the wrapped exception.
+ */
+ public String getMessage() {
+ String message = super.getMessage();
+ if (message == null && this.wrappedException != null) {
+ return this.wrappedException.getMessage();
+ } else {
+ return message;
+ }
+ }
+
+ /**
+ * Instantiation of a new exception based on a message and another (wrapped)
+ * exception.
+ *
+ * @param message
+ * The exception message.
+ * @param exception
+ * Another exception.
+ */
+ public ConfigUtilsException(final String message, final Exception exception) {
+ super(message);
+ this.wrappedException = exception;
+ }
+
+ /**
+ * Instantiated a new exception based on a message.
+ *
+ * @param message
+ * The message of the new exception.
+ */
+ public ConfigUtilsException(final String message) {
+ super(message);
+ this.wrappedException = null;
+ }
+
+ /**
+ * Instantiates a new exception based on another (wrapped) exception.
+ *
+ * @param exception
+ * The wrapped exception.
+ */
+ public ConfigUtilsException(final Exception exception) {
+ super();
+ this.wrappedException = exception;
+ }
+
+ /**
+ * Instantiates a new (unspecified) exception.
+ */
+ public ConfigUtilsException() {
+ super();
+ this.wrappedException = null;
+
+ }
+
+ /**
+ * Returns the text representation of this instance.
+ *
+ * @return The text representation of this instance.
+ */
+ public String toString() {
+ if (this.wrappedException != null) {
+ return this.wrappedException.toString();
+ } else {
+ return super.toString();
+ }
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
index b4546e4..0ec6a55 100644
--- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
+++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
@@ -33,6 +33,7 @@ import org.apache.log4j.PropertyConfigurator;
import at.gv.egiz.pdfas.PdfAsFactory;
import at.gv.egiz.pdfas.api.PdfAs;
import at.gv.egiz.pdfas.api.commons.Constants;
+import at.gv.egiz.pdfas.api.exceptions.ConfigUtilsException;
import at.gv.egiz.pdfas.api.exceptions.PdfAsException;
import at.gv.egiz.pdfas.api.io.DataSink;
import at.gv.egiz.pdfas.api.io.DataSource;
@@ -46,18 +47,17 @@ import at.gv.egiz.pdfas.api.verify.VerifyResult;
import at.gv.egiz.pdfas.api.verify.VerifyResults;
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.config.SettingsHelper;
import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
import at.gv.egiz.pdfas.io.FileBasedDataSink;
import at.gv.egiz.pdfas.io.FileBasedDataSource;
import at.gv.egiz.pdfas.io.StringTextBasedDataSource;
+import at.gv.egiz.pdfas.utils.ConfigUtils;
import at.knowcenter.wag.egov.egiz.PdfAS;
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.PDFDocumentException;
-import at.knowcenter.wag.egov.egiz.exceptions.PlaceholderException;
import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingNotFoundException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureTypesException;
@@ -119,6 +119,13 @@ public abstract class Main
* verified.
*/
protected static final String PARAMETER_VERIFY_WHICH = "-verify_which";
+
+ /**
+ * Command line parameter that starts the deployment of the default configuration to the current
+ * user's home folder.
+ * @see Constants#USERHOME_CONFIG_FOLDER
+ */
+ protected static final String PARAMETER_DEPLOY_DEFAULT_CONFIGURATION = "-ddc";
/**
* The application mode sign
@@ -166,6 +173,23 @@ public abstract class Main
{
// ConfigLogger.setLevel(Level.DEBUG);
+ // search for PARAMETER_DEPLOY_DEFAULT_CONFIGURATION before initializing the SettingsReader
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].trim().equals(PARAMETER_DEPLOY_DEFAULT_CONFIGURATION)) {
+ try {
+ if (ConfigUtils.deployDefaultConfiguration()) {
+ System.out.println("Default configuration successfully deployed to the current user's home.");
+ } else {
+ System.out.println("Default configuration NOT deployed because to the current user's home because it already exists.");
+ }
+ System.exit(0);
+ } catch (ConfigUtilsException e) {
+ System.err.println("Deployment of default configuration failed: " + e.getMessage());
+ System.exit(1);
+ }
+ }
+ }
+
SettingsReader.initializeForCommandLine();
PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties");
@@ -417,7 +441,7 @@ public abstract class Main
logger_.error("Couldn't delete output file " + output);
}
}
- }
+ }
finally
{
SettingsReader.clearTemporaryDirectory();
@@ -807,7 +831,7 @@ public abstract class Main
*/
public static void printUsage(PrintStream writer) throws PresentableException
{
- writer.println("Usage: pdf-as [OPTIONS] <input file> [output file]");
+ writer.println("Usage: pdf-as [[OPTIONS] <input file> [output file]|UTILOPTIONS]");
writer.println(" Required OPTIONS:");
writer.println(" " + PARAMETER_MODE + " <" + VALUE_MODE_SIGN + "|" + VALUE_MODE_VERIFY + ">");
@@ -840,6 +864,10 @@ public abstract class Main
writer.println(" " + id + " ... " + ci[i].getDescription());
}
+ writer.println(" Resp. required UTILity OPTIONS");
+
+ writer.println(" " + PARAMETER_DEPLOY_DEFAULT_CONFIGURATION + " ... deploys the default configuration to the current user's home");
+
writer.println(" OPTIONS for signation:");
writer.println(" " + PARAMETER_SIGNATURE_MODE + " <" + VALUE_SIGNATURE_MODE_BINARY + "|" + VALUE_SIGNATURE_MODE_TEXTUAL + ">");
@@ -901,6 +929,7 @@ public abstract class Main
writer.println(" Example usage:");
writer.println(" pdf-as " + PARAMETER_MODE + " " + VALUE_MODE_SIGN + " " + PARAMETER_CONNECTOR + " moa some_document.pdf");
writer.println(" pdf-as " + PARAMETER_MODE + " " + VALUE_MODE_VERIFY + " some_document.pdf_out.pdf");
+ writer.println(" pdf-as " + PARAMETER_DEPLOY_DEFAULT_CONFIGURATION);
}
/**
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
index b744d2a..303d48f 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/api/PdfAsObject.java
@@ -29,6 +29,7 @@ import at.gv.egiz.pdfas.api.verify.VerifyResult;
import at.gv.egiz.pdfas.api.verify.VerifyResults;
import at.gv.egiz.pdfas.commandline.CommandlineConnectorChooser;
import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.gv.egiz.pdfas.framework.ConnectorFactory;
import at.gv.egiz.pdfas.framework.config.SettingsHelper;
import at.gv.egiz.pdfas.framework.input.ExtractionStage;
import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
@@ -65,10 +66,6 @@ import at.knowcenter.wag.egov.egiz.sig.SignatureTypes;
*/
public class PdfAsObject implements PdfAs
{
- /**
- * The work directory.
- */
- protected File workDirectory = null;
/**
* The log.
@@ -86,21 +83,23 @@ public class PdfAsObject implements PdfAs
*/
public PdfAsObject(File workDirectory) throws PdfAsException
{
- if (workDirectory == null)
- {
- throw new IllegalArgumentException("The work directory must not be null.");
- }
- if (!workDirectory.isDirectory())
- {
- throw new IllegalArgumentException("The work directory does not exist or is not a directory. " + workDirectory.getPath());
- }
-
- this.workDirectory = workDirectory;
-
- SettingsReader.initialize(workDirectory.getPath());
+ String path = workDirectory != null ? workDirectory.getPath() : null;
+ SettingsReader.initialize(path, path);
reloadConfig();
}
-
+
+ /**
+ * This constructor is for internal use only - use
+ * {@link at.gv.egiz.pdfas.PdfAsFactory} instead.
+ *
+ * @throws PdfAsException
+ * Thrown, if the configuration cannot be processed.
+ */
+ public PdfAsObject() throws PdfAsException
+ {
+ this(null);
+ }
+
/**
* @see at.gv.egiz.pdfas.api.PdfAs#reloadConfig()
*/
@@ -235,7 +234,7 @@ public class PdfAsObject implements PdfAs
TablePos pos = PosHelper.formTablePos(signParameters.getSignaturePositioning());
String connectorId = CommandlineConnectorChooser.chooseCommandlineConnectorForSign(signParameters.getSignatureDevice());
-
+
SignatorInformation si = PdfAS
.signCommandline(new PdfDataSourceAdapter(signParameters.getDocument()), new DataSinkAdapter(signParameters.getOutput()), signatorId, connectorId, signParameters.getSignatureProfileId(), pos);
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
new file mode 100644
index 0000000..c98cb59
--- /dev/null
+++ b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java
@@ -0,0 +1,176 @@
+package at.gv.egiz.pdfas.utils;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+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.ConfigUtilsException;
+
+/**
+ * @author <a href="mailto:thomas.knall@egiz.gv.at">Thomas Knall</a>
+ */
+public final class ConfigUtils {
+
+ private ConfigUtils() {
+ }
+
+ /**
+ * The log.
+ */
+ private static final Log logger_ = LogFactory.getLog(ConfigUtils.class);
+
+ /**
+ * Deploys the default configuration with apache commons vfs.
+ *
+ * @param destination The destination folder.
+ * @param overwriteExisting If set <code>true</code> an already existing configuration is overwritten. If <code>false</code> nothing is being copied if the destination folder already exists.
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ */
+ /*
+ private static boolean deployWithCommonsVFS(String destination, boolean overwriteExisting) throws ConfigUtilsException {
+ try {
+ FileSystemManager fsManager = VFS.getManager();
+ FileObject defaultConfigurationFile = fsManager.resolveFile("res:DefaultConfiguration");
+ FileObject destinationFile = fsManager.resolveFile(destination);
+
+ if (destinationFile.exists() && !overwriteExisting) {
+ return false;
+ }
+
+ destinationFile.copyFrom(defaultConfigurationFile, new AllFileSelector());
+ return true;
+ } catch (FileSystemException e) {
+ throw new ConfigUtilsException(e);
+ }
+ }
+ */
+
+
+ /**
+ * Deploys the default configuration from an included zip file.
+ *
+ * @param destination The destination folder.
+ * @param overwriteExisting If set <code>true</code> an already existing configuration is overwritten. If <code>false</code> nothing is being copied if the destination folder already exists.
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ */
+ private static boolean deployFromZIP(String destination, boolean overwriteExisting) throws ConfigUtilsException {
+ try {
+ File destinationFolder = new File(destination);
+ if (destinationFolder.exists() && !overwriteExisting) {
+ return false;
+ }
+ InputStream in = ConfigUtils.class.getClassLoader().getResourceAsStream(Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE);
+ if (in == null) {
+ throw new ConfigUtilsException("Unable to find default configuration resource \"" + Constants.DEFAULT_CONFIGURATION_ZIP_RESOURCE + "\".");
+ }
+ ZipInputStream zis = new ZipInputStream(in);
+ ZipEntry ze;
+ destinationFolder.mkdirs();
+ logger_.debug("Extracting default configuration to folder \"" + destinationFolder.getCanonicalPath() + "\".");
+ while ((ze = zis.getNextEntry()) != null) {
+ if (ze.isDirectory()) {
+ File newFolder = new File(destinationFolder, ze.getName());
+ logger_.debug("Extracting folder \"" + newFolder.getPath() + "\".");
+ newFolder.mkdirs();
+ } else {
+ File destFile = new File(destinationFolder, ze.getName());
+ logger_.trace("Extracting file \"" + destFile.getName() + "\".");
+ toFile(zis, destFile);
+ }
+ zis.closeEntry();
+ }
+ zis.close();
+ return true;
+ } catch (IOException e) {
+ throw new ConfigUtilsException(e);
+ }
+ }
+
+ /**
+ * Deploys the default configuration to the given destination folder.
+ *
+ * @param destination The destination folder.
+ * @param overwriteExisting If set <code>true</code> an already existing configuration is overwritten. If <code>false</code> nothing is being copied if the destination folder already exists.
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ */
+ public static boolean deployDefaultConfiguration(String destination, boolean overwriteExisting) throws ConfigUtilsException {
+ if (destination == null) {
+ throw new NullPointerException("Destination must not be null.");
+ }
+ if (destination.length() == 0) {
+ throw new IllegalArgumentException("Destination must not be empty.");
+ }
+ return deployFromZIP(destination, overwriteExisting);
+ }
+
+ /**
+ * Deploys the default configuration to the user's home directory to the subdirectory specified by
+ * <code>Constants.Constants.USERHOME_CONFIG_FOLDER</code>.
+ *
+ * @param overwriteExisting If set <code>true</code> an already existing configuration is overwritten. If <code>false</code> nothing is being copied if the destination folder already exists.
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ * @see Constants#USERHOME_CONFIG_FOLDER
+ */
+ public static boolean deployDefaultConfiguration(boolean overwriteExisting) throws ConfigUtilsException {
+ String userHome = System.getProperty("user.home");
+ if (userHome == null || userHome.length() == 0) {
+ return false;
+ }
+ return deployDefaultConfiguration(userHome + File.separator + Constants.USERHOME_CONFIG_FOLDER, overwriteExisting);
+ }
+
+ /**
+ * Deploys the default configuration to the user's home directory to the subdirectory specified by
+ * <code>Constants.Constants.USERHOME_CONFIG_FOLDER</code>.
+ *
+ * @return <code>true</code> if the configuration has been deployed, <code>false</code> if not.
+ * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration.
+ * @see Constants#USERHOME_CONFIG_FOLDER
+ */
+ public static boolean deployDefaultConfiguration() throws ConfigUtilsException {
+ return deployDefaultConfiguration(false);
+ }
+
+ public static boolean toFile(InputStream inputStream, File file) throws IOException {
+ boolean result = false;
+ BufferedOutputStream bufferedOutputStream = null;
+ try {
+ bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+ writeInputStreamToOutputStream(inputStream, bufferedOutputStream);
+ } finally {
+ if (bufferedOutputStream != null) {
+ try {
+ bufferedOutputStream.close();
+ result = true;
+ } catch (IOException e) {
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
+
+ public static void writeInputStreamToOutputStream(InputStream inputStream, OutputStream outputStream) throws IOException {
+ final int bufferSize = 1024;
+ byte[] buffer = new byte[bufferSize];
+ int len = -1;
+ while ((len = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, len);
+ }
+ outputStream.flush();
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/utils/StreamUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/StreamUtils.java
index acf7e75..44303b0 100644
--- a/src/main/java/at/gv/egiz/pdfas/utils/StreamUtils.java
+++ b/src/main/java/at/gv/egiz/pdfas/utils/StreamUtils.java
@@ -16,6 +16,7 @@ public class StreamUtils
{
os.write(buffer, 0, read);
}
+ os.flush();
is.close();
os.close();
}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
index 5752838..93c0aa2 100644
--- a/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
+++ b/src/main/java/at/gv/egiz/pdfas/web/helper/SessionHelper.java
@@ -3,7 +3,6 @@
*/
package at.gv.egiz.pdfas.web.helper;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java
index 5dbc8b6..341b97c 100644
--- a/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java
+++ b/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java
@@ -129,7 +129,7 @@ public class SignServletHelper
// TODO TR: Web-Applikation verwendet in Loc-Ref-Variante ext. Referenz, um performanter zu sein;
// nachfolend auskommentieren, wenn anstatt SwA-Connector LocRef-Connector verwendet wird
- URL signature_data_URL = new URL(request.getScheme(), host, request.getServerPort(), request.getContextPath() + "/RetrieveSignatureData");
+ URL signature_data_URL = new URL(LocalRequestHelper.getLocalContextAddress(request, response) + "/RetrieveSignatureData");
String signature_data_url = response.encodeURL(signature_data_URL.toString());
Connector c = ConnectorChooser.chooseWebConnectorForSign(si.connector, si.type, signature_data_url);
diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java
index e3f10ed..e7ce3ac 100644
--- a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java
+++ b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java
@@ -48,6 +48,69 @@ public class TempDirHelper
protected static long runningIndex = 0;
+ /**
+ * Assembles the File of the temporary directory without checking if it really
+ * exists.
+ */
+ public static File assembleTemporaryDirectoryFile()
+ {
+ File temp_dir = new File(SettingsReader.TMP_PATH);
+ return temp_dir;
+ }
+
+ /**
+ * Returns the directory where temporary files should be stored.
+ *
+ * <p>
+ * If the directory doesn't exist, it is created.
+ * </p>
+ *
+ * @return Returns the directory where temporary files should be stored.
+ */
+ public static File getTemporaryDirectory()
+ {
+ File temp_dir = assembleTemporaryDirectoryFile();
+ if (!temp_dir.exists())
+ {
+ temp_dir.mkdirs();
+ }
+ return temp_dir;
+ }
+
+ /**
+ * Deletes all files in the temporary directory, if it exists.
+ *
+ * <p>
+ * This should be used to clear temporary files when the application shuts
+ * down.
+ * </p>
+ */
+ public static void clearTemporaryDirectory()
+ {
+ File temp_dir = assembleTemporaryDirectoryFile();
+ log.debug("Clearing temporary directory: " + temp_dir);
+
+ if (!temp_dir.exists())
+ {
+ return;
+ }
+
+ File[] files = temp_dir.listFiles();
+ for (int i = 0; i < files.length; i++)
+ {
+ // added by tknall: do not try to remove svn-metadata
+ if (files[i].getName().endsWith(".svn")) {
+ continue;
+ }
+ log.debug(" Clearing temporary file: " + files[i]);
+ boolean delete_success = files[i].delete();
+ if (!delete_success)
+ {
+ log.error("Couldn't delete the temporary file: " + files[i]);
+ }
+ }
+ }
+
public static void storeTextSignatureHoldersIfApplicable(List shs, String fileNameSuffix) throws IOException
{
Iterator it = shs.iterator();
@@ -166,7 +229,8 @@ public class TempDirHelper
protected static File getFileInTempDir (String fileName)
{
- File tempDir = new File(new File(SettingsReader.RESOURCES_PATH), "pdfastmp");
+// File tempDir = new File(new File(SettingsReader.RESOURCES_PATH), "pdfastmp");
+ File tempDir = assembleTemporaryDirectoryFile();
File tmpFile = new File(tempDir, fileName);