diff options
Diffstat (limited to 'netx/net/sourceforge/jnlp')
29 files changed, 1172 insertions, 210 deletions
diff --git a/netx/net/sourceforge/jnlp/Launcher.java b/netx/net/sourceforge/jnlp/Launcher.java index 2ca6304..4d80252 100644 --- a/netx/net/sourceforge/jnlp/Launcher.java +++ b/netx/net/sourceforge/jnlp/Launcher.java @@ -39,10 +39,10 @@ import java.util.jar.JarFile; import net.sourceforge.jnlp.cache.CacheUtil; import net.sourceforge.jnlp.cache.ResourceTracker; import net.sourceforge.jnlp.cache.UpdatePolicy; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.AppThreadGroup; import net.sourceforge.jnlp.runtime.AppletInstance; import net.sourceforge.jnlp.runtime.ApplicationInstance; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPClassLoader; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.services.InstanceExistsException; diff --git a/netx/net/sourceforge/jnlp/SecurityDesc.java b/netx/net/sourceforge/jnlp/SecurityDesc.java index c695bec..7613017 100644 --- a/netx/net/sourceforge/jnlp/SecurityDesc.java +++ b/netx/net/sourceforge/jnlp/SecurityDesc.java @@ -22,7 +22,7 @@ import java.util.*; import java.security.*; import java.awt.AWTPermission; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; /** diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java index e316282..59ead51 100644 --- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java +++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java @@ -27,6 +27,7 @@ import java.security.*; import javax.jnlp.*; import net.sourceforge.jnlp.*; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.*; import net.sourceforge.jnlp.util.FileUtils; diff --git a/netx/net/sourceforge/jnlp/config/BasicValueValidators.java b/netx/net/sourceforge/jnlp/config/BasicValueValidators.java new file mode 100644 index 0000000..1cb2af7 --- /dev/null +++ b/netx/net/sourceforge/jnlp/config/BasicValueValidators.java @@ -0,0 +1,268 @@ +/* BasicValueCheckers.java + Copyright (C) 2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +import java.net.URL; +import java.util.Arrays; +import java.util.Locale; + +/** + * Provides {@link ValueValidator} implementations for some common value types + * + * @see #getBooleanValidator() + * @see #getFilePathValidator() + * @see #getRangedIntegerValidator(int, int) + * @see #getStringValidator(String[]) + * @see #getUrlValidator() + */ +public class BasicValueValidators { + + /** + * Checks if a value is a valid boolean + */ + private static class BooleanValidator implements ValueValidator { + + @Override + public void validate(Object value) throws IllegalArgumentException { + Object possibleValue = value; + + if (possibleValue instanceof String) { + String lower = ((String) possibleValue).toLowerCase(Locale.ENGLISH); + if (lower.equals(Boolean.TRUE.toString()) + || (lower.equals(Boolean.FALSE.toString()))) { + possibleValue = Boolean.valueOf(lower); + } + } + + if (!(possibleValue instanceof Boolean)) { + throw new IllegalArgumentException(); + } + } + + @Override + public String getPossibleValues() { + return R("VVPossibleBooleanValues", Boolean.TRUE.toString(), Boolean.FALSE.toString()); + } + }; + + /** + * Checks if a value is a valid file path (not a valid file!). The actual + * file may or may not exist + */ + private static class FilePathValidator implements ValueValidator { + + @Override + public void validate(Object value) throws IllegalArgumentException { + if (value == null) { + return; + } + + Object possibleValue = value; + + if (!(possibleValue instanceof String)) { + throw new IllegalArgumentException(); + } + + String possibleFile = (String) possibleValue; + if (!(possibleFile.startsWith("/"))) { + throw new IllegalArgumentException(); + } + + } + + @Override + public String getPossibleValues() { + return R("VVPossibleFileValues"); + } + + } + + /** + * Checks that the value is an Integer or Long (or a String representation + * of one) that is within a desired range). + */ + private static class RangedIntegerValidator implements ValueValidator { + private int low = 0; + private int high = 0; + + public RangedIntegerValidator(int low, int high) { + this.low = low; + this.high = high; + } + + @Override + public void validate(Object value) throws IllegalArgumentException { + Object possibleValue = value; + + long actualValue = 0; + try { + if (possibleValue instanceof String) { + actualValue = Long.valueOf((String) possibleValue); + } else if (possibleValue instanceof Integer) { + actualValue = (Integer) possibleValue; + } else if (possibleValue instanceof Long) { + actualValue = (Long) possibleValue; + } else { + throw new IllegalArgumentException("Must be an integer"); + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Must be an integer"); + + } + + if (actualValue < low || actualValue > high) { + throw new IllegalArgumentException("Not in range from " + low + " to " + high); + } + } + + @Override + public String getPossibleValues() { + return R("VVPossibleRangedIntegerValues", low, high); + } + + }; + + /** + * Checks that the value is one of the acceptable String values + */ + private static class StringValueValidator implements ValueValidator { + String[] options = null; + + public StringValueValidator(String[] acceptableOptions) { + options = acceptableOptions; + } + + @Override + public void validate(Object value) throws IllegalArgumentException { + Object possibleValue = value; + if (!(possibleValue instanceof String)) { + throw new IllegalArgumentException("Must be a string"); + } + + String stringVal = (String) possibleValue; + boolean found = false; + for (String knownVal : options) { + if (knownVal.equals(stringVal)) { + found = true; + break; + } + } + + if (!found) { + throw new IllegalArgumentException(); + } + } + + @Override + public String getPossibleValues() { + return Arrays.toString(options); + } + + } + + /** + * Checks that the value is a URL + */ + private static class UrlValidator implements ValueValidator { + + @Override + public void validate(Object value) throws IllegalArgumentException { + if (value == null) { + return; + } + try { + new URL((String) value); + } catch (Exception e) { + throw new IllegalArgumentException(); + } + } + + @Override + public String getPossibleValues() { + return R("VVPossibleUrlValues"); + } + + } + + /** + * @return a {@link ValueValidator} that can be used to check if an object is + * a valid Boolean + */ + public static ValueValidator getBooleanValidator() { + return new BooleanValidator(); + } + + /** + * @return a {@link ValueValidator} that can be used to check if an object is + * a String containing a valid file path or not + */ + public static ValueValidator getFilePathValidator() { + return new FilePathValidator(); + } + + /** + * Returns a {@link ValueValidator} that checks if an object represents a + * valid integer (it is a Integer or Long or a String representation of + * one), within the given range. The values are inclusive. + * @param low the lowest valid value + * @param high the highest valid value + */ + public static ValueValidator getRangedIntegerValidator(int low, int high) { + return new RangedIntegerValidator(low, high); + } + + /** + * Returns a {@link ValueValidator} that checks if an object is a string from + * one of the provided Strings. + * @param validValues an array of Strings which are considered valid + */ + public static ValueValidator getStringValidator(String[] validValues) { + return new StringValueValidator(validValues); + } + + /** + * @return a {@link ValueValidator} that checks if an object represents a + * valid url + */ + public static ValueValidator getUrlValidator() { + return new UrlValidator(); + } + +} diff --git a/netx/net/sourceforge/jnlp/config/ConfiguratonValidator.java b/netx/net/sourceforge/jnlp/config/ConfiguratonValidator.java new file mode 100644 index 0000000..2ec4c5b --- /dev/null +++ b/netx/net/sourceforge/jnlp/config/ConfiguratonValidator.java @@ -0,0 +1,120 @@ +/* Validator.java + Copyright (C) 2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Validates a DeploymentConfiguration by identifying settings with + * unrecognized names or incorrect values. + */ +public class ConfiguratonValidator { + + private List<Setting<String>> incorrectEntries; + private List<Setting<String>> unrecognizedEntries; + private Map<String, Setting<String>> toValidate = null; + + private boolean validated = false; + + /** + * @param toValidate the settings to validate + */ + public ConfiguratonValidator(Map<String, Setting<String>> toValidate) { + this.toValidate = toValidate; + } + + /** + * Validates the settings used in the constructor. Use + * {@link #getIncorrectSetting()} and {@link #getUnrecognizedSetting()} to + * get the list of incorrect or unrecognized settings. + */ + public void validate() { + incorrectEntries = new ArrayList<Setting<String>>(); + unrecognizedEntries = new ArrayList<Setting<String>>(); + + Map<String, Setting<String>> knownGood = Defaults.getDefaults(); + + for (String key : toValidate.keySet()) { + // check for known incorrect settings + if (knownGood.containsKey(key)) { + Setting<String> good = knownGood.get(key); + Setting<String> unknown = toValidate.get(key); + ValueValidator checker = good.getValidator(); + if (checker != null) { + try { + checker.validate(unknown.getValue()); + } catch (IllegalArgumentException e) { + Setting<String> strange = new Setting<String>(unknown); + strange.setValue(unknown.getValue()); + incorrectEntries.add(strange); + } + } + } else { + // check for unknown settings + Setting<String> strange = new Setting<String>(toValidate.get(key)); + unrecognizedEntries.add(strange); + } + } + + validated = true; + } + + /** + * @return a list of settings which have incorrect values + */ + public List<Setting<String>> getIncorrectSetting() { + if (!validated) { + throw new IllegalStateException(); + } + + return new ArrayList<Setting<String>>(incorrectEntries); + } + + /** + * @return a list of settings which are not recognized + */ + public List<Setting<String>> getUnrecognizedSetting() { + if (!validated) { + throw new IllegalStateException(); + } + return new ArrayList<Setting<String>>(unrecognizedEntries); + } + +} diff --git a/netx/net/sourceforge/jnlp/config/Defaults.java b/netx/net/sourceforge/jnlp/config/Defaults.java new file mode 100644 index 0000000..78e203d --- /dev/null +++ b/netx/net/sourceforge/jnlp/config/Defaults.java @@ -0,0 +1,394 @@ +/* Defaults.java + Copyright (C) 2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import net.sourceforge.jnlp.ShortcutDesc; +import net.sourceforge.jnlp.runtime.JNLPProxySelector; + +/** + * This class stores the default configuration + */ +public class Defaults { + + /** + * Get the default settings for deployment + */ + public static Map<String, Setting<String>> getDefaults() { + File userFile = new File(System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_DIR + + File.separator + DeploymentConfiguration.DEPLOYMENT_PROPERTIES); + + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkRead(userFile.toString()); + } + + final String SYSTEM_HOME = System.getProperty("java.home"); + final String SYSTEM_SECURITY = SYSTEM_HOME + File.separator + "lib" + File.separator + "security"; + + final String USER_HOME = System.getProperty("user.home") + File.separator + DeploymentConfiguration.DEPLOYMENT_DIR; + final String USER_SECURITY = USER_HOME + File.separator + "security"; + + final String LOCKS_DIR = System.getProperty("java.io.tmpdir") + File.separator + + System.getProperty("user.name") + File.separator + "netx" + File.separator + + "locks"; + + /* + * This is more or less a straight copy from the deployment + * configuration page, with occasional replacements of "" or no-defaults + * with null + * + * The format of this is: + * name + * checker (can be null or a ValueChecker) + * value (can be null or a String) + */ + + Object[][] defaults = new Object[][] { + /* infrastructure */ + { + DeploymentConfiguration.KEY_USER_CACHE_DIR, + BasicValueValidators.getFilePathValidator(), + USER_HOME + File.separator + "cache" + }, + { + DeploymentConfiguration.KEY_USER_PERSISTENCE_CACHE_DIR, + BasicValueValidators.getFilePathValidator(), + USER_HOME + File.separator + "pcache" + }, + { + DeploymentConfiguration.KEY_SYSTEM_CACHE_DIR, + BasicValueValidators.getFilePathValidator(), + null + }, + { + DeploymentConfiguration.KEY_USER_LOG_DIR, + BasicValueValidators.getFilePathValidator(), + USER_HOME + File.separator + "log" + }, + { + DeploymentConfiguration.KEY_USER_TMP_DIR, + BasicValueValidators.getFilePathValidator(), + USER_HOME + File.separator + "tmp" + }, + { + DeploymentConfiguration.KEY_USER_LOCKS_DIR, + BasicValueValidators.getFilePathValidator(), + LOCKS_DIR + }, + { + DeploymentConfiguration.KEY_USER_NETX_RUNNING_FILE, + BasicValueValidators.getFilePathValidator(), + LOCKS_DIR + File.separator + "netx_running" + }, + /* certificates and policy files */ + { + DeploymentConfiguration.KEY_USER_SECURITY_POLICY, + BasicValueValidators.getUrlValidator(), + "file://" + USER_SECURITY + File.separator + "java.policy" + }, + { + DeploymentConfiguration.KEY_USER_TRUSTED_CA_CERTS, + BasicValueValidators.getFilePathValidator(), + USER_SECURITY + File.separator + "trusted.cacerts" + }, + { + DeploymentConfiguration.KEY_USER_TRUSTED_JSSE_CA_CERTS, + BasicValueValidators.getFilePathValidator(), + USER_SECURITY + File.separator + "trusted.jssecacerts" + }, + { + DeploymentConfiguration.KEY_USER_TRUSTED_CERTS, + BasicValueValidators.getFilePathValidator(), + USER_SECURITY + File.separator + "trusted.certs" + }, + { + DeploymentConfiguration.KEY_USER_TRUSTED_JSSE_CERTS, + BasicValueValidators.getFilePathValidator(), + USER_SECURITY + File.separator + "trusted.jssecerts" + }, + { + DeploymentConfiguration.KEY_USER_TRUSTED_CLIENT_CERTS, + BasicValueValidators.getFilePathValidator(), + USER_SECURITY + File.separator + "trusted.clientcerts" + }, + { + DeploymentConfiguration.KEY_SYSTEM_SECURITY_POLICY, + BasicValueValidators.getUrlValidator(), + null + }, + { + DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CA_CERTS, + BasicValueValidators.getFilePathValidator(), + SYSTEM_SECURITY + File.separator + "cacerts" + }, + { + DeploymentConfiguration.KEY_SYSTEM_TRUSTED_JSSE_CA_CERTS, + BasicValueValidators.getFilePathValidator(), + SYSTEM_SECURITY + File.separator + "jssecacerts" + }, + { + DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CERTS, + BasicValueValidators.getFilePathValidator(), + SYSTEM_SECURITY + File.separator + "trusted.certs" + }, + { + DeploymentConfiguration.KEY_SYSTEM_TRUSTED_JSSE_CERTS, + BasicValueValidators.getFilePathValidator(), + SYSTEM_SECURITY + File.separator + "trusted.jssecerts" + }, + { + DeploymentConfiguration.KEY_SYSTEM_TRUSTED_CLIENT_CERTS, + BasicValueValidators.getFilePathValidator(), + SYSTEM_SECURITY + File.separator + "trusted.clientcerts" + }, + /* security access and control */ + { + DeploymentConfiguration.KEY_SECURITY_PROMPT_USER, + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + "deployment.security.askgrantdialog.notinca", + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + "deployment.security.notinca.warning", + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + "deployment.security.expired.warning", + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + "deployment.security.jsse.hostmismatch.warning", + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + "deployment.security.trusted.policy", + BasicValueValidators.getFilePathValidator(), + null + }, + { + DeploymentConfiguration.KEY_SECURITY_ALLOW_HIDE_WINDOW_WARNING, + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + DeploymentConfiguration.KEY_SECURITY_PROMPT_USER_FOR_JNLP, + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + { + DeploymentConfiguration.KEY_SECURITY_INSTALL_AUTHENTICATOR, + BasicValueValidators.getBooleanValidator(), + String.valueOf(true) + }, + /* networking */ + { + DeploymentConfiguration.KEY_PROXY_TYPE, + BasicValueValidators.getRangedIntegerValidator(JNLPProxySelector.PROXY_TYPE_UNKNOWN, JNLPProxySelector.PROXY_TYPE_BROWSER), + String.valueOf(JNLPProxySelector.PROXY_TYPE_BROWSER) + }, + { + DeploymentConfiguration.KEY_PROXY_SAME, + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, + { + DeploymentConfiguration.KEY_PROXY_AUTO_CONFIG_URL, + BasicValueValidators.getUrlValidator(), + null + }, + { + DeploymentConfiguration.KEY_PROXY_BYPASS_LIST, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_BYPASS_LOCAL, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_HTTP_HOST, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_HTTP_PORT, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_HTTPS_HOST, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_HTTPS_PORT, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_FTP_HOST, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_FTP_PORT, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_SOCKS4_HOST, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_SOCKS4_PORT, + null, + null + }, + { + DeploymentConfiguration.KEY_PROXY_OVERRIDE_HOSTS, + null, + null + }, + /* cache and optional package repository */ + { + "deployment.cache.max.size", + BasicValueValidators.getRangedIntegerValidator(-1, Integer.MAX_VALUE), + String.valueOf("-1") + }, + { + "deployment.cache.jarcompression", + BasicValueValidators.getRangedIntegerValidator(0, 10), + String.valueOf(0) + }, + { + "deployment.javapi.cache.enabled", + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, + /* java console */ + { + DeploymentConfiguration.KEY_CONSOLE_STARTUP_MODE, + BasicValueValidators.getStringValidator(new String[] { + DeploymentConfiguration.CONSOLE_DISABLE, + DeploymentConfiguration.CONSOLE_HIDE, + DeploymentConfiguration.CONSOLE_SHOW + }), + DeploymentConfiguration.CONSOLE_HIDE + }, + /* tracing and logging */ + { + DeploymentConfiguration.KEY_ENABLE_TRACING, + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, + { + DeploymentConfiguration.KEY_ENABLE_LOGGING, + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, + /* JNLP association */ + { + DeploymentConfiguration.KEY_JNLP_ASSOCIATIONS, + BasicValueValidators.getRangedIntegerValidator(DeploymentConfiguration.JNLP_ASSOCIATION_NEVER, + DeploymentConfiguration.JNLP_ASSOCIATION_REPLACE_ASK), + String.valueOf(DeploymentConfiguration.JNLP_ASSOCIATION_ASK_USER) + }, + /* desktop integration */ + { + DeploymentConfiguration.KEY_CREATE_DESKTOP_SHORTCUT, + BasicValueValidators.getStringValidator(new String[] { + ShortcutDesc.CREATE_ALWAYS, + ShortcutDesc.CREATE_ALWAYS_IF_HINTED, + ShortcutDesc.CREATE_ASK_USER, + ShortcutDesc.CREATE_ASK_USER_IF_HINTED, + ShortcutDesc.CREATE_NEVER + }), + ShortcutDesc.CREATE_ASK_USER_IF_HINTED + }, + /* jre selection */ + { + DeploymentConfiguration.KEY_JRE_INTSTALL_URL, + BasicValueValidators.getUrlValidator(), + null + }, + /* jre management */ + { + DeploymentConfiguration.KEY_AUTO_DOWNLOAD_JRE, + BasicValueValidators.getBooleanValidator(), + String.valueOf(false) + }, + /* browser selection */ + { + DeploymentConfiguration.KEY_BROWSER_PATH, + BasicValueValidators.getFilePathValidator(), + null + }, + /* check for update timeout */ + { + DeploymentConfiguration.KEY_UPDATE_TIMEOUT, + BasicValueValidators.getRangedIntegerValidator(0, 10000), + String.valueOf(500) + } + }; + + HashMap<String, Setting<String>> result = new HashMap<String, Setting<String>>(); + for (int i = 0; i < defaults.length; i++) { + String name = (String) defaults[i][0]; + ValueValidator checker = (ValueValidator) defaults[i][1]; + String actualValue = (String) defaults[i][2]; + boolean locked = false; + Setting<String> value = new Setting<String>(name, name, locked, checker, actualValue, actualValue, "<internal>"); + result.put(name, value); + } + + return result; + } +} diff --git a/netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 662730f..dd329aa 100644 --- a/netx/net/sourceforge/jnlp/runtime/DeploymentConfiguration.java +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -14,9 +14,10 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -package net.sourceforge.jnlp.runtime; +package net.sourceforge.jnlp.config; + +import static net.sourceforge.jnlp.runtime.Translator.R; -import java.awt.AWTPermission; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; @@ -36,7 +37,7 @@ import java.util.Set; import javax.naming.ConfigurationException; -import net.sourceforge.jnlp.ShortcutDesc; +import net.sourceforge.jnlp.runtime.JNLPRuntime; /** * Manages the various properties and configuration related to deployment. @@ -46,59 +47,6 @@ import net.sourceforge.jnlp.ShortcutDesc; */ public final class DeploymentConfiguration { - /** - * Represents a value for a configuration. Provides methods to get the value - * as well as marking the value as locked. - */ - private final class ConfigValue { - - private String value; - private boolean locked; - - ConfigValue(String value) { - this(value, false); - } - - ConfigValue(String value, boolean locked) { - this.value = value; - this.locked = locked; - } - - ConfigValue(ConfigValue other) { - this(other.value, other.locked); - } - - String get() { - return value; - } - - /** - * Note that setting the value is not enforced - it is the caller's - * responsibility to check if a value is locked or not before setting a - * new value - * - * @param value the new value - */ - void set(String value) { - this.value = value; - } - - /** - * @return true if the value has been marked as locked - */ - boolean isLocked() { - return locked; - } - - /** - * Mark a value as locked - * @param locked - */ - void setLocked(boolean locked) { - this.locked = locked; - } - } - public static final String DEPLOYMENT_DIR = ".icedtea"; public static final String DEPLOYMENT_CONFIG = "deployment.config"; public static final String DEPLOYMENT_PROPERTIES = "deployment.properties"; @@ -135,12 +83,14 @@ public final class DeploymentConfiguration { */ public static final String KEY_USER_NETX_RUNNING_FILE = "deployment.user.runningfile"; + public static final String KEY_USER_SECURITY_POLICY = "deployment.user.security.policy"; public static final String KEY_USER_TRUSTED_CA_CERTS = "deployment.user.security.trusted.cacerts"; public static final String KEY_USER_TRUSTED_JSSE_CA_CERTS = "deployment.user.security.trusted.jssecacerts"; public static final String KEY_USER_TRUSTED_CERTS = "deployment.user.security.trusted.certs"; public static final String KEY_USER_TRUSTED_JSSE_CERTS = "deployment.user.security.trusted.jssecerts"; public static final String KEY_USER_TRUSTED_CLIENT_CERTS = "deployment.user.security.trusted.clientauthcerts"; + public static final String KEY_SYSTEM_SECURITY_POLICY = "deployment.system.security.policy"; public static final String KEY_SYSTEM_TRUSTED_CA_CERTS = "deployment.system.security.cacerts"; public static final String KEY_SYSTEM_TRUSTED_JSSE_CA_CERTS = "deployment.system.security.jssecacerts"; public static final String KEY_SYSTEM_TRUSTED_CERTS = "deployment.system.security.trusted.certs"; @@ -184,16 +134,26 @@ public final class DeploymentConfiguration { /* * Tracing and Logging */ - + public static final String KEY_ENABLE_TRACING = "deployment.trace"; public static final String KEY_ENABLE_LOGGING = "deployment.log"; /* + * Console + */ + public static final String KEY_CONSOLE_STARTUP_MODE = "deployment.console.startup.mode"; + + /* * Desktop Integration */ + public static final String KEY_JNLP_ASSOCIATIONS = "deployment.javaws.associations"; public static final String KEY_CREATE_DESKTOP_SHORTCUT = "deployment.javaws.shortcut"; + public static final String KEY_JRE_INTSTALL_URL = "deployment.javaws.installURL"; + public static final String KEY_AUTO_DOWNLOAD_JRE = "deployment.javaws.autodownload"; + public static final String KEY_BROWSER_PATH = "deployment.browser.path"; + public static final String KEY_UPDATE_TIMEOUT = "deployment.javaws.update.timeout"; public enum ConfigType { System, User @@ -208,14 +168,14 @@ public final class DeploymentConfiguration { private File userPropertiesFile = null; /** the current deployment properties */ - private Map<String, ConfigValue> currentConfiguration; + private Map<String, Setting<String>> currentConfiguration; /** the deployment properties that cannot be changed */ - private Map<String, ConfigValue> unchangeableConfiguration; + private Map<String, Setting<String>> unchangeableConfiguration; public DeploymentConfiguration() { - currentConfiguration = new HashMap<String, ConfigValue>(); - unchangeableConfiguration = new HashMap<String, ConfigValue>(); + currentConfiguration = new HashMap<String, Setting<String>>(); + unchangeableConfiguration = new HashMap<String, Setting<String>>(); } /** @@ -225,6 +185,18 @@ public final class DeploymentConfiguration { * @throws DeploymentException if it encounters a fatal error. */ public void load() throws ConfigurationException { + load(true); + } + + /** + * Initialize this deployment configuration by reading configuration files. + * Generally, it will try to continue and ignore errors it finds (such as file not found). + * + * @param fixIssues If true, fix issues that are discovered when reading configuration by + * resorting to the default values + * @throws DeploymentException if it encounters a fatal error. + */ + public void load(boolean fixIssues) throws ConfigurationException { // make sure no state leaks if security check fails later on File userFile = new File(System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR + File.separator + DEPLOYMENT_PROPERTIES); @@ -234,9 +206,9 @@ public final class DeploymentConfiguration { sm.checkRead(userFile.toString()); } - Map<String, ConfigValue> initialProperties = loadDefaultProperties(); + Map<String, Setting<String>> initialProperties = Defaults.getDefaults(); - Map<String, ConfigValue> systemProperties = null; + Map<String, Setting<String>> systemProperties = null; /* * First, try to read the system's deployment.config file to find if @@ -259,22 +231,25 @@ public final class DeploymentConfiguration { } /* need a copy of the original when we have to save */ - unchangeableConfiguration = new HashMap<String, ConfigValue>(); + unchangeableConfiguration = new HashMap<String, Setting<String>>(); Set<String> keys = initialProperties.keySet(); for (String key : keys) { - unchangeableConfiguration.put(key, new ConfigValue(initialProperties.get(key))); + unchangeableConfiguration.put(key, new Setting<String>(initialProperties.get(key))); } /* * Third, read the user's deployment.properties file */ userPropertiesFile = userFile; - Map<String, ConfigValue> userProperties = loadProperties(ConfigType.User, userPropertiesFile, - false); + Map<String, Setting<String>> userProperties = loadProperties(ConfigType.User, userPropertiesFile, false); if (userProperties != null) { mergeMaps(initialProperties, userProperties); } + if (fixIssues) { + checkAndFixConfiguration(initialProperties); + } + currentConfiguration = initialProperties; } @@ -292,7 +267,7 @@ public final class DeploymentConfiguration { } } - return currentConfiguration.get(key).get(); + return currentConfiguration.get(key).getValue(); } /** @@ -310,6 +285,20 @@ public final class DeploymentConfiguration { } /** + * @return a map containing property names and the corresponding settings + */ + public Map<String, Setting<String>> getRaw() { + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + if (userPropertiesFile != null) { + sm.checkRead(userPropertiesFile.toString()); + } + } + + return currentConfiguration; + } + + /** * Sets the value of corresponding to the key. If the value has been marked * as locked, it is not changed * @@ -324,119 +313,49 @@ public final class DeploymentConfiguration { } } - ConfigValue currentValue = currentConfiguration.get(key); + Setting<String> currentValue = currentConfiguration.get(key); if (currentValue != null) { if (!currentValue.isLocked()) { - currentValue.set(value); + currentValue.setValue(value); } } else { - currentValue = new ConfigValue(value); + currentValue = new Setting<String>(key, key, false, null, null, value, "<unknown>"); currentConfiguration.put(key, currentValue); } } /** - * Loads the default properties for deployment + * Check that the configuration is valid. If there are invalid values,set + * those values to the default values. This is done by using check() + * method of the ValueCheker for each setting on the actual value. Fixes + * are made in-place. + * + * @param initial a map representing the initial configuration */ - private Map<String, ConfigValue> loadDefaultProperties() { - - final String SYSTEM_HOME = System.getProperty("java.home"); - final String SYSTEM_SECURITY = SYSTEM_HOME + File.separator + "lib" + File.separator - + "security"; + public void checkAndFixConfiguration(Map<String, Setting<String>> initial) { - final String USER_HOME = System.getProperty("user.home") + File.separator + DEPLOYMENT_DIR; - final String USER_SECURITY = USER_HOME + File.separator + "security"; + Map<String, Setting<String>> defaults = Defaults.getDefaults(); - final String LOCKS_DIR = System.getProperty("java.io.tmpdir") + File.separator - + System.getProperty("user.name") + File.separator + "netx" + File.separator - + "locks"; - - /* - * This is more or less a straight copy from the deployment - * configuration page, with occasional replacements of "" or no-defaults - * with null - */ + for (String key : initial.keySet()) { + Setting<String> s = initial.get(key); + if (!(s.getName().equals(key))) { + System.out.println(R("DCInternal", "key " + key + " does not match setting name " + s.getName())); + } else if (!defaults.containsKey(key)) { + System.out.println(R("DCUnknownSettingWithVal", key)); + } else { + ValueValidator checker = defaults.get(key).getValidator(); + if (checker == null) { + continue; + } - String[][] defaults = new String[][] { - /* infrastructure */ - { KEY_USER_CACHE_DIR, USER_HOME + File.separator + "cache" }, - { KEY_USER_PERSISTENCE_CACHE_DIR, USER_HOME + File.separator + "pcache" }, - { KEY_SYSTEM_CACHE_DIR, null }, - { KEY_USER_LOG_DIR, USER_HOME + File.separator + "log" }, - { KEY_USER_TMP_DIR, USER_HOME + File.separator + "tmp" }, - { KEY_USER_LOCKS_DIR, LOCKS_DIR }, - { KEY_USER_NETX_RUNNING_FILE, LOCKS_DIR + File.separator + "netx_running" }, - /* certificates and policy files */ - { "deployment.user.security.policy", "file://" + USER_SECURITY + File.separator + "java.policy" }, - { KEY_USER_TRUSTED_CA_CERTS, USER_SECURITY + File.separator + "trusted.cacerts" }, - { KEY_USER_TRUSTED_JSSE_CA_CERTS, USER_SECURITY + File.separator + "trusted.jssecacerts" }, - { KEY_USER_TRUSTED_CERTS, USER_SECURITY + File.separator + "trusted.certs" }, - { KEY_USER_TRUSTED_JSSE_CERTS, USER_SECURITY + File.separator + "trusted.jssecerts" }, - { KEY_USER_TRUSTED_CLIENT_CERTS, USER_SECURITY + File.separator + "trusted.clientcerts" }, - { "deployment.system.security.policy", null }, - { KEY_SYSTEM_TRUSTED_CA_CERTS, SYSTEM_SECURITY + File.separator + "cacerts" }, - { KEY_SYSTEM_TRUSTED_JSSE_CA_CERTS, SYSTEM_SECURITY + File.separator + "jssecacerts" }, - { KEY_SYSTEM_TRUSTED_CERTS, SYSTEM_SECURITY + File.separator + "trusted.certs" }, - { KEY_SYSTEM_TRUSTED_JSSE_CERTS, SYSTEM_SECURITY + File.separator + "trusted.jssecerts" }, - { KEY_SYSTEM_TRUSTED_CLIENT_CERTS, SYSTEM_SECURITY + File.separator + "trusted.clientcerts" }, - /* security access and control */ - { KEY_SECURITY_PROMPT_USER, String.valueOf(true) }, - { "deployment.security.askgrantdialog.notinca", String.valueOf(true) }, - { "deployment.security.notinca.warning", String.valueOf(true) }, - { "deployment.security.expired.warning", String.valueOf(true) }, - { "deployment.security.jsse.hostmismatch.warning", String.valueOf(true) }, - { "deployment.security.trusted.policy", null }, - { KEY_SECURITY_ALLOW_HIDE_WINDOW_WARNING, String.valueOf(true) }, - { KEY_SECURITY_PROMPT_USER_FOR_JNLP, String.valueOf(true) }, - { KEY_SECURITY_INSTALL_AUTHENTICATOR, String.valueOf(true) }, - /* networking */ - { KEY_PROXY_TYPE, String.valueOf(JNLPProxySelector.PROXY_TYPE_BROWSER) }, - { KEY_PROXY_SAME, String.valueOf(false) }, - { KEY_PROXY_AUTO_CONFIG_URL, null }, - { KEY_PROXY_BYPASS_LIST, null }, - { KEY_PROXY_BYPASS_LOCAL, null }, - { KEY_PROXY_HTTP_HOST, null }, - { KEY_PROXY_HTTP_PORT, null }, - { KEY_PROXY_HTTPS_HOST, null }, - { KEY_PROXY_HTTPS_PORT, null }, - { KEY_PROXY_FTP_HOST, null }, - { KEY_PROXY_FTP_PORT, null }, - { KEY_PROXY_SOCKS4_HOST, null }, - { KEY_PROXY_SOCKS4_PORT, null }, - { KEY_PROXY_OVERRIDE_HOSTS, null }, - /* cache and optional package repository */ - { "deployment.cache.max.size", String.valueOf("-1") }, - { "deployment.cache.jarcompression", String.valueOf(0) }, - { "deployment.javapi.cache.enabled", String.valueOf(false) }, - /* java console */ - { "deployment.console.startup.mode", CONSOLE_HIDE }, - /* tracing and logging */ - { "deployment.trace", String.valueOf(false) }, - { KEY_ENABLE_LOGGING, String.valueOf(false) }, - /* JNLP association */ - { "deployment.javaws.associations", String.valueOf(JNLP_ASSOCIATION_ASK_USER) }, - /* desktop integration */ - { KEY_CREATE_DESKTOP_SHORTCUT, ShortcutDesc.CREATE_ASK_USER_IF_HINTED }, - /* jre selection */ - { "deployment.javaws.installURL", null }, - /* jre management */ - { "deployment.javaws.autodownload", null }, - /* browser selection */ - { KEY_BROWSER_PATH, null }, - /* check for update timeout */ - { "deployment.javaws.update.timeout", String.valueOf(500) } - }; - - HashMap<String, ConfigValue> result = new HashMap<String, ConfigValue>(); - for (int i = 0; i < defaults.length; i++) { - String key = defaults[i][0]; - String actualValue = defaults[i][1]; - boolean locked = false; - ConfigValue value = new ConfigValue(actualValue, locked); - result.put(key, value); + try { + checker.validate(s.getValue()); + } catch (IllegalArgumentException e) { + System.out.println(R("DCErrorInSetting", key, s.getValue(), s.getDefaultValue(), checker.getPossibleValues())); + s.setValue(s.getDefaultValue()); + } + } } - - return result; } /** @@ -468,7 +387,7 @@ public final class DeploymentConfiguration { System.out.println("Loading system configuation from: " + configFile); } - Map<String, ConfigValue> systemConfiguration = new HashMap<String, ConfigValue>(); + Map<String, Setting<String>> systemConfiguration = new HashMap<String, Setting<String>>(); try { systemConfiguration = parsePropertiesFile(configFile); } catch (IOException e) { @@ -484,7 +403,7 @@ public final class DeploymentConfiguration { */ try { - String urlString = systemConfiguration.get("deployment.system.config").get(); + String urlString = systemConfiguration.get("deployment.system.config").getValue(); if (urlString == null) { if (JNLPRuntime.isDebug()) { System.out.println("No System level " + DEPLOYMENT_PROPERTIES + " found."); @@ -498,8 +417,8 @@ public final class DeploymentConfiguration { System.out.println("Using System level" + DEPLOYMENT_PROPERTIES + ": " + systemPropertiesFile); } - ConfigValue mandatory = systemConfiguration.get("deployment.system.config.mandatory"); - systemPropertiesMandatory = Boolean.valueOf(mandatory == null ? null : mandatory.get()); + Setting<String> mandatory = systemConfiguration.get("deployment.system.config.mandatory"); + systemPropertiesMandatory = Boolean.valueOf(mandatory == null ? null : (String) mandatory.getValue()); return true; } else { if (JNLPRuntime.isDebug()) { @@ -524,7 +443,7 @@ public final class DeploymentConfiguration { * * @throws ConfigurationException if the file is mandatory but cannot be read */ - private Map<String, ConfigValue> loadProperties(ConfigType type, File file, boolean mandatory) + private Map<String, Setting<String>> loadProperties(ConfigType type, File file, boolean mandatory) throws ConfigurationException { if (file == null || !file.isFile()) { if (JNLPRuntime.isDebug()) { @@ -570,9 +489,9 @@ public final class DeploymentConfiguration { for (String key : currentConfiguration.keySet()) { String oldValue = unchangeableConfiguration.get(key) == null ? null - : unchangeableConfiguration.get(key).get(); - String newValue = currentConfiguration.get(key) == null ? null : currentConfiguration - .get(key).get(); + : (String) unchangeableConfiguration.get(key).getValue(); + String newValue = currentConfiguration.get(key) == null ? null : (String) currentConfiguration + .get(key).getValue(); if (oldValue == null && newValue == null) { continue; } else if (oldValue == null && newValue != null) { @@ -609,8 +528,8 @@ public final class DeploymentConfiguration { * @param destination the map to which all the properties should be added * @throws IOException if an IO problem occurs */ - private Map<String, ConfigValue> parsePropertiesFile(File propertiesFile) throws IOException { - Map<String, ConfigValue> result = new HashMap<String, ConfigValue>(); + private Map<String, Setting<String>> parsePropertiesFile(File propertiesFile) throws IOException { + Map<String, Setting<String>> result = new HashMap<String, Setting<String>>(); Properties properties = new Properties(); @@ -625,9 +544,9 @@ public final class DeploymentConfiguration { for (String key : keys) { if (key.endsWith(".locked")) { String realKey = key.substring(0, key.length() - ".locked".length()); - ConfigValue configValue = result.get(realKey); + Setting<String> configValue = result.get(realKey); if (configValue == null) { - configValue = new ConfigValue(null, true); + configValue = new Setting<String>(realKey, realKey, true, null, null, null, propertiesFile.toString()); result.put(realKey, configValue); } else { configValue.setLocked(true); @@ -635,12 +554,13 @@ public final class DeploymentConfiguration { } else { /* when parsing a properties we set value without checking if it is locked or not */ String newValue = properties.getProperty(key); - ConfigValue configValue = result.get(key); + Setting<String> configValue = result.get(key); if (configValue == null) { - configValue = new ConfigValue(newValue); + configValue = new Setting<String>(key, key, false, null, null, newValue, propertiesFile.toString()); result.put(key, configValue); } else { - configValue.set(newValue); + configValue.setValue(newValue); + configValue.setSource(propertiesFile.toString()); } } } @@ -656,15 +576,16 @@ public final class DeploymentConfiguration { * @param finalMap the destination for putting values * @param srcMap the source for reading key value pairs */ - private void mergeMaps(Map<String, ConfigValue> finalMap, Map<String, ConfigValue> srcMap) { + private void mergeMaps(Map<String, Setting<String>> finalMap, Map<String, Setting<String>> srcMap) { for (String key : srcMap.keySet()) { - ConfigValue configValue = finalMap.get(key); - if (configValue == null) { - configValue = srcMap.get(key); - finalMap.put(key, configValue); + Setting<String> destValue = finalMap.get(key); + Setting<String> srcValue = srcMap.get(key); + if (destValue == null) { + finalMap.put(key, srcValue); } else { - if (!configValue.isLocked()) { - configValue.set(srcMap.get(key).get()); + if (!destValue.isLocked()) { + destValue.setSource(srcValue.getSource()); + destValue.setValue(srcValue.getValue()); } } } @@ -678,12 +599,12 @@ public final class DeploymentConfiguration { * @param out the PrintStream to write data to */ @SuppressWarnings("unused") - private static void dumpConfiguration(Map<String, ConfigValue> config, PrintStream out) { + private static void dumpConfiguration(Map<String, Setting<String>> config, PrintStream out) { System.out.println("KEY: VALUE [Locked]"); for (String key : config.keySet()) { - ConfigValue value = config.get(key); - out.println("'" + key + "': '" + value.get() + "'" + Setting<String> value = config.get(key); + out.println("'" + key + "': '" + value.getValue() + "'" + (value.isLocked() ? " [LOCKED]" : "")); } } diff --git a/netx/net/sourceforge/jnlp/config/Setting.java b/netx/net/sourceforge/jnlp/config/Setting.java new file mode 100644 index 0000000..34faacc --- /dev/null +++ b/netx/net/sourceforge/jnlp/config/Setting.java @@ -0,0 +1,176 @@ +/* Setting.java + Copyright (C) 2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +/** + * Represents a value for a configuration. Provides methods to get the value + * as well as marking the value as locked. + * + * Each instance of this class has an associated ValueChecker. This checker + * can be used to check if the current value is valid. The default value + * _must_ be valid. Null values can not originate externally so are (mostly) + * considered valid. + */ +public class Setting<T> { + + private String name = null; + private String description = null; + private boolean locked = false; + private ValueValidator validator = null; + private T defaultValue = null; + private T value = null; + private String source = null; + + /** + * Creates a new Settings object + * + * @param name the name of this setting + * @param description a human readable description of this setting + * @param locked whether this setting is currently locked + * @param validator the {@link ValueValidator} that can be used to validate + * the value + * @param defaultValue the default value of this setting. If this is not a + * recognized setting, use null. + * @param value the initial value of this setting + * @param source the origin of the value (a file, or perhaps "<internal>") + */ + public Setting(String name, String description, boolean locked, + ValueValidator validator, T defaultValue, T value, String source) { + this.name = name; + this.description = description; + this.locked = locked; + this.validator = validator; + this.source = source; + this.defaultValue = defaultValue; + this.value = value; + } + + /** + * Creates a new Settings object by cloning the values from another + * Settings object + * @param other a Settings object to initialize settings from + */ + public Setting(Setting<T> other) { + this(other.name, other.description, other.locked, other.validator, + other.defaultValue, other.value, other.source); + } + + /** + * @return the {@link ValueValidator} that can be used to check if + * the current value is valid + */ + public ValueValidator getValidator() { + return validator; + } + + /** + * @return the default value for this setting. May be null if this is not + * one of the supported settings + */ + public T getDefaultValue() { + return defaultValue; + } + + /** + * @return a human readable description of this setting + */ + public String getDescription() { + return description; + } + + /** + * @return the name (like foo.bar.baz) of this setting + */ + public String getName() { + return name; + } + + /** + * @return the source of the current value of this setting. May be a string + * like "internal" or it may be the location of the properties file + */ + public String getSource() { + return source; + } + + /** + * @return the current value of this setting + */ + public T getValue() { + return value; + } + + /** + * @return true if this setting is locked + */ + public boolean isLocked() { + return locked; + } + + /** + * Marks this setting as locked or unlocked. Setting the value is not + * enforced by this class. + * + * @param locked whether to mark this setting as locked or not locked. + */ + public void setLocked(boolean locked) { + this.locked = locked; + } + + /** + * Sets the source of the current value of this Setting. Maybe a string + * like "internal" or the location of the properties file + * + * @param source the source of the value + */ + public void setSource(String source) { + this.source = source; + } + + /** + * Note that setting the value is not enforced - it is the caller's + * responsibility to check if a value is locked or not before setting a + * new value + * + * @param value the new value + */ + public void setValue(T value) { + this.value = value; + } + +} diff --git a/netx/net/sourceforge/jnlp/config/ValueValidator.java b/netx/net/sourceforge/jnlp/config/ValueValidator.java new file mode 100644 index 0000000..d743e6f --- /dev/null +++ b/netx/net/sourceforge/jnlp/config/ValueValidator.java @@ -0,0 +1,66 @@ +/* ValueChecker.java + Copyright (C) 2010 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. +*/ + +package net.sourceforge.jnlp.config; + +/** + * A class implements the ValueValidator interface to indicate that it can validate + * values. + * + * @see BasicValueValidators + */ +public interface ValueValidator { + + /** + * This method checks if the given object is a valid value for this + * specific {@link ValueValidator}. Any arbitrary operation can be + * performed to ensure that the value is valid. + * + * @param value The object to validate + * @throws IllegalArgumentException if the value is invalid + */ + public void validate(Object value) throws IllegalArgumentException; + + /** + * Returns a string describing possible values in human-readable form that + * this {@link ValueValidator} accepts + * + * @return a string describing possible values that this + * {@link ValueValidator} accepts + */ + public String getPossibleValues(); +} diff --git a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java index 241f04c..8a74ca1 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java +++ b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java @@ -31,7 +31,7 @@ import javax.swing.JDialog; import javax.swing.SwingUtilities; import javax.swing.UIManager; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java index adeb32e..0017dd1 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java +++ b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java @@ -43,7 +43,7 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java index 3273940..ba480c3 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/ControlPanel.java @@ -46,7 +46,7 @@ import javax.swing.border.EmptyBorder; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.security.viewer.CertificatePane; diff --git a/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java b/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java index 1cdbb46..a556f40 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/DebuggingPanel.java @@ -32,7 +32,7 @@ import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/DesktopShortcutPanel.java b/netx/net/sourceforge/jnlp/controlpanel/DesktopShortcutPanel.java index 8563b82..299a4e1 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/DesktopShortcutPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/DesktopShortcutPanel.java @@ -29,7 +29,7 @@ import javax.swing.Box; import javax.swing.JComboBox; import javax.swing.JLabel; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java b/netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java index 74f039b..7a92830 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java +++ b/netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java @@ -23,7 +23,7 @@ import java.awt.event.MouseEvent; import javax.swing.JTextArea; import javax.swing.JTextField; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; /** * When middle click pastes to the textboxes it doesn't register it... This is diff --git a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java index ae21521..f49c672 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java @@ -43,7 +43,7 @@ import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTextField; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/SecuritySettingsPanel.java b/netx/net/sourceforge/jnlp/controlpanel/SecuritySettingsPanel.java index d148b8a..9727b46 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/SecuritySettingsPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/SecuritySettingsPanel.java @@ -30,7 +30,7 @@ import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JPanel; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java b/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java index 413b585..9ed954b 100644 --- a/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java +++ b/netx/net/sourceforge/jnlp/controlpanel/TemporaryInternetFilesPanel.java @@ -46,7 +46,7 @@ import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.Translator; /** diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 4c04906..e16e91f 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -232,6 +232,17 @@ KSJsseCerts=Trusted JSSE Certificates KSCaCerts=Trusted Root CA Certificates
KSJsseCaCerts=Trusted JSSE Root CA Certificates,
KSClientCerts=Client Authentication Certificates
+
+# Deployment Configuration messages
+DCErrorInSetting=Error: setting "{0}" has incorrect value "{1}". Using the default value "{2}" instead. Possible values {3}.
+DCInternal=Internal error: {0}
+DCUnknownSettingWithVal=Unknown setting "{0}"
+
+# Value Validator messages. Messages should follow "Possible values ..."
+VVPossibleBooleanValues=are {0} or {1}
+VVPossibleFileValues=include the absolute location of a file - it must begin with a /
+VVPossibleRangedIntegerValues=are in range {0} to {1} (inclusive)
+VVPossibleUrlValues=include any valid url (eg http://icedtea.classpath.org/hg/)
# Control Panel - Tab Descriptions CPAboutDescription=View version information about Icedtea Control Panel. diff --git a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java index f86eb39..de7bfb4 100644 --- a/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java +++ b/netx/net/sourceforge/jnlp/runtime/ApplicationInstance.java @@ -32,6 +32,7 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.PropertyDesc; import net.sourceforge.jnlp.SecurityDesc; import net.sourceforge.jnlp.ShortcutDesc; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.event.ApplicationEvent; import net.sourceforge.jnlp.event.ApplicationListener; import net.sourceforge.jnlp.security.SecurityWarning; diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java index 4a55145..acf8e85 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPProxySelector.java @@ -32,6 +32,8 @@ import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; +import net.sourceforge.jnlp.config.DeploymentConfiguration; + /** * A ProxySelector specific to JNLPs. This proxy uses the deployment * configuration to determine what to do. diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index 1e3a91c..b080806 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -36,6 +36,7 @@ import javax.swing.text.html.parser.ParserDelegator; import net.sourceforge.jnlp.*; import net.sourceforge.jnlp.cache.*; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.security.JNLPAuthenticator; import net.sourceforge.jnlp.security.SecurityDialogMessageHandler; import net.sourceforge.jnlp.security.VariableX509TrustManager; @@ -103,7 +104,7 @@ public class JNLPRuntime { private static boolean securityEnabled = true; /** whether debug mode is on */ - private static boolean debug = false; // package access by Boot + private static boolean debug = false; /** whether streams should be redirected */ private static boolean redirectStreams = false; diff --git a/netx/net/sourceforge/jnlp/security/KeyStores.java b/netx/net/sourceforge/jnlp/security/KeyStores.java index fda324a..0c76ff2 100644 --- a/netx/net/sourceforge/jnlp/security/KeyStores.java +++ b/netx/net/sourceforge/jnlp/security/KeyStores.java @@ -50,7 +50,7 @@ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.runtime.Translator; import net.sourceforge.jnlp.util.FileUtils; diff --git a/netx/net/sourceforge/jnlp/security/SecurityWarning.java b/netx/net/sourceforge/jnlp/security/SecurityWarning.java index 863cb2a..08f67fd 100644 --- a/netx/net/sourceforge/jnlp/security/SecurityWarning.java +++ b/netx/net/sourceforge/jnlp/security/SecurityWarning.java @@ -48,7 +48,7 @@ import javax.swing.JDialog; import javax.swing.SwingUtilities; import net.sourceforge.jnlp.JNLPFile; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; /** diff --git a/netx/net/sourceforge/jnlp/services/ServiceUtil.java b/netx/net/sourceforge/jnlp/services/ServiceUtil.java index 96d040a..b55bba4 100644 --- a/netx/net/sourceforge/jnlp/services/ServiceUtil.java +++ b/netx/net/sourceforge/jnlp/services/ServiceUtil.java @@ -37,8 +37,8 @@ import javax.jnlp.SingleInstanceService; import javax.jnlp.UnavailableServiceException; import net.sourceforge.jnlp.JNLPFile; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.ApplicationInstance; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.security.SecurityWarning; import net.sourceforge.jnlp.security.SecurityWarning.AccessType; diff --git a/netx/net/sourceforge/jnlp/services/SingleInstanceLock.java b/netx/net/sourceforge/jnlp/services/SingleInstanceLock.java index d9430a3..3684232 100644 --- a/netx/net/sourceforge/jnlp/services/SingleInstanceLock.java +++ b/netx/net/sourceforge/jnlp/services/SingleInstanceLock.java @@ -28,7 +28,7 @@ import java.net.BindException; import java.net.ServerSocket; import net.sourceforge.jnlp.JNLPFile; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.FileUtils; diff --git a/netx/net/sourceforge/jnlp/services/XBasicService.java b/netx/net/sourceforge/jnlp/services/XBasicService.java index 124025c..7def5e6 100644 --- a/netx/net/sourceforge/jnlp/services/XBasicService.java +++ b/netx/net/sourceforge/jnlp/services/XBasicService.java @@ -28,8 +28,8 @@ import net.sourceforge.jnlp.InformationDesc; import net.sourceforge.jnlp.JARDesc; import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.Launcher; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.ApplicationInstance; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.PropertiesFile; diff --git a/netx/net/sourceforge/jnlp/services/XPersistenceService.java b/netx/net/sourceforge/jnlp/services/XPersistenceService.java index 5388438..4f296e3 100644 --- a/netx/net/sourceforge/jnlp/services/XPersistenceService.java +++ b/netx/net/sourceforge/jnlp/services/XPersistenceService.java @@ -24,6 +24,7 @@ import javax.jnlp.*; import net.sourceforge.jnlp.*; import net.sourceforge.jnlp.cache.*; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.*; import net.sourceforge.jnlp.util.FileUtils; diff --git a/netx/net/sourceforge/jnlp/util/XDesktopEntry.java b/netx/net/sourceforge/jnlp/util/XDesktopEntry.java index 06dff37..b13fcea 100644 --- a/netx/net/sourceforge/jnlp/util/XDesktopEntry.java +++ b/netx/net/sourceforge/jnlp/util/XDesktopEntry.java @@ -32,7 +32,7 @@ import net.sourceforge.jnlp.JNLPFile; import net.sourceforge.jnlp.StreamEater; import net.sourceforge.jnlp.cache.CacheUtil; import net.sourceforge.jnlp.cache.UpdatePolicy; -import net.sourceforge.jnlp.runtime.DeploymentConfiguration; +import net.sourceforge.jnlp.config.DeploymentConfiguration; import net.sourceforge.jnlp.runtime.JNLPRuntime; /** |