mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 17:13:21 +00:00 
			
		
		
		
	GUAC-800: Migrate to JSON for protocol descriptions. Use full Forms instead of simply Fields for protocol parameters (allow sections).
This commit is contained in:
		| @@ -22,7 +22,6 @@ | ||||
|  | ||||
| package org.glyptodon.guacamole.environment; | ||||
|  | ||||
| import java.io.BufferedInputStream; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FilenameFilter; | ||||
| @@ -31,18 +30,13 @@ import java.io.InputStream; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map; | ||||
| import java.util.Properties; | ||||
| import org.codehaus.jackson.map.ObjectMapper; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.GuacamoleServerException; | ||||
| import org.glyptodon.guacamole.properties.GuacamoleProperty; | ||||
| import org.glyptodon.guacamole.protocols.ProtocolInfo; | ||||
| import org.glyptodon.guacamole.xml.DocumentHandler; | ||||
| import org.glyptodon.guacamole.xml.protocol.ProtocolTagHandler; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import org.xml.sax.InputSource; | ||||
| import org.xml.sax.SAXException; | ||||
| import org.xml.sax.XMLReader; | ||||
| import org.xml.sax.helpers.XMLReaderFactory; | ||||
|  | ||||
| /** | ||||
|  * The environment of the locally-running Guacamole instance, describing | ||||
| @@ -79,6 +73,11 @@ public class LocalEnvironment implements Environment { | ||||
|      */ | ||||
|     private final Map<String, ProtocolInfo> availableProtocols; | ||||
|  | ||||
|     /** | ||||
|      * The Jackson parser for parsing JSON files. | ||||
|      */ | ||||
|     private static final ObjectMapper mapper = new ObjectMapper(); | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Environment, initializing that environment based on the | ||||
|      * location of GUACAMOLE_HOME and the contents of guacamole.properties. | ||||
| @@ -162,48 +161,25 @@ public class LocalEnvironment implements Environment { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Parses the given XML file, returning the parsed ProtocolInfo. | ||||
|      * Parses the given JSON file, returning the parsed ProtocolInfo. The JSON | ||||
|      * format is conveniently and intentionally identical to a serialized | ||||
|      * ProtocolInfo object, which is identical to the JSON format used by the | ||||
|      * protocol REST service built into the Guacamole web application. | ||||
|      * | ||||
|      * @param input An input stream containing XML describing the parameters | ||||
|      *              associated with a protocol supported by Guacamole. | ||||
|      * @return A new ProtocolInfo object which contains the parameters described | ||||
|      *         by the XML file parsed. | ||||
|      * @throws GuacamoleException If an error occurs while parsing the XML file. | ||||
|      * @param input | ||||
|      *     An input stream containing JSON describing the forms and parameters | ||||
|      *     associated with a protocol supported by Guacamole. | ||||
|      * | ||||
|      * @return | ||||
|      *     A new ProtocolInfo object which contains the forms and parameters | ||||
|      *     described by the JSON file parsed. | ||||
|      * | ||||
|      * @throws IOException | ||||
|      *     If an error occurs while parsing the JSON file. | ||||
|      */ | ||||
|     private ProtocolInfo readProtocol(InputStream input) | ||||
|             throws GuacamoleException { | ||||
|  | ||||
|         // Parse document | ||||
|         try { | ||||
|  | ||||
|             // Get handler for root element | ||||
|             ProtocolTagHandler protocolTagHandler = | ||||
|                     new ProtocolTagHandler(); | ||||
|  | ||||
|             // Set up document handler | ||||
|             DocumentHandler contentHandler = new DocumentHandler( | ||||
|                     "protocol", protocolTagHandler); | ||||
|  | ||||
|             // Set up XML parser | ||||
|             XMLReader parser = XMLReaderFactory.createXMLReader(); | ||||
|             parser.setContentHandler(contentHandler); | ||||
|  | ||||
|             // Read and parse file | ||||
|             InputStream xml = new BufferedInputStream(input); | ||||
|             parser.parse(new InputSource(xml)); | ||||
|             xml.close(); | ||||
|  | ||||
|             // Return parsed protocol | ||||
|             return protocolTagHandler.asProtocolInfo(); | ||||
|  | ||||
|         } | ||||
|         catch (IOException e) { | ||||
|             throw new GuacamoleException("Error reading basic user mapping file.", e); | ||||
|         } | ||||
|         catch (SAXException e) { | ||||
|             throw new GuacamoleException("Error parsing basic user mapping XML.", e); | ||||
|         } | ||||
|  | ||||
|             throws IOException { | ||||
|         return mapper.readValue(input, ProtocolInfo.class); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -212,9 +188,11 @@ public class LocalEnvironment implements Environment { | ||||
|      * each of these protocols. The key of each entry will be the name of that | ||||
|      * protocol, as would be passed to guacd during connection. | ||||
|      * | ||||
|      * @return A map of all available protocols. | ||||
|      * @throws GuacamoleException If an error occurs while reading the various | ||||
|      *                            protocol XML files. | ||||
|      * @return | ||||
|      *     A map of all available protocols. | ||||
|      * | ||||
|      * @throws GuacamoleException | ||||
|      *     If an error occurs while reading the various protocol JSON files. | ||||
|      */ | ||||
|     private Map<String, ProtocolInfo> readProtocols() throws GuacamoleException { | ||||
|  | ||||
| @@ -227,13 +205,13 @@ public class LocalEnvironment implements Environment { | ||||
|         // Read protocols from directory if it exists | ||||
|         if (protocol_directory.isDirectory()) { | ||||
|  | ||||
|             // Get all XML files | ||||
|             // Get all JSON files | ||||
|             File[] files = protocol_directory.listFiles( | ||||
|                 new FilenameFilter() { | ||||
|  | ||||
|                     @Override | ||||
|                     public boolean accept(File file, String string) { | ||||
|                         return string.endsWith(".xml"); | ||||
|                         return string.endsWith(".json"); | ||||
|                     } | ||||
|  | ||||
|                 } | ||||
| @@ -261,7 +239,7 @@ public class LocalEnvironment implements Environment { | ||||
|                 } | ||||
|                 catch (IOException e) { | ||||
|                     logger.error("Unable to read connection parameter information from \"{}\": {}", file.getAbsolutePath(), e.getMessage()); | ||||
|                     logger.debug("Error reading protocol XML.", e); | ||||
|                     logger.debug("Error reading protocol JSON.", e); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
| @@ -276,11 +254,18 @@ public class LocalEnvironment implements Environment { | ||||
|  | ||||
|                 InputStream stream = LocalEnvironment.class.getResourceAsStream( | ||||
|                         "/org/glyptodon/guacamole/protocols/" | ||||
|                         + protocol + ".xml"); | ||||
|                         + protocol + ".json"); | ||||
|  | ||||
|                 // Parse XML if available | ||||
|                 if (stream != null) | ||||
|                     protocols.put(protocol, readProtocol(stream)); | ||||
|                 // Parse JSON if available | ||||
|                 if (stream != null) { | ||||
|                     try { | ||||
|                         protocols.put(protocol, readProtocol(stream)); | ||||
|                     } | ||||
|                     catch (IOException e) { | ||||
|                         logger.error("Unable to read pre-defined connection parameter information for protocol \"{}\": {}", protocol, e.getMessage()); | ||||
|                         logger.debug("Error reading pre-defined protocol JSON.", e); | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|  | ||||
|   | ||||
| @@ -0,0 +1,277 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.form; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
|  | ||||
| /** | ||||
|  * Represents an arbitrary field, such as an HTTP parameter, the parameter of a | ||||
|  * remote desktop protocol, or an input field within a form. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class Field { | ||||
|  | ||||
|     /** | ||||
|      * All possible types of field. | ||||
|      */ | ||||
|     public enum Type { | ||||
|  | ||||
|         /** | ||||
|          * A text field, accepting arbitrary values. | ||||
|          */ | ||||
|         TEXT, | ||||
|  | ||||
|         /** | ||||
|          * A username field. This field type generally behaves identically to | ||||
|          * arbitrary text fields, but has semantic differences. | ||||
|          */ | ||||
|         USERNAME, | ||||
|  | ||||
|         /** | ||||
|          * A password field, whose value is sensitive and must be hidden. | ||||
|          */ | ||||
|         PASSWORD, | ||||
|  | ||||
|         /** | ||||
|          * A numeric field, whose value must contain only digits. | ||||
|          */ | ||||
|         NUMERIC, | ||||
|  | ||||
|         /** | ||||
|          * A boolean field, whose value is either blank or "true". | ||||
|          */ | ||||
|         BOOLEAN, | ||||
|  | ||||
|         /** | ||||
|          * An enumerated field, whose legal values are fully enumerated by a | ||||
|          * provided, finite list. | ||||
|          */ | ||||
|         ENUM, | ||||
|  | ||||
|         /** | ||||
|          * A text field that can span more than one line. | ||||
|          */ | ||||
|         MULTILINE | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The unique name that identifies this field. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * A human-readable name to be presented to the user. | ||||
|      */ | ||||
|     private String title; | ||||
|  | ||||
|     /** | ||||
|      * The type of this field. | ||||
|      */ | ||||
|     private Type type; | ||||
|  | ||||
|     /** | ||||
|      * The value of this field, when checked. This is only applicable to | ||||
|      * BOOLEAN fields. | ||||
|      */ | ||||
|     private String value; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all associated field options. | ||||
|      */ | ||||
|     private Collection<FieldOption> options; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with no associated name, title, or type. | ||||
|      */ | ||||
|     public Field() { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with the given name, title, and type. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public Field(String name, String title, Type type) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new BOOLEAN Parameter with the given name, title, and value. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value that should be assigned to this field if enabled. | ||||
|      */ | ||||
|     public Field(String name, String title, String value) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = Type.BOOLEAN; | ||||
|         this.value   = value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ENUM Parameter with the given name, title, and options. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this field. | ||||
|      * | ||||
|      * @param options | ||||
|      *     A collection of all possible valid options for this field. | ||||
|      */ | ||||
|     public Field(String name, String title, Collection<FieldOption> options) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = Type.ENUM; | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique name associated with this field. | ||||
|      * | ||||
|      * @return | ||||
|      *     The unique name associated with this field. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique name associated with this field. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to assign to this field. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the human-readable title associated with this field. | ||||
|      * | ||||
|      * @return | ||||
|      *     The human-readable title associated with this field. | ||||
|      */ | ||||
|     public String getTitle() { | ||||
|         return title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the title associated with this field. The title must be a human- | ||||
|      * readable string which describes accurately this field. | ||||
|      * | ||||
|      * @param title | ||||
|      *     A human-readable string describing this field. | ||||
|      */ | ||||
|     public void setTitle(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the value that should be assigned to this field if enabled. This | ||||
|      * is only applicable to BOOLEAN fields. | ||||
|      * | ||||
|      * @return | ||||
|      *     The value that should be assigned to this field if enabled. | ||||
|      */ | ||||
|     public String getValue() { | ||||
|         return value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the value that should be assigned to this field if enabled. This is | ||||
|      * only applicable to BOOLEAN fields. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value that should be assigned to this field if enabled. | ||||
|      */ | ||||
|     public void setValue(String value) { | ||||
|         this.value = value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the type of this field. | ||||
|      * | ||||
|      * @return | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public Type getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the type of this field. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this field. | ||||
|      */ | ||||
|     public void setType(Type type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of field options. Changes to this | ||||
|      * collection directly affect the available options. This is only | ||||
|      * applicable to ENUM fields. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of field options, or null if the field has no | ||||
|      *     options. | ||||
|      */ | ||||
|     public Collection<FieldOption> getOptions() { | ||||
|         return options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the options available as possible values of this field. This is | ||||
|      * only applicable to ENUM fields. | ||||
|      * | ||||
|      * @param options | ||||
|      *     The options to associate with this field. | ||||
|      */ | ||||
|     public void setOptions(Collection<FieldOption> options) { | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -22,12 +22,15 @@ | ||||
| 
 | ||||
| package org.glyptodon.guacamole.form; | ||||
| 
 | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
| 
 | ||||
| /** | ||||
|  * Describes an available legal value for an enumerated parameter. | ||||
|  * Describes an available legal value for an enumerated field. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class ParameterOption { | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class FieldOption { | ||||
| 
 | ||||
|     /** | ||||
|      * The value that will be assigned if this option is chosen. | ||||
| @@ -40,13 +43,13 @@ public class ParameterOption { | ||||
|     private String title; | ||||
| 
 | ||||
|     /** | ||||
|      * Creates a new ParameterOption with no associated value or title. | ||||
|      * Creates a new FieldOption with no associated value or title. | ||||
|      */ | ||||
|     public ParameterOption() { | ||||
|     public FieldOption() { | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Creates a new ParameterOption having the given value and title. | ||||
|      * Creates a new FieldOption having the given value and title. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value to assign if this option is chosen. | ||||
| @@ -54,11 +57,11 @@ public class ParameterOption { | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this option. | ||||
|      */ | ||||
|     public ParameterOption(String value, String title) { | ||||
|     public FieldOption(String value, String title) { | ||||
|         this.value = value; | ||||
|         this.title = title; | ||||
|     } | ||||
|      | ||||
| 
 | ||||
|     /** | ||||
|      * Returns the value that will be assigned if this option is chosen. | ||||
|      * | ||||
| @@ -0,0 +1,143 @@ | ||||
| /* | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.form; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import org.codehaus.jackson.map.annotate.JsonSerialize; | ||||
|  | ||||
| /** | ||||
|  * Information which describes logical set of fields. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL) | ||||
| public class Form { | ||||
|  | ||||
|     /** | ||||
|      * The name of this form. The form name must identify the form uniquely | ||||
|      * from other forms. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * The a human-readable title describing this form. | ||||
|      */ | ||||
|     private String title; | ||||
|  | ||||
|     /** | ||||
|      * All fields associated with this form. | ||||
|      */ | ||||
|     private Collection<Field> fields; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Form object with no associated fields. The name and title | ||||
|      * of the form are left unset as null. If no form name is provided, this | ||||
|      * form must not be used in the same context as another unnamed form. | ||||
|      */ | ||||
|     public Form() { | ||||
|         fields = new ArrayList<Field>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Form object having the given name and title, and | ||||
|      * containing the given fields. | ||||
|      * | ||||
|      * @param name | ||||
|      *     A name which uniquely identifies this form. | ||||
|      * | ||||
|      * @param title | ||||
|      *     A human-readable title describing this form. | ||||
|      * | ||||
|      * @param fields | ||||
|      *     The fields to provided within the new Form. | ||||
|      */ | ||||
|     public Form(String name, String title, Collection<Field> fields) { | ||||
|         this.fields = fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of the fields associated with this form. | ||||
|      * Changes to this collection affect the fields exposed to the user. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of fields. | ||||
|      */ | ||||
|     public Collection<Field> getFields() { | ||||
|         return fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the collection of fields associated with this form. | ||||
|      * | ||||
|      * @param fields | ||||
|      *     The collection of fields to associate with this form. | ||||
|      */ | ||||
|     public void setFields(Collection<Field> fields) { | ||||
|         this.fields = fields; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the name of this form. Form names must uniquely identify each | ||||
|      * form. | ||||
|      * | ||||
|      * @return | ||||
|      *     The name of this form, or null if the form has no name. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the name of this form. Form names must uniquely identify each form. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The name to assign to this form. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the human-readable title associated with this form. A form's | ||||
|      * title describes the form, but need not be unique. | ||||
|      * | ||||
|      * @return | ||||
|      *     A human-readable title describing this form. | ||||
|      */ | ||||
|     public String getTitle() { | ||||
|         return title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the human-readable title associated with this form. A form's title | ||||
|      * describes the form, but need not be unique. | ||||
|      * | ||||
|      * @param title | ||||
|      *     A human-readable title describing this form. | ||||
|      */ | ||||
|     public void setTitle(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,283 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.form; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
|  | ||||
| /** | ||||
|  * Represents an arbitrary parameter, such as an HTTP parameter, or the | ||||
|  * parameter of a remote desktop protocol. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
|  */ | ||||
| public class Parameter { | ||||
|  | ||||
|     /** | ||||
|      * All possible types of parameter. | ||||
|      */ | ||||
|     public enum Type { | ||||
|  | ||||
|         /** | ||||
|          * A text parameter, accepting arbitrary values. | ||||
|          */ | ||||
|         TEXT, | ||||
|  | ||||
|         /** | ||||
|          * A username parameter. This parameter type generally behaves | ||||
|          * identically to arbitrary text parameters, but has semantic | ||||
|          * differences. If credential pass-through is in use, the value for this | ||||
|          * parameter may be automatically provided using the credentials | ||||
|          * originally used by the user to authenticate. | ||||
|          */ | ||||
|         USERNAME, | ||||
|  | ||||
|         /** | ||||
|          * A password parameter, whose value is sensitive and must be hidden. If | ||||
|          * credential pass-through is in use, the value for this parameter may | ||||
|          * be automatically provided using the credentials originally used by | ||||
|          * the user to authenticate. | ||||
|          */ | ||||
|         PASSWORD, | ||||
|  | ||||
|         /** | ||||
|          * A numeric parameter, whose value must contain only digits. | ||||
|          */ | ||||
|         NUMERIC, | ||||
|  | ||||
|         /** | ||||
|          * A boolean parameter, whose value is either blank or "true". | ||||
|          */ | ||||
|         BOOLEAN, | ||||
|  | ||||
|         /** | ||||
|          * An enumerated parameter, whose legal values are fully enumerated | ||||
|          * by a provided, finite list. | ||||
|          */ | ||||
|         ENUM, | ||||
|  | ||||
|         /** | ||||
|          * A text parameter that can span more than one line. | ||||
|          */ | ||||
|         MULTILINE | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * The unique name that identifies this parameter. | ||||
|      */ | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * A human-readable name to be presented to the user. | ||||
|      */ | ||||
|     private String title; | ||||
|  | ||||
|     /** | ||||
|      * The type of this parameter. | ||||
|      */ | ||||
|     private Type type; | ||||
|  | ||||
|     /** | ||||
|      * The value of this parameter, when checked. This is only applicable to | ||||
|      * BOOLEAN parameters. | ||||
|      */ | ||||
|     private String value; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all associated parameter options. | ||||
|      */ | ||||
|     private Collection<ParameterOption> options; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with no associated name, title, or type. | ||||
|      */ | ||||
|     public Parameter() { | ||||
|         this.options = new ArrayList<ParameterOption>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new Parameter with the given name, title, and type. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this parameter. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this parameter. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this parameter. | ||||
|      */ | ||||
|     public Parameter(String name, String title, Type type) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = type; | ||||
|         this.options = new ArrayList<ParameterOption>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new BOOLEAN Parameter with the given name, title, and value. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this parameter. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this parameter. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value that should be assigned to this parameter if enabled. | ||||
|      */ | ||||
|     public Parameter(String name, String title, String value) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = Type.BOOLEAN; | ||||
|         this.value   = value; | ||||
|         this.options = new ArrayList<ParameterOption>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ENUM Parameter with the given name, title, and options. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to associate with this parameter. | ||||
|      * | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with this parameter. | ||||
|      * | ||||
|      * @param options | ||||
|      *     A collection of all possible valid options for this parameter. | ||||
|      */ | ||||
|     public Parameter(String name, String title, Collection<ParameterOption> options) { | ||||
|         this.name    = name; | ||||
|         this.title   = title; | ||||
|         this.type    = Type.ENUM; | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the unique name associated with this parameter. | ||||
|      * | ||||
|      * @return | ||||
|      *     The unique name associated with this parameter. | ||||
|      */ | ||||
|     public String getName() { | ||||
|         return name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the unique name associated with this parameter. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name to assign to this parameter. | ||||
|      */ | ||||
|     public void setName(String name) { | ||||
|         this.name = name; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the human-readable title associated with this parameter. | ||||
|      * | ||||
|      * @return | ||||
|      *     The human-readable title associated with this parameter. | ||||
|      */ | ||||
|     public String getTitle() { | ||||
|         return title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the title associated with this parameter. The title must be a | ||||
|      * human-readable string which describes accurately this parameter. | ||||
|      * | ||||
|      * @param title | ||||
|      *     A human-readable string describing this parameter. | ||||
|      */ | ||||
|     public void setTitle(String title) { | ||||
|         this.title = title; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the value that should be assigned to this parameter if enabled. | ||||
|      * This is only applicable to BOOLEAN parameters. | ||||
|      * | ||||
|      * @return | ||||
|      *     The value that should be assigned to this parameter if enabled. | ||||
|      */ | ||||
|     public String getValue() { | ||||
|         return value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the value that should be assigned to this parameter if enabled. | ||||
|      * This is only applicable to BOOLEAN parameters. | ||||
|      * | ||||
|      * @param value | ||||
|      *     The value that should be assigned to this parameter if enabled. | ||||
|      */ | ||||
|     public void setValue(String value) { | ||||
|         this.value = value; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the type of this parameter. | ||||
|      * | ||||
|      * @return | ||||
|      *     The type of this parameter. | ||||
|      */ | ||||
|     public Type getType() { | ||||
|         return type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the type of this parameter. | ||||
|      * | ||||
|      * @param type | ||||
|      *     The type of this parameter. | ||||
|      */ | ||||
|     public void setType(Type type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of parameter options. Changes to this | ||||
|      * collection directly affect the available options. This is only | ||||
|      * applicable to ENUM parameters. | ||||
|      * | ||||
|      * @return | ||||
|      *     A mutable collection of parameter options. | ||||
|      */ | ||||
|     public Collection<ParameterOption> getOptions() { | ||||
|         return options; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the options available as possible values of this parameter. This | ||||
|      * is only applicable to ENUM parameters. | ||||
|      * | ||||
|      * @param options | ||||
|      *     The options to associate with this parameter. | ||||
|      */ | ||||
|     public void setOptions(Collection<ParameterOption> options) { | ||||
|         this.options = options; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,5 +1,5 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * Copyright (C) 2015 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
| @@ -21,8 +21,7 @@ | ||||
|  */ | ||||
| 
 | ||||
| /** | ||||
|  * Classes related to parsing XML files which describe the parameters of a | ||||
|  * protocol. | ||||
|  * Provides classes which describe the contents and semantics of forms which | ||||
|  * may be presented to the user. | ||||
|  */ | ||||
| package org.glyptodon.guacamole.xml.protocol; | ||||
| 
 | ||||
| package org.glyptodon.guacamole.form; | ||||
| @@ -24,7 +24,7 @@ package org.glyptodon.guacamole.net.auth; | ||||
|  | ||||
| import java.util.Collection; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.form.Parameter; | ||||
| import org.glyptodon.guacamole.form.Field; | ||||
|  | ||||
| /** | ||||
|  * The context of an active user. The functions of this class enforce all | ||||
| @@ -121,7 +121,7 @@ public interface UserContext { | ||||
|      * @return | ||||
|      *     A collection of all attributes applicable to users. | ||||
|      */ | ||||
|     Collection<Parameter> getUserAttributes(); | ||||
|     Collection<Field> getUserAttributes(); | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a collection of all attributes applicable to connections. This | ||||
| @@ -132,7 +132,7 @@ public interface UserContext { | ||||
|      * @return | ||||
|      *     A collection of all attributes applicable to connections. | ||||
|      */ | ||||
|     Collection<Parameter> getConnectionAttributes(); | ||||
|     Collection<Field> getConnectionAttributes(); | ||||
|  | ||||
|     /** | ||||
|      * Retrieves a collection of all attributes applicable to connection | ||||
| @@ -143,6 +143,6 @@ public interface UserContext { | ||||
|      * @return | ||||
|      *     A collection of all attributes applicable to connection groups. | ||||
|      */ | ||||
|     Collection<Parameter> getConnectionGroupAttributes(); | ||||
|     Collection<Field> getConnectionGroupAttributes(); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -25,7 +25,7 @@ package org.glyptodon.guacamole.net.auth.credentials; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collection; | ||||
| import java.util.Collections; | ||||
| import org.glyptodon.guacamole.form.Parameter; | ||||
| import org.glyptodon.guacamole.form.Field; | ||||
|  | ||||
| /** | ||||
|  * Information which describes a set of valid credentials. | ||||
| @@ -35,45 +35,45 @@ import org.glyptodon.guacamole.form.Parameter; | ||||
| public class CredentialsInfo { | ||||
|  | ||||
|     /** | ||||
|      * All parameters required for valid credentials. | ||||
|      * All fields required for valid credentials. | ||||
|      */ | ||||
|     private final Collection<Parameter> parameters; | ||||
|     private final Collection<Field> fields; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new CredentialsInfo object which requires the given parameters | ||||
|      * for any conforming credentials. | ||||
|      * Creates a new CredentialsInfo object which requires the given fields for | ||||
|      * any conforming credentials. | ||||
|      * | ||||
|      * @param parameters | ||||
|      *     The parameters to require. | ||||
|      * @param fields | ||||
|      *     The fields to require. | ||||
|      */ | ||||
|     public CredentialsInfo(Collection<Parameter> parameters) { | ||||
|         this.parameters = parameters; | ||||
|     public CredentialsInfo(Collection<Field> fields) { | ||||
|         this.fields = fields; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Returns all parameters required for valid credentials as described by | ||||
|      * this object. | ||||
|      * Returns all fields required for valid credentials as described by this | ||||
|      * object. | ||||
|      * | ||||
|      * @return | ||||
|      *     All parameters required for valid credentials. | ||||
|      *     All fields required for valid credentials. | ||||
|      */ | ||||
|     public Collection<Parameter> getParameters() { | ||||
|         return Collections.unmodifiableCollection(parameters); | ||||
|     public Collection<Field> getFields() { | ||||
|         return Collections.unmodifiableCollection(fields); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * CredentialsInfo object which describes empty credentials. No parameters | ||||
|      * are required. | ||||
|      * CredentialsInfo object which describes empty credentials. No fields are | ||||
|      * required. | ||||
|      */ | ||||
|     public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.<Parameter>emptyList()); | ||||
|     public static final CredentialsInfo EMPTY = new CredentialsInfo(Collections.<Field>emptyList()); | ||||
|  | ||||
|     /** | ||||
|      * CredentialsInfo object which describes standard username/password | ||||
|      * credentials. | ||||
|      */ | ||||
|     public static final CredentialsInfo USERNAME_PASSWORD = new CredentialsInfo(Arrays.asList( | ||||
|         new Parameter("username", "username", Parameter.Type.USERNAME), | ||||
|         new Parameter("password", "password", Parameter.Type.PASSWORD) | ||||
|         new Field("username", "username", Field.Type.USERNAME), | ||||
|         new Field("password", "password", Field.Type.PASSWORD) | ||||
|     )); | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -28,7 +28,7 @@ import java.util.Collections; | ||||
| import java.util.Map; | ||||
| import java.util.UUID; | ||||
| import org.glyptodon.guacamole.GuacamoleException; | ||||
| import org.glyptodon.guacamole.form.Parameter; | ||||
| import org.glyptodon.guacamole.form.Field; | ||||
| import org.glyptodon.guacamole.net.auth.ActiveConnection; | ||||
| import org.glyptodon.guacamole.net.auth.Connection; | ||||
| import org.glyptodon.guacamole.net.auth.ConnectionGroup; | ||||
| @@ -176,18 +176,18 @@ public class SimpleUserContext implements UserContext { | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Parameter> getUserAttributes() { | ||||
|         return Collections.<Parameter>emptyList(); | ||||
|     public Collection<Field> getUserAttributes() { | ||||
|         return Collections.<Field>emptyList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Parameter> getConnectionAttributes() { | ||||
|         return Collections.<Parameter>emptyList(); | ||||
|     public Collection<Field> getConnectionAttributes() { | ||||
|         return Collections.<Field>emptyList(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Collection<Parameter> getConnectionGroupAttributes() { | ||||
|         return Collections.<Parameter>emptyList(); | ||||
|     public Collection<Field> getConnectionGroupAttributes() { | ||||
|         return Collections.<Field>emptyList(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -24,11 +24,11 @@ package org.glyptodon.guacamole.protocols; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import org.glyptodon.guacamole.form.Parameter; | ||||
| import org.glyptodon.guacamole.form.Form; | ||||
|  | ||||
| /** | ||||
|  * Describes a protocol and all parameters associated with it, as required by | ||||
|  * a protocol plugin for guacd. This class allows known parameters for a | ||||
|  * Describes a protocol and all forms associated with it, as required by | ||||
|  * a protocol plugin for guacd. This class allows known forms for a | ||||
|  * protocol to be exposed to the user as friendly fields. | ||||
|  * | ||||
|  * @author Michael Jumper | ||||
| @@ -46,21 +46,21 @@ public class ProtocolInfo { | ||||
|     private String name; | ||||
|  | ||||
|     /** | ||||
|      * A collection of all associated protocol parameters. | ||||
|      * A collection of all associated protocol forms. | ||||
|      */ | ||||
|     private Collection<Parameter> parameters; | ||||
|     private Collection<Form> forms; | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo with no associated name, title, or | ||||
|      * parameters. | ||||
|      * forms. | ||||
|      */ | ||||
|     public ProtocolInfo() { | ||||
|         this.parameters = new ArrayList<Parameter>(); | ||||
|         this.forms = new ArrayList<Form>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo having the given name and title, but without | ||||
|      * any parameters. | ||||
|      * any forms. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name associated with the protocol. | ||||
| @@ -69,13 +69,13 @@ public class ProtocolInfo { | ||||
|      *     The human-readable title to associate with the protocol. | ||||
|      */ | ||||
|     public ProtocolInfo(String name, String title) { | ||||
|         this.name       = name; | ||||
|         this.title      = title; | ||||
|         this.parameters = new ArrayList<Parameter>(); | ||||
|         this.name  = name; | ||||
|         this.title = title; | ||||
|         this.forms = new ArrayList<Form>(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Creates a new ProtocolInfo having the given name, title, and parameters. | ||||
|      * Creates a new ProtocolInfo having the given name, title, and forms. | ||||
|      * | ||||
|      * @param name | ||||
|      *     The unique name associated with the protocol. | ||||
| @@ -83,13 +83,13 @@ public class ProtocolInfo { | ||||
|      * @param title | ||||
|      *     The human-readable title to associate with the protocol. | ||||
|      *  | ||||
|      * @param parameters | ||||
|      *     The parameters to associate with the protocol. | ||||
|      * @param forms | ||||
|      *     The forms to associate with the protocol. | ||||
|      */ | ||||
|     public ProtocolInfo(String name, String title, Collection<Parameter> parameters) { | ||||
|         this.name       = name; | ||||
|         this.title      = title; | ||||
|         this.parameters = parameters; | ||||
|     public ProtocolInfo(String name, String title, Collection<Form> forms) { | ||||
|         this.name  = name; | ||||
|         this.title = title; | ||||
|         this.forms = forms; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -131,25 +131,25 @@ public class ProtocolInfo { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns a mutable collection of the protocol parameters associated with | ||||
|      * this protocol. Changes to this collection affect the parameters exposed | ||||
|      * Returns a mutable collection of the protocol forms associated with | ||||
|      * this protocol. Changes to this collection affect the forms exposed | ||||
|      * to the user. | ||||
|      * | ||||
|      * @return A mutable collection of protocol parameters. | ||||
|      * @return A mutable collection of protocol forms. | ||||
|      */ | ||||
|     public Collection<Parameter> getParameters() { | ||||
|         return parameters; | ||||
|     public Collection<Form> getForms() { | ||||
|         return forms; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sets the collection of protocol parameters associated with this | ||||
|      * Sets the collection of protocol forms associated with this | ||||
|      * protocol. | ||||
|      * | ||||
|      * @param parameters | ||||
|      *     The collection of parameters to associate with this protocol. | ||||
|      * @param forms | ||||
|      *     The collection of forms to associate with this protocol. | ||||
|      */ | ||||
|     public void setParameters(Collection<Parameter> parameters) { | ||||
|         this.parameters = parameters; | ||||
|     public void setForms(Collection<Form> forms) { | ||||
|         this.forms = forms; | ||||
|     } | ||||
|      | ||||
| } | ||||
|   | ||||
| @@ -1,65 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.xml.protocol; | ||||
|  | ||||
| import org.glyptodon.guacamole.form.ParameterOption; | ||||
| import org.glyptodon.guacamole.xml.TagHandler; | ||||
| import org.xml.sax.Attributes; | ||||
| import org.xml.sax.SAXException; | ||||
|  | ||||
| /** | ||||
|  * TagHandler for the "option" element. | ||||
|  * | ||||
|  * @author Mike Jumper | ||||
|  */ | ||||
| public class OptionTagHandler implements TagHandler { | ||||
|  | ||||
|     /** | ||||
|      * The option backing this option tag. | ||||
|      */ | ||||
|     private ParameterOption option = new ParameterOption(); | ||||
|  | ||||
|     @Override | ||||
|     public void init(Attributes attributes) throws SAXException { | ||||
|         option.setValue(attributes.getValue("value")); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TagHandler childElement(String localName) throws SAXException { | ||||
|         throw new SAXException("The 'param' tag can contain no elements."); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void complete(String textContent) throws SAXException { | ||||
|         option.setTitle(textContent); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the ParameterOption backing this tag. | ||||
|      * @return The ParameterOption backing this tag. | ||||
|      */ | ||||
|     public ParameterOption asParameterOption() { | ||||
|         return option; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,124 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.xml.protocol; | ||||
|  | ||||
| import org.glyptodon.guacamole.form.Parameter; | ||||
| import org.glyptodon.guacamole.xml.TagHandler; | ||||
| import org.xml.sax.Attributes; | ||||
| import org.xml.sax.SAXException; | ||||
|  | ||||
| /** | ||||
|  * TagHandler for the "param" element. | ||||
|  * | ||||
|  * @author Mike Jumper | ||||
|  */ | ||||
| public class ParamTagHandler implements TagHandler { | ||||
|  | ||||
|     /** | ||||
|      * The Parameter backing this tag handler. | ||||
|      */ | ||||
|     private Parameter protocolParameter = new Parameter(); | ||||
|  | ||||
|     @Override | ||||
|     public void init(Attributes attributes) throws SAXException { | ||||
|  | ||||
|         protocolParameter.setName(attributes.getValue("name")); | ||||
|         protocolParameter.setTitle(attributes.getValue("title")); | ||||
|         protocolParameter.setValue(attributes.getValue("value")); | ||||
|  | ||||
|         // Parse type | ||||
|         String type = attributes.getValue("type"); | ||||
|  | ||||
|         // Text field | ||||
|         if ("text".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.TEXT); | ||||
|  | ||||
|         // Numeric field | ||||
|         else if ("numeric".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.NUMERIC); | ||||
|  | ||||
|         // Username field | ||||
|         else if ("username".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.USERNAME); | ||||
|  | ||||
|         // Password field | ||||
|         else if ("password".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.PASSWORD); | ||||
|  | ||||
|         // Enumerated field | ||||
|         else if ("enum".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.ENUM); | ||||
|  | ||||
|         // Multiline field | ||||
|         else if ("multiline".equals(type)) | ||||
|             protocolParameter.setType(Parameter.Type.MULTILINE); | ||||
|  | ||||
|         // Boolean field | ||||
|         else if ("boolean".equals(type)) { | ||||
|             protocolParameter.setType(Parameter.Type.BOOLEAN); | ||||
|  | ||||
|             if(protocolParameter.getValue() == null) | ||||
|                 throw new SAXException | ||||
|                         ("A value is required for the boolean parameter type."); | ||||
|         } | ||||
|  | ||||
|         // Otherwise, fail with unrecognized type | ||||
|         else | ||||
|             throw new SAXException("Invalid parameter type: " + type); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TagHandler childElement(String localName) throws SAXException { | ||||
|  | ||||
|         // Start parsing of option tags | ||||
|         if (localName.equals("option")) { | ||||
|  | ||||
|             // Get tag handler for option tag | ||||
|             OptionTagHandler tagHandler = new OptionTagHandler(); | ||||
|  | ||||
|             // Store stub in options collection | ||||
|             protocolParameter.getOptions().add( | ||||
|                 tagHandler.asParameterOption()); | ||||
|             return tagHandler; | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void complete(String textContent) throws SAXException { | ||||
|         // Do nothing | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the Parameter backing this tag. | ||||
|      * @return The Parameter backing this tag. | ||||
|      */ | ||||
|     public Parameter asParameter() { | ||||
|         return protocolParameter; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,81 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (C) 2013 Glyptodon LLC | ||||
|  * | ||||
|  * Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
|  * of this software and associated documentation files (the "Software"), to deal | ||||
|  * in the Software without restriction, including without limitation the rights | ||||
|  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
|  * copies of the Software, and to permit persons to whom the Software is | ||||
|  * furnished to do so, subject to the following conditions: | ||||
|  * | ||||
|  * The above copyright notice and this permission notice shall be included in | ||||
|  * all copies or substantial portions of the Software. | ||||
|  * | ||||
|  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
|  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
|  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
|  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
|  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
|  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
|  * THE SOFTWARE. | ||||
|  */ | ||||
|  | ||||
| package org.glyptodon.guacamole.xml.protocol; | ||||
|  | ||||
| import org.glyptodon.guacamole.protocols.ProtocolInfo; | ||||
| import org.glyptodon.guacamole.xml.TagHandler; | ||||
| import org.xml.sax.Attributes; | ||||
| import org.xml.sax.SAXException; | ||||
|  | ||||
| /** | ||||
|  * TagHandler for the "protocol" element. | ||||
|  * | ||||
|  * @author Mike Jumper | ||||
|  */ | ||||
| public class ProtocolTagHandler implements TagHandler { | ||||
|  | ||||
|     /** | ||||
|      * The ProtocolInfo object which will contain all data parsed by this tag | ||||
|      * handler. | ||||
|      */ | ||||
|     private ProtocolInfo info = new ProtocolInfo(); | ||||
|  | ||||
|     @Override | ||||
|     public void init(Attributes attributes) throws SAXException { | ||||
|         info.setName(attributes.getValue("name")); | ||||
|         info.setTitle(attributes.getValue("title")); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public TagHandler childElement(String localName) throws SAXException { | ||||
|  | ||||
|         // Start parsing of param tags, add to list of all parameters | ||||
|         if (localName.equals("param")) { | ||||
|  | ||||
|             // Get tag handler for param tag | ||||
|             ParamTagHandler tagHandler = new ParamTagHandler(); | ||||
|  | ||||
|             // Store stub in parameters collection | ||||
|             info.getParameters().add(tagHandler.asParameter()); | ||||
|             return tagHandler; | ||||
|  | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void complete(String textContent) throws SAXException { | ||||
|         // Do nothing | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Returns the ProtocolInfo backing this tag. | ||||
|      * @return The ProtocolInfo backing this tag. | ||||
|      */ | ||||
|     public ProtocolInfo asProtocolInfo() { | ||||
|         return info; | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user