1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 20 package org.apache.guacamole.form; 21 22 import java.util.Collection; 23 24 /** 25 * Represents a basic text field. The field may generally contain any data, but 26 * may not contain multiple lines. 27 */ 28 public class TextField extends Field { 29 30 /** 31 * Creates a new TextField with the given name. 32 * 33 * @param name 34 * The unique name to associate with this field. 35 */ TextField(String name)36 public TextField(String name) { 37 super(name, Field.Type.TEXT); 38 } 39 40 /** 41 * Creates a new TextField with the given name and possible values. As a 42 * text field may contain any data by definition, any provided options are 43 * simply known-good values. 44 * 45 * @param name 46 * The unique name to associate with this field. 47 * 48 * @param options 49 * A set of known legal options for this field. 50 */ TextField(String name, Collection<String> options)51 public TextField(String name, Collection<String> options) { 52 super(name, Field.Type.TEXT, options); 53 } 54 55 /** 56 * Parses the given string, interpreting empty strings as equivalent to 57 * null. For all other cases, the given string is returned verbatim. 58 * 59 * @param str 60 * The string to parse, which may be null. 61 * 62 * @return 63 * The given string, or null if the given string was null or empty. 64 */ parse(String str)65 public static String parse(String str) { 66 67 // Return null if no value provided 68 if (str == null || str.isEmpty()) 69 return null; 70 71 // Otherwise, return string unmodified 72 return str; 73 74 } 75 76 } 77