[4838] | 1 | /**
|
---|
| 2 | *#########################################################################
|
---|
| 3 | *
|
---|
[6389] | 4 | * A component of the Greenstone Librarian Interface (GLI) application,
|
---|
| 5 | * part of the Greenstone digital library software suite from the New
|
---|
| 6 | * Zealand Digital Library Project at the University of Waikato,
|
---|
| 7 | * New Zealand.
|
---|
[4838] | 8 | *
|
---|
[6389] | 9 | * Author: John Thompson
|
---|
| 10 | * Greenstone Project, New Zealand Digital Library
|
---|
| 11 | * University of Waikato
|
---|
| 12 | * http://www.nzdl.org
|
---|
[4838] | 13 | *
|
---|
[6389] | 14 | * Copyright (C) 2004 New Zealand Digital Library, University of Waikato
|
---|
[4838] | 15 | *
|
---|
| 16 | * This program is free software; you can redistribute it and/or modify
|
---|
| 17 | * it under the terms of the GNU General Public License as published by
|
---|
| 18 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 19 | * (at your option) any later version.
|
---|
| 20 | *
|
---|
| 21 | * This program is distributed in the hope that it will be useful,
|
---|
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 24 | * GNU General Public License for more details.
|
---|
| 25 | *
|
---|
| 26 | * You should have received a copy of the GNU General Public License
|
---|
| 27 | * along with this program; if not, write to the Free Software
|
---|
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 29 | *########################################################################
|
---|
| 30 | */
|
---|
[6389] | 31 |
|
---|
[4932] | 32 | package org.greenstone.gatherer.cdm;
|
---|
[4838] | 33 |
|
---|
[4932] | 34 | import java.io.*;
|
---|
| 35 | import java.util.*;
|
---|
[6389] | 36 | import org.greenstone.gatherer.Configuration;
|
---|
[8236] | 37 | import org.greenstone.gatherer.DebugStream;
|
---|
[4932] | 38 | import org.greenstone.gatherer.Gatherer;
|
---|
| 39 | import org.greenstone.gatherer.collection.Collection;
|
---|
| 40 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
[8313] | 41 | import org.greenstone.gatherer.metadata.MetadataElement;
|
---|
| 42 | import org.greenstone.gatherer.metadata.MetadataTools;
|
---|
[4932] | 43 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
[12824] | 44 | import org.greenstone.gatherer.util.Utility;
|
---|
[8015] | 45 | import org.greenstone.gatherer.util.XMLTools;
|
---|
[4932] | 46 | import org.w3c.dom.*;
|
---|
| 47 |
|
---|
[4838] | 48 | /** This class contains all the details about a single argument that can be passed to this plugin, including option lists if the parameters are restricted.
|
---|
[6389] | 49 | * @author John Thompson, Greenstone Project, New Zealand Digital Library, University of Waikato
|
---|
| 50 | * @version 2.41 final
|
---|
[4838] | 51 | */
|
---|
| 52 | public class Argument
|
---|
| 53 | implements Comparable, Serializable {
|
---|
[6389] | 54 | /** An element of the argument type enumeration specifying a combobox control. */
|
---|
[4838] | 55 | static final public byte ENUM = 0;
|
---|
[6389] | 56 | /** An element of the argument type enumeration specifying a checkbox control. */
|
---|
[4838] | 57 | static final public byte FLAG = 1;
|
---|
[6389] | 58 | /** An element of the argument type enumeration specifying a tree control. */
|
---|
[4838] | 59 | static final public byte HIERARCHY = 2;
|
---|
[6389] | 60 | /** An element of the argument type enumeration specifying a spinner control. */
|
---|
[4838] | 61 | static final public byte INTEGER = 3;
|
---|
[6389] | 62 | /** An element of the argument type enumeration specifying a language combobox control. */
|
---|
[4838] | 63 | static final public byte LANGUAGE = 4;
|
---|
[6389] | 64 | /** An element of the argument type enumeration specifying a list control. */
|
---|
[4838] | 65 | static final public byte METADATA = 5;
|
---|
[6389] | 66 | /** An element of the argument type enumeration specifying a metadata combobox control. */
|
---|
[4838] | 67 | static final public byte METADATUM = 6;
|
---|
[6389] | 68 | /** An element of the argument type enumeration specifying a text field. */
|
---|
[4838] | 69 | static final public byte STRING = 7;
|
---|
[6389] | 70 | /** An element of the argument type enumeration specifying a regular expression text field. */
|
---|
| 71 | static final public byte REGEXP = 8;
|
---|
[11344] | 72 | /** An element of the argument type enumeration specifying a metadata set combobox control. */
|
---|
| 73 | static final public byte METADATA_SET_NAMESPACE = 9;
|
---|
[12466] | 74 |
|
---|
| 75 | ///////////kk added the number was 9, I changed it to 10//////////////
|
---|
| 76 | /** An element of the argument type enumeration specifying a text field. */
|
---|
| 77 | static final public byte URL = 10;
|
---|
| 78 | /////////////////////////////////////////////////////////////////
|
---|
| 79 |
|
---|
[11283] | 80 | /** true if this argument should actually be hidden within the GLI. This is important for arguments such as import dir or other location critical arguments. */
|
---|
[6389] | 81 | private boolean hidden_gli = false;
|
---|
[4932] | 82 | /** <i>true</i> if this argument is required for the applicable script to work properly, <i>false</i> otherwise. */
|
---|
| 83 | private boolean required = false;
|
---|
[6389] | 84 | /** The type of this argument. Used to be an int, but bytes are cheaper. */
|
---|
[4932] | 85 | private byte type = STRING;
|
---|
[6087] | 86 | /** The maximum value an integer based control can have. */
|
---|
| 87 | private int maximum = Integer.MAX_VALUE;
|
---|
| 88 | /** The minimum value an integer based control can have. */
|
---|
| 89 | private int minimum = Integer.MIN_VALUE;
|
---|
[6389] | 90 | /** Every argument has a detail mode level at which it becomes available to the user to edit.
|
---|
| 91 | * @see org.greenstone.gatherer.Configuration
|
---|
| 92 | */
|
---|
| 93 | private int mode_level = Configuration.LIBRARIAN_MODE;
|
---|
| 94 | /** The DOM element this argument is built around, if any. */
|
---|
[4932] | 95 | private Element element;
|
---|
| 96 | /** If the argument is of type ENUM then this map holds all the various options. Each entry is an <option value> -> <description> mapping. */
|
---|
[12824] | 97 | private ArrayList option_list = null;
|
---|
[4932] | 98 | /** A default value for parameter-type arguments. May be a Perl pattern. */
|
---|
| 99 | private String default_value = null;
|
---|
| 100 | /** The text description of this argument parsed from the pluginfo output. */
|
---|
| 101 | private String description = null;
|
---|
| 102 | /** The argument flag as it appears in the command. Also used as the unique identifier of an argument. */
|
---|
| 103 | private String name = null;
|
---|
| 104 | /** The plugin that owns this argument, for the purposes of visualising inheritance. */
|
---|
| 105 | private String owner = null;
|
---|
| 106 |
|
---|
[12466] | 107 | private String display_name = null;
|
---|
| 108 |
|
---|
[4838] | 109 | /** Default Constructor. */
|
---|
| 110 | public Argument() {
|
---|
| 111 | }
|
---|
[4932] | 112 |
|
---|
[6389] | 113 | /** Another constructor but this one is a little more interesting as it takes a DOM element.
|
---|
| 114 | * @param element the Element this argument is based around
|
---|
| 115 | */
|
---|
[4932] | 116 | public Argument(Element element) {
|
---|
| 117 | this.element = element;
|
---|
[4838] | 118 | }
|
---|
[4932] | 119 |
|
---|
[12824] | 120 | /** Method to add an element to the option_list.
|
---|
[6389] | 121 | * @param name the name value of the option as a String
|
---|
| 122 | * @param desc the description of this options as a String
|
---|
[4932] | 123 | */
|
---|
[4838] | 124 | public void addOption(String name, String desc) {
|
---|
| 125 | if(type == ENUM && name != null) {
|
---|
| 126 | if(desc == null) {
|
---|
| 127 | desc = "";
|
---|
| 128 | }
|
---|
[12824] | 129 | if(option_list == null) {
|
---|
| 130 | option_list = new ArrayList();
|
---|
[4838] | 131 | }
|
---|
[12824] | 132 | option_list.add(new ArgumentOption(name, desc));
|
---|
[4838] | 133 | }
|
---|
| 134 | }
|
---|
[4932] | 135 |
|
---|
[4838] | 136 | /** Method to compare two arguments for ordering.
|
---|
[6389] | 137 | * @param object the argument we are comparing to, as an Object
|
---|
| 138 | * @return an int specifying the argument order, using values as set out in String
|
---|
[4932] | 139 | * @see org.greenstone.gatherer.cdm.Argument
|
---|
| 140 | */
|
---|
[4838] | 141 | public int compareTo(Object object) {
|
---|
[4932] | 142 | if(object instanceof Argument) {
|
---|
| 143 | return getName().compareTo(((Argument)object).getName());
|
---|
| 144 | }
|
---|
| 145 | else {
|
---|
| 146 | return toString().compareTo(object.toString());
|
---|
| 147 | }
|
---|
[4838] | 148 | }
|
---|
[4932] | 149 |
|
---|
[6389] | 150 | /** Create a copy of this argument.
|
---|
| 151 | * @return a newly created Argument with the same details as this one
|
---|
| 152 | */
|
---|
[4838] | 153 | public Argument copy() {
|
---|
[4932] | 154 | Argument copy = new Argument();
|
---|
| 155 | copy.setDefaultValue(default_value);
|
---|
| 156 | copy.setDescription(description);
|
---|
[12824] | 157 | copy.setOptions(option_list);
|
---|
[4932] | 158 | copy.setOwner(owner);
|
---|
| 159 | copy.setName(name);
|
---|
[4838] | 160 | copy.setRequired(required);
|
---|
[4932] | 161 | copy.setType(type);
|
---|
[7108] | 162 | copy.setMinimum(minimum);
|
---|
| 163 | copy.setMaximum(maximum);
|
---|
| 164 | copy.setModeLevel(mode_level);
|
---|
[11283] | 165 | copy.setHiddenGLI(hidden_gli);
|
---|
[4838] | 166 | return copy;
|
---|
| 167 | }
|
---|
[4932] | 168 |
|
---|
[4838] | 169 | /** Method to determine if two arguments are equal.
|
---|
[6389] | 170 | * @param object the argument to test against, as an Object
|
---|
| 171 | * @return true if the arguments names match, false otherwise
|
---|
[4932] | 172 | */
|
---|
[4838] | 173 | public boolean equals(Object object) {
|
---|
| 174 | return (compareTo(object) == 0);
|
---|
| 175 | }
|
---|
[4932] | 176 |
|
---|
[4838] | 177 | /** Method to retrieve the value of default_value.
|
---|
[6389] | 178 | * @return a String containing the default value
|
---|
[4932] | 179 | */
|
---|
[4838] | 180 | public String getDefaultValue() {
|
---|
| 181 | return default_value;
|
---|
| 182 | }
|
---|
[4932] | 183 |
|
---|
[4838] | 184 | /** Method to retrieve this arguments description.
|
---|
[6389] | 185 | * @return a String containing the description
|
---|
[4932] | 186 | */
|
---|
| 187 | public String getDescription() {
|
---|
| 188 | return description;
|
---|
[4838] | 189 | }
|
---|
[4932] | 190 |
|
---|
[12251] | 191 | public Element getElement() {
|
---|
| 192 | return element;
|
---|
| 193 | }
|
---|
[6389] | 194 | /** Retrieve the upper bound of a range based argument.
|
---|
| 195 | * @return the maximum as an int
|
---|
| 196 | */
|
---|
[6087] | 197 | public int getMaximum() {
|
---|
| 198 | return maximum;
|
---|
| 199 | }
|
---|
| 200 |
|
---|
[6389] | 201 | /** Retrieve the lower bound of a range based argument.
|
---|
| 202 | * @return the minimum as an int
|
---|
| 203 | */
|
---|
[6087] | 204 | public int getMinimum() {
|
---|
| 205 | return minimum;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[6389] | 208 | /** Retrieves the mode level at which this argument should become available. Any higher levels should also see this argument.
|
---|
| 209 | * @return the mode level as an int
|
---|
[4932] | 210 | */
|
---|
[6389] | 211 | public int getModeLevel() {
|
---|
| 212 | return mode_level;
|
---|
[4838] | 213 | }
|
---|
[4932] | 214 |
|
---|
[4838] | 215 | /** Method to retrieve the value of name.
|
---|
[6389] | 216 | * @return a String containing the argument name
|
---|
| 217 | * @see org.greenstone.gatherer.util.StaticStrings#NAME_ATTRIBUTE
|
---|
[4932] | 218 | */
|
---|
[4838] | 219 | public String getName() {
|
---|
[4932] | 220 | if(name == null && element != null) {
|
---|
| 221 | name = element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
| 222 | }
|
---|
[4838] | 223 | return name;
|
---|
| 224 | }
|
---|
[4932] | 225 |
|
---|
[12466] | 226 | public String getDisplayName() {
|
---|
| 227 | return display_name;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 |
|
---|
[6389] | 231 | /** Method to retrieve the option list for this argument.
|
---|
| 232 | * @return a HashMap containing <option value> -> <description> entries
|
---|
| 233 | */
|
---|
[12824] | 234 | public ArrayList getOptions() {
|
---|
| 235 | return option_list;
|
---|
[6389] | 236 | }
|
---|
| 237 |
|
---|
[4838] | 238 | /** Retrieve the name of the owner of this argument.
|
---|
[6389] | 239 | * @return the owners name as a String
|
---|
[4932] | 240 | */
|
---|
[4838] | 241 | public String getOwner() {
|
---|
| 242 | return owner;
|
---|
| 243 | }
|
---|
[4932] | 244 |
|
---|
[4838] | 245 | /** Method to determine the type of this argument.
|
---|
[6389] | 246 | * @return a byte specifying the type
|
---|
[4932] | 247 | */
|
---|
[4838] | 248 | public byte getType() {
|
---|
| 249 | return type;
|
---|
| 250 | }
|
---|
[4932] | 251 |
|
---|
[4838] | 252 | /** Method to retrieve the value of value.
|
---|
[6389] | 253 | * @return the value of value as a String
|
---|
| 254 | * @see org.greenstone.gatherer.Gatherer#c_man
|
---|
| 255 | * @see org.greenstone.gatherer.collection.CollectionManager#getCollection
|
---|
[4932] | 256 | */
|
---|
[8313] | 257 | public String getValue()
|
---|
| 258 | {
|
---|
| 259 | // Only assigned arguments have values.
|
---|
| 260 | if (element == null) {
|
---|
| 261 | return null;
|
---|
[4838] | 262 | }
|
---|
[4932] | 263 |
|
---|
[8313] | 264 | return XMLTools.getValue(element);
|
---|
[4838] | 265 | }
|
---|
[4932] | 266 |
|
---|
[8313] | 267 |
|
---|
[4838] | 268 | /** Method to determine if this argument has been assigned.
|
---|
[6389] | 269 | * @return true if it has, false otherwise
|
---|
| 270 | * @see org.greenstone.gatherer.util.StaticStrings#ASSIGNED_ATTRIBUTE
|
---|
| 271 | * @see org.greenstone.gatherer.util.StaticStrings#TRUE_STR
|
---|
[4932] | 272 | */
|
---|
[4838] | 273 | public boolean isAssigned() {
|
---|
[4932] | 274 | return (element != null && element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
[4838] | 275 | }
|
---|
[4932] | 276 |
|
---|
[12466] | 277 | /** Determine if this is a custom argument ie one that has been parsed from the config file but doesn't have a matching entry in the argument library.
|
---|
| 278 | * @return true if this argument is a custom, false otherwise
|
---|
| 279 | * @see org.greenstone.gatherer.util.StaticStrings#CUSTOM_ATTRIBUTE
|
---|
| 280 | * @see org.greenstone.gatherer.util.StaticStrings#TRUE_STR
|
---|
| 281 | */
|
---|
| 282 | public boolean isCustomArgument() {
|
---|
| 283 | return (element != null && element.getAttribute(StaticStrings.CUSTOM_ATTRIBUTE).equals(StaticStrings.TRUE_STR));
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[6389] | 286 | /** Determine if this argument is hidden in GLI
|
---|
| 287 | * @return true if the argument is hidden, false otherwise
|
---|
| 288 | */
|
---|
| 289 | public boolean isHiddenGLI() {
|
---|
| 290 | return hidden_gli;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
[4838] | 293 | /** Method to determine of this argument is required for the associated script to work.
|
---|
[6389] | 294 | * @return true if this argument is required, false otherwise
|
---|
[4932] | 295 | */
|
---|
[4838] | 296 | public boolean isRequired() {
|
---|
| 297 | return required;
|
---|
| 298 | }
|
---|
[4932] | 299 |
|
---|
[4838] | 300 | /** Method to allow for the activation of arguments that might never have their setValue() method called.
|
---|
[4932] | 301 | * @param assigned the desired state as a boolean
|
---|
[6389] | 302 | * @see org.greenstone.gatherer.util.StaticStrings#ASSIGNED_ATTRIBUTE
|
---|
| 303 | * @see org.greenstone.gatherer.util.StaticStrings#FALSE_STR
|
---|
| 304 | * @see org.greenstone.gatherer.util.StaticStrings#TRUE_STR
|
---|
[4932] | 305 | */
|
---|
| 306 | public void setAssigned(boolean assigned) {
|
---|
| 307 | if(element != null) {
|
---|
| 308 | element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
|
---|
[4838] | 309 | }
|
---|
[4932] | 310 | }
|
---|
| 311 |
|
---|
[4838] | 312 | /** Sets the value of default_value.
|
---|
[4932] | 313 | * @param default_value The new value for default_value as a <strong>String</strong>.
|
---|
| 314 | */
|
---|
| 315 | public void setDefaultValue(String default_value) {
|
---|
| 316 | this.default_value = default_value;
|
---|
[4838] | 317 | }
|
---|
[4932] | 318 |
|
---|
[4838] | 319 | /** Set the value of desc.
|
---|
[6389] | 320 | * @param description the new value of desc as a String
|
---|
[4932] | 321 | */
|
---|
| 322 | public void setDescription(String description) {
|
---|
| 323 | this.description = description;
|
---|
[4838] | 324 | }
|
---|
| 325 |
|
---|
[6389] | 326 | /** Set the element this argument should be based upon.
|
---|
| 327 | * @param element the Element
|
---|
| 328 | */
|
---|
[4932] | 329 | public void setElement(Element element) {
|
---|
[4838] | 330 | this.element = element;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[6389] | 333 | /** Mark this argument as being hidden in GLI. */
|
---|
[11283] | 334 | public void setHiddenGLI(boolean hidden) {
|
---|
| 335 | this.hidden_gli = hidden;
|
---|
[6389] | 336 | }
|
---|
| 337 |
|
---|
| 338 | /** Set the upper bound for a range type argument.
|
---|
| 339 | * @param maximum the maximum as an int
|
---|
| 340 | */
|
---|
[6087] | 341 | public void setMaximum(int maximum) {
|
---|
| 342 | this.maximum = maximum;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[6389] | 345 | /** Set the lower bound for a range type argument.
|
---|
| 346 | * @param minimum the minimum as an int
|
---|
| 347 | */
|
---|
[6087] | 348 | public void setMinimum(int minimum) {
|
---|
| 349 | this.minimum = minimum;
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[6389] | 352 | /** Set the detail mode level where this argument will become available.
|
---|
| 353 | * @param mode_level the mode level as an int
|
---|
| 354 | */
|
---|
| 355 | public void setModeLevel(int mode_level) {
|
---|
| 356 | this.mode_level = mode_level;
|
---|
| 357 | }
|
---|
| 358 |
|
---|
[4838] | 359 | /** Set the value of name.
|
---|
[6389] | 360 | * @param name the new value of name as a String
|
---|
[4932] | 361 | */
|
---|
| 362 | public void setName(String name) {
|
---|
| 363 | this.name = name;
|
---|
[4838] | 364 | }
|
---|
[4932] | 365 |
|
---|
[4838] | 366 | /** Sets the value of the options list.
|
---|
[6389] | 367 | * @param list the new options list as a HashMap
|
---|
[4932] | 368 | */
|
---|
[12824] | 369 | public void setOptions(ArrayList list) {
|
---|
| 370 | this.option_list = list;
|
---|
[4838] | 371 | }
|
---|
[4932] | 372 |
|
---|
[4838] | 373 | /** Set the owner of this argument.
|
---|
[6389] | 374 | * @param owner the name of the owner of this argument as a String
|
---|
[4932] | 375 | */
|
---|
[4838] | 376 | public void setOwner(String owner) {
|
---|
| 377 | this.owner = owner;
|
---|
| 378 | }
|
---|
[4932] | 379 |
|
---|
[4838] | 380 | /** Set the value of required.
|
---|
[6389] | 381 | * @param required the new value of required as a boolean
|
---|
[4932] | 382 | */
|
---|
| 383 | public void setRequired(boolean required) {
|
---|
| 384 | this.required = required;
|
---|
[4838] | 385 | }
|
---|
[4932] | 386 |
|
---|
[4838] | 387 | /** Set the value of type.
|
---|
[6389] | 388 | * @param type the new value of type as an byte
|
---|
[4932] | 389 | */
|
---|
| 390 | public void setType(byte type) {
|
---|
| 391 | this.type = type;
|
---|
[4838] | 392 | }
|
---|
[4932] | 393 |
|
---|
[4838] | 394 | /** Set the value of type, by matching a type to the given string.
|
---|
[6389] | 395 | * @param new_type a String which contains the name of a certain argument type
|
---|
| 396 | * @see org.greenstone.gatherer.util.StaticStrings#ENUM_STR
|
---|
| 397 | * @see org.greenstone.gatherer.util.StaticStrings#FLAG_STR
|
---|
| 398 | * @see org.greenstone.gatherer.util.StaticStrings#HIERARCHY_STR
|
---|
| 399 | * @see org.greenstone.gatherer.util.StaticStrings#INT_STR
|
---|
| 400 | * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGE_STR
|
---|
| 401 | * @see org.greenstone.gatherer.util.StaticStrings#METADATA_TYPE_STR
|
---|
| 402 | * @see org.greenstone.gatherer.util.StaticStrings#METADATUM_TYPE_STR
|
---|
| 403 | * @see org.greenstone.gatherer.util.StaticStrings#REGEXP_STR
|
---|
[4932] | 404 | */
|
---|
[4838] | 405 | public void setType(String new_type) {
|
---|
[4932] | 406 | if(new_type.equalsIgnoreCase(StaticStrings.ENUM_STR)) {
|
---|
[4838] | 407 | this.type = ENUM;
|
---|
[12824] | 408 | option_list = new ArrayList();
|
---|
[4838] | 409 | }
|
---|
[4932] | 410 | else if(new_type.equalsIgnoreCase(StaticStrings.FLAG_STR)) {
|
---|
[4838] | 411 | this.type = FLAG;
|
---|
| 412 | }
|
---|
[4932] | 413 | else if(new_type.equalsIgnoreCase(StaticStrings.HIERARCHY_STR)) {
|
---|
[4838] | 414 | this.type = HIERARCHY;
|
---|
| 415 | }
|
---|
[4932] | 416 | else if(new_type.equalsIgnoreCase(StaticStrings.INT_STR)) {
|
---|
[4838] | 417 | this.type = INTEGER;
|
---|
| 418 | }
|
---|
[4932] | 419 | else if(new_type.equalsIgnoreCase(StaticStrings.LANGUAGE_STR)) {
|
---|
[4838] | 420 | this.type = LANGUAGE;
|
---|
| 421 | }
|
---|
[4932] | 422 | else if(new_type.equalsIgnoreCase(StaticStrings.METADATA_TYPE_STR)) {
|
---|
[4838] | 423 | this.type = METADATA;
|
---|
| 424 | }
|
---|
[4932] | 425 | else if(new_type.equalsIgnoreCase(StaticStrings.METADATUM_TYPE_STR)) {
|
---|
[4838] | 426 | this.type = METADATUM;
|
---|
| 427 | }
|
---|
[6389] | 428 | else if(new_type.equalsIgnoreCase(StaticStrings.REGEXP_STR)) {
|
---|
| 429 | this.type = REGEXP;
|
---|
| 430 | }
|
---|
[4932] | 431 | else {
|
---|
[4838] | 432 | this.type = STRING;
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
[6389] | 435 |
|
---|
[4932] | 436 | /** Method to set the value of this argument.
|
---|
[6389] | 437 | * @param value the new value for the argument
|
---|
| 438 | * @see org.greenstone.gatherer.Gatherer#println
|
---|
[4932] | 439 | */
|
---|
| 440 | public void setValue(String value) {
|
---|
| 441 | if(element != null) {
|
---|
[8015] | 442 | XMLTools.setValue(element, value);
|
---|
[4932] | 443 | }
|
---|
| 444 | else {
|
---|
[8236] | 445 | DebugStream.println("Argument.setValue(" + value + ") called on a base Argument.");
|
---|
[4932] | 446 | }
|
---|
| 447 | }
|
---|
[4838] | 448 |
|
---|
| 449 | /** Set the values vector to the given values. Currently I just assign the new values, whereas I may later want to implement a deep clone.
|
---|
[4932] | 450 | * @param values an ArrayList of values
|
---|
[6389] | 451 | * @see org.greenstone.gatherer.Gatherer#println
|
---|
[4932] | 452 | */
|
---|
| 453 | public void setValues(ArrayList values) {
|
---|
| 454 | if(element != null) {
|
---|
| 455 | StringBuffer value = new StringBuffer();
|
---|
| 456 | int value_length = values.size();
|
---|
| 457 | for(int i = 0; i < value_length; i++) {
|
---|
| 458 | value.append(values.get(i));
|
---|
| 459 | value.append(StaticStrings.COMMA_CHARACTER);
|
---|
[4838] | 460 | }
|
---|
[4932] | 461 | value.deleteCharAt(value.length() - 1); // Remove last ','
|
---|
[8015] | 462 | XMLTools.setValue(element, value.toString());
|
---|
[4838] | 463 | }
|
---|
[4932] | 464 | else {
|
---|
[8236] | 465 | DebugStream.println("Argument.setValues([" + values.size() + " items]) called on a base Argument.");
|
---|
[4932] | 466 | }
|
---|
[4838] | 467 | }
|
---|
| 468 |
|
---|
[4932] | 469 | /** Method for translating the data of this class into a string.
|
---|
| 470 | * @return a String containing a fragment of the total arguments string
|
---|
[6389] | 471 | * @see org.greenstone.gatherer.Gatherer#c_man
|
---|
| 472 | * @see org.greenstone.gatherer.collection.CollectionManager#getCollection
|
---|
| 473 | * @see org.greenstone.gatherer.util.StaticStrings#COMMA_CHARACTER
|
---|
| 474 | * @see org.greenstone.gatherer.util.StaticStrings#NAME_ATTRIBUTE
|
---|
| 475 | * @see org.greenstone.gatherer.util.StaticStrings#SPACE_CHARACTER
|
---|
| 476 | * @see org.greenstone.gatherer.util.StaticStrings#SPEECH_CHARACTER
|
---|
[4932] | 477 | */
|
---|
[8313] | 478 | public String toString()
|
---|
| 479 | {
|
---|
[4932] | 480 | StringBuffer text = new StringBuffer("-");
|
---|
[8313] | 481 |
|
---|
| 482 | if (element == null) {
|
---|
| 483 | return text.toString();
|
---|
[4838] | 484 | }
|
---|
[8313] | 485 |
|
---|
| 486 | if (name == null) {
|
---|
| 487 | name = element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
|
---|
| 488 | }
|
---|
| 489 | text.append(name);
|
---|
| 490 |
|
---|
| 491 | String value = XMLTools.getValue(element);
|
---|
| 492 | if (value.length() == 0) {
|
---|
| 493 | return text.toString();
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | text.append(StaticStrings.SPACE_CHARACTER);
|
---|
| 497 |
|
---|
| 498 | // // Handle metadata elements specially
|
---|
| 499 | // if (type == METADATA || type == METADATUM) {
|
---|
| 500 | // // Tokenize the string
|
---|
| 501 | // StringTokenizer tokenizer = new StringTokenizer(value, ",");
|
---|
| 502 | // while (tokenizer.hasMoreTokens()) {
|
---|
| 503 | // String token = tokenizer.nextToken();
|
---|
| 504 |
|
---|
| 505 | // MetadataElement metadata_element = MetadataTools.getMetadataElementWithDisplayName(token);
|
---|
| 506 | // if (metadata_element != null) {
|
---|
| 507 | // text.append(metadata_element.getFullName());
|
---|
| 508 | // }
|
---|
| 509 | // else {
|
---|
| 510 | // text.append(token);
|
---|
| 511 | // }
|
---|
| 512 |
|
---|
| 513 | // if (tokenizer.hasMoreTokens()) {
|
---|
| 514 | // text.append(StaticStrings.COMMA_CHARACTER);
|
---|
| 515 | // }
|
---|
| 516 | // }
|
---|
| 517 | // return text.toString();
|
---|
| 518 | // }
|
---|
| 519 |
|
---|
| 520 | // If the value contains a space, add speech marks
|
---|
| 521 | // (Except for metadata elements, which won't have spaces when written out to collect.cfg)
|
---|
| 522 | if (value.indexOf(StaticStrings.SPACE_CHARACTER) != -1 && !(type == METADATUM || type == METADATA)) {
|
---|
| 523 | value = StaticStrings.SPEECH_CHARACTER + value + StaticStrings.SPEECH_CHARACTER;
|
---|
| 524 | }
|
---|
| 525 |
|
---|
| 526 | text.append(value);
|
---|
[4932] | 527 | return text.toString();
|
---|
[9126] | 528 | }
|
---|
| 529 |
|
---|
| 530 | /** parse the <Option> XML from eg import.pl -xml or pluginfo.pl -xml */
|
---|
| 531 | public void parseXML(Element option) {
|
---|
| 532 |
|
---|
| 533 | for(Node node = option.getFirstChild(); node != null; node = node.getNextSibling()) {
|
---|
| 534 | String node_name = node.getNodeName();
|
---|
| 535 | if(node_name.equals("Name")) {
|
---|
| 536 | setName(XMLTools.getValue(node));
|
---|
| 537 | }
|
---|
| 538 | else if(node_name.equals("Desc")) {
|
---|
| 539 | setDescription(XMLTools.getValue(node));
|
---|
| 540 | }
|
---|
| 541 | else if(node_name.equals("Type")) {
|
---|
| 542 | setType(XMLTools.getValue(node));
|
---|
| 543 | }
|
---|
| 544 | else if(node_name.equals("Default")) {
|
---|
| 545 | setDefaultValue(XMLTools.getValue(node));
|
---|
| 546 | }
|
---|
| 547 | else if(node_name.equals("Required")) {
|
---|
| 548 | String v = XMLTools.getValue(node);
|
---|
| 549 | if(v != null && v.equals("yes")) {
|
---|
| 550 | setRequired(true);
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 | else if(node_name.equals("List")) {
|
---|
| 554 | // Two final loops are required to parse lists.
|
---|
| 555 | for(Node value = node.getFirstChild(); value != null; value = value.getNextSibling()) {
|
---|
| 556 | if(value.getNodeName().equals("Value")) {
|
---|
| 557 | String key = null;
|
---|
| 558 | String desc = "";
|
---|
| 559 | for(Node subvalue = value.getFirstChild(); subvalue != null; subvalue = subvalue.getNextSibling()) {
|
---|
| 560 | node_name = subvalue.getNodeName();
|
---|
| 561 | if(node_name.equals("Name")) {
|
---|
| 562 | key = XMLTools.getValue(subvalue);
|
---|
| 563 | }
|
---|
| 564 | else if(node_name.equals("Desc")) {
|
---|
| 565 | desc = XMLTools.getValue(subvalue);
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | if(key != null) {
|
---|
| 569 | addOption(key, desc);
|
---|
| 570 | }
|
---|
| 571 | }
|
---|
| 572 | }
|
---|
| 573 | }
|
---|
| 574 | else if(node_name.equals("Range")) {
|
---|
| 575 | String range_raw = XMLTools.getValue(node);
|
---|
| 576 | int index = -1;
|
---|
| 577 | if((index = range_raw.indexOf(StaticStrings.COMMA_CHARACTER)) != -1) {
|
---|
| 578 | if(index > 0) {
|
---|
| 579 | try {
|
---|
| 580 | String first_number = range_raw.substring(0, index);
|
---|
| 581 | setMinimum(Integer.parseInt(first_number));
|
---|
| 582 | first_number = null;
|
---|
| 583 | }
|
---|
| 584 | catch(Exception exception) {
|
---|
| 585 | }
|
---|
| 586 | }
|
---|
| 587 |
|
---|
| 588 | if(index + 1 < range_raw.length()) {
|
---|
| 589 | try {
|
---|
| 590 | String second_number = range_raw.substring(index + 1);
|
---|
| 591 | setMaximum(Integer.parseInt(second_number));
|
---|
| 592 | second_number = null;
|
---|
| 593 | }
|
---|
| 594 | catch(Exception exception) {
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 | // Else it wasn't a valid range anyway, so ignore it
|
---|
| 599 | }
|
---|
| 600 | else if(node_name.equals("HiddenGLI")) {
|
---|
[11283] | 601 | setHiddenGLI(true);
|
---|
[9126] | 602 | }
|
---|
| 603 | else if(node_name.equals("ModeGLI")) {
|
---|
| 604 | String mode_level_str = XMLTools.getValue(node);
|
---|
| 605 | try {
|
---|
| 606 | int mode_level = Integer.parseInt(mode_level_str);
|
---|
| 607 | setModeLevel(mode_level);
|
---|
| 608 | }
|
---|
| 609 | catch(Exception exception) {
|
---|
| 610 | DebugStream.println("Exception in Argument.parseXML() - Unexpected but non-fatal");
|
---|
| 611 | DebugStream.printStackTrace(exception);
|
---|
| 612 | }
|
---|
| 613 | }
|
---|
| 614 |
|
---|
| 615 | } // for each option
|
---|
| 616 |
|
---|
| 617 | } // parseXML
|
---|
[12824] | 618 |
|
---|
| 619 | public class ArgumentOption
|
---|
| 620 | implements Comparable {
|
---|
| 621 | public String name;
|
---|
| 622 | public String description;
|
---|
| 623 | private String text; // cached version
|
---|
| 624 |
|
---|
| 625 | public ArgumentOption(String name, String desc) {
|
---|
| 626 | this.name = name;
|
---|
| 627 | this.description = desc;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | public int compareTo(Object obj) {
|
---|
| 631 | return toString().compareTo(obj.toString());
|
---|
| 632 | }
|
---|
| 633 |
|
---|
| 634 | public boolean equals(Object obj) {
|
---|
| 635 | return (obj != null && compareTo(obj) == 0);
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | public String toString() {
|
---|
| 639 | return name + " "+ StaticStrings.MINUS_CHARACTER + " "+ description;
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | public String getToolTip() {
|
---|
| 643 | return Utility.formatHTMLWidth(name+": "+description, 80);
|
---|
| 644 | }
|
---|
| 645 | }
|
---|
[4838] | 646 | }
|
---|