diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleException.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleException.java
index 3a09c5ac7..cb2e586fa 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleException.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleException.java
@@ -19,16 +19,41 @@ package net.sourceforge.guacamole;
* along with this program. If not, see .
*/
+
+/**
+ * A generic exception thrown when parts of the Guacamole API encounter
+ * errors.
+ *
+ * @author Michael Jumper
+ */
public class GuacamoleException extends Exception {
+ /**
+ * Creates a new GuacamoleException with the given message and cause.
+ *
+ * @param message A human readable description of the exception that
+ * occurred.
+ * @param cause The cause of this exception.
+ */
public GuacamoleException(String message, Throwable cause) {
super(message, cause);
}
+ /**
+ * Creates a new GuacamoleException with the given message.
+ *
+ * @param message A human readable description of the exception that
+ * occurred.
+ */
public GuacamoleException(String message) {
super(message);
}
+ /**
+ * Creates a new GuacamoleException with the given cause.
+ *
+ * @param cause The cause of this exception.
+ */
public GuacamoleException(Throwable cause) {
super(cause);
}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleProperties.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleProperties.java
deleted file mode 100644
index 9bf3ebf3b..000000000
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleProperties.java
+++ /dev/null
@@ -1,151 +0,0 @@
-
-package net.sourceforge.guacamole;
-
-/*
- * Guacamole - Clientless Remote Desktop
- * Copyright (C) 2010 Michael Jumper
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see .
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-public class GuacamoleProperties {
-
- private static final Properties properties;
- private static GuacamoleException exception;
-
- static {
-
- properties = new Properties();
-
- try {
-
- InputStream stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties");
- if (stream == null)
- throw new IOException("Resource /guacamole.properties not found.");
-
- properties.load(stream);
- }
- catch (IOException e) {
- exception = new GuacamoleException("Error reading guacamole.properties", e);
- }
-
- }
-
- public static String getProperty(String name) throws GuacamoleException {
- if (exception != null) throw exception;
- return properties.getProperty(name);
- }
-
- protected static String humanReadableList(Object... values) {
-
- String list = "";
- for (int i=0; i= 1)
- list += ", ";
-
- if (i == values.length -1)
- list += " or ";
-
- list += "\"" + values[i] + "\"";
- }
-
- return list;
-
- }
-
- public static String getProperty(String name, String defaultValue, String... allowedValues) throws GuacamoleException {
-
- String value = getProperty(name);
-
- // Use default if not specified
- if (value == null) {
- if (defaultValue == null)
- throw new GuacamoleException("Parameter \"" + name + "\" is required.");
-
- return defaultValue;
- }
-
- // If not restricted to certain values, just return whatever is given.
- if (allowedValues.length == 0)
- return value;
-
- // If restricted, only return value within given list
- for (String allowedValue : allowedValues)
- if (value.equals(allowedValue))
- return value;
-
- throw new GuacamoleException("Parameter \"" + name + "\" must be " + humanReadableList((Object) allowedValues));
- }
-
- public static boolean getBooleanProperty(String name, Boolean defaultValue) throws GuacamoleException {
-
- String value = getProperty(name);
-
- // Use default if not specified
- if (value == null) {
- if (defaultValue == null)
- throw new GuacamoleException("Parameter \"" + name + "\" is required.");
-
- return defaultValue;
- }
-
- value = value.trim();
- if (value.equals("true"))
- return true;
-
- if (value.equals("false"))
- return false;
-
- throw new GuacamoleException("Parameter \"" + name + "\" must be \"true\" or \"false\".");
-
- }
-
- public static int getIntProperty(String name, Integer defaultValue, Integer... allowedValues) throws GuacamoleException {
-
- String parmString = getProperty(name);
-
- // Use default if not specified
- if (parmString== null) {
- if (defaultValue == null)
- throw new GuacamoleException("Parameter \"" + name + "\" is required.");
-
- return defaultValue;
- }
-
- try {
- int value = Integer.parseInt(parmString);
-
- // If not restricted to certain values, just return whatever is given.
- if (allowedValues.length == 0)
- return value;
-
- // If restricted, only return value within given list
- for (int allowedValue : allowedValues)
- if (value == allowedValue)
- return value;
-
- throw new GuacamoleException("Parameter \"" + name + "\" must be " + humanReadableList((Object) allowedValues));
- }
- catch (NumberFormatException e) {
- throw new GuacamoleException("Parameter \"" + name + "\" must be an integer.", e);
- }
-
- }
-
-}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/FileGuacamoleProperty.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/FileGuacamoleProperty.java
new file mode 100644
index 000000000..c51e86dd8
--- /dev/null
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/FileGuacamoleProperty.java
@@ -0,0 +1,32 @@
+
+package net.sourceforge.guacamole.properties;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import java.io.File;
+import net.sourceforge.guacamole.GuacamoleException;
+
+public abstract class FileGuacamoleProperty implements GuacamoleProperty {
+
+ @Override
+ public File parseValue(String value) throws GuacamoleException {
+ return new File(value);
+ }
+
+}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java
new file mode 100644
index 000000000..76f713849
--- /dev/null
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperties.java
@@ -0,0 +1,74 @@
+
+package net.sourceforge.guacamole.properties;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import net.sourceforge.guacamole.GuacamoleException;
+
+public class GuacamoleProperties {
+
+ public static final StringGuacamoleProperty GUACD_HOSTNAME = new StringGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "guacd-hostname"; }
+
+ };
+
+ public static final IntegerGuacamoleProperty GUACD_PORT = new IntegerGuacamoleProperty() {
+
+ @Override
+ public String getName() { return "guacd-port"; }
+
+ };
+
+ private static final Properties properties;
+ private static GuacamoleException exception;
+
+ static {
+
+ properties = new Properties();
+
+ try {
+
+ InputStream stream = GuacamoleProperties.class.getResourceAsStream("/guacamole.properties");
+ if (stream == null)
+ throw new IOException("Resource /guacamole.properties not found.");
+
+ properties.load(stream);
+
+ }
+ catch (IOException e) {
+ exception = new GuacamoleException("Error reading guacamole.properties", e);
+ }
+
+ }
+
+ public static Type getProperty(GuacamoleProperty property) throws GuacamoleException {
+
+ if (exception != null)
+ throw exception;
+
+ return property.parseValue(properties.getProperty(property.getName()));
+
+ }
+
+}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperty.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperty.java
new file mode 100644
index 000000000..b32072554
--- /dev/null
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/GuacamoleProperty.java
@@ -0,0 +1,31 @@
+
+package net.sourceforge.guacamole.properties;
+
+import net.sourceforge.guacamole.GuacamoleException;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+
+public interface GuacamoleProperty {
+
+ public String getName();
+
+ public Type parseValue(String value) throws GuacamoleException;
+
+}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/IntegerGuacamoleProperty.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/IntegerGuacamoleProperty.java
new file mode 100644
index 000000000..6c6919d08
--- /dev/null
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/IntegerGuacamoleProperty.java
@@ -0,0 +1,39 @@
+
+package net.sourceforge.guacamole.properties;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import net.sourceforge.guacamole.GuacamoleException;
+
+public abstract class IntegerGuacamoleProperty implements GuacamoleProperty {
+
+ @Override
+ public Integer parseValue(String value) throws GuacamoleException {
+
+ try {
+ Integer integer = new Integer(value);
+ return integer;
+ }
+ catch (NumberFormatException e) {
+ throw new GuacamoleException("Property \"" + getName() + "\" must be an integer.", e);
+ }
+
+ }
+
+}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/StringGuacamoleProperty.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/StringGuacamoleProperty.java
new file mode 100644
index 000000000..05a3509ef
--- /dev/null
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/properties/StringGuacamoleProperty.java
@@ -0,0 +1,31 @@
+
+package net.sourceforge.guacamole.properties;
+
+/*
+ * Guacamole - Clientless Remote Desktop
+ * Copyright (C) 2010 Michael Jumper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+import net.sourceforge.guacamole.GuacamoleException;
+
+public abstract class StringGuacamoleProperty implements GuacamoleProperty {
+
+ @Override
+ public String parseValue(String value) throws GuacamoleException {
+ return value;
+ }
+
+}