From 1eac16f95618fc4bc1e90b5d44cc94252647f136 Mon Sep 17 00:00:00 2001 From: tknall Date: Tue, 10 Jun 2008 10:47:02 +0000 Subject: Manual deployment of pdf-as configuration (commandline parameter -ddc) considers the system property pdf-as.work-dir. Internal default configuration updated. log4.properties within the workdir is now being considered using the api. git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@280 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/api/commons/Constants.java | 2 +- .../java/at/gv/egiz/pdfas/commandline/Main.java | 7 +++--- .../at/gv/egiz/pdfas/impl/api/PdfAsObject.java | 2 ++ .../java/at/gv/egiz/pdfas/utils/ConfigUtils.java | 28 +++++++++++++--------- 4 files changed, 24 insertions(+), 15 deletions(-) (limited to 'src/main/java/at/gv/egiz') 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 33a418e..f9a3c03 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 @@ -78,7 +78,7 @@ public final class Constants /** * 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"; + public final static String CONFIG_DIR_SYSTEM_PROPERTY = "pdf-as.work-dir"; /** * The zip file containing the default configuration. 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 0ec6a55..dea19b6 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java @@ -177,10 +177,11 @@ public abstract class Main 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."); + String defaultConfigurationDeployedTo = ConfigUtils.deployDefaultConfiguration(); + if (defaultConfigurationDeployedTo != null) { + System.out.println("Default configuration successfully deployed to \"" + defaultConfigurationDeployedTo + "\"."); } else { - System.out.println("Default configuration NOT deployed because to the current user's home because it already exists."); + System.out.println("Default configuration has NOT been deployed. Maybe the configuration already exists."); } System.exit(0); } catch (ConfigUtilsException e) { 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 303d48f..0450a50 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 @@ -14,6 +14,7 @@ import java.util.Vector; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.log4j.PropertyConfigurator; import at.gv.egiz.pdfas.api.PdfAs; import at.gv.egiz.pdfas.api.analyze.AnalyzeParameters; @@ -105,6 +106,7 @@ public class PdfAsObject implements PdfAs */ public void reloadConfig() throws PdfAsException { + PropertyConfigurator.configure(SettingsReader.CONFIG_PATH + "log4j.properties"); SettingsReader.createInstance(); SignatureTypes.createInstance(); } diff --git a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java index c98cb59..0e606d7 100644 --- a/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java +++ b/src/main/java/at/gv/egiz/pdfas/utils/ConfigUtils.java @@ -102,17 +102,17 @@ public final class ConfigUtils { * * @param destination The destination folder. * @param overwriteExisting If set true an already existing configuration is overwritten. If false nothing is being copied if the destination folder already exists. - * @return true if the configuration has been deployed, false if not. + * @return The folder the configuration has been extracted to or null if the configuration has NOT been deployed. * @throws ConfigUtilsException Thrown if there was an error during the deployment of the configuration. */ - public static boolean deployDefaultConfiguration(String destination, boolean overwriteExisting) throws ConfigUtilsException { + public static String 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); + return deployFromZIP(destination, overwriteExisting) ? destination : null; } /** @@ -120,27 +120,33 @@ public final class ConfigUtils { * Constants.Constants.USERHOME_CONFIG_FOLDER. * * @param overwriteExisting If set true an already existing configuration is overwritten. If false nothing is being copied if the destination folder already exists. - * @return true if the configuration has been deployed, false if not. + * @return The folder the configuration has been extracted to or null if the configuration has NOT been deployed. * @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; + public static String deployDefaultConfiguration(boolean overwriteExisting) throws ConfigUtilsException { + String configdir = System.getProperty(Constants.CONFIG_DIR_SYSTEM_PROPERTY); + if (configdir == null) { + configdir = System.getProperty("user.home"); + if (configdir != null) { + configdir = configdir + File.separator + Constants.USERHOME_CONFIG_FOLDER; + } } - return deployDefaultConfiguration(userHome + File.separator + Constants.USERHOME_CONFIG_FOLDER, overwriteExisting); + if (configdir == null || configdir.length() == 0) { + return null; + } + return deployDefaultConfiguration(configdir, overwriteExisting); } /** * Deploys the default configuration to the user's home directory to the subdirectory specified by * Constants.Constants.USERHOME_CONFIG_FOLDER. * - * @return true if the configuration has been deployed, false if not. + * @return The folder the configuration has been extracted to or null if the configuration has NOT been deployed. * @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 { + public static String deployDefaultConfiguration() throws ConfigUtilsException { return deployDefaultConfiguration(false); } -- cgit v1.2.3