source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/download/Download.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 6.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.download;
28
29import java.io.*;
30import java.util.*;
31import org.greenstone.gatherer.util.StaticStrings;
32import org.greenstone.gatherer.util.Utility;
33import org.w3c.dom.*;
34import org.greenstone.gatherer.cdm.*;
35
36
37/** This class is responsible for storing information from a parsed downloadinfo.pl call in such a way that it allows easy access to parsed details for the purposes of user design and specification of downloads.
38 * @author John Thompson, Greenstone Digital Library, University of Waikato
39 * @version 2.3
40 */
41public class Download
42 extends ArgumentContainer
43{
44 private boolean is_abstract = false;
45
46 /** A reference to the download that this one inherits from. */
47 private Download super_download = null;
48 /** The element this download is based upon. */
49 private Element element;
50 /** A description of this download. */
51 private String description = null;
52 private String name = null;
53
54
55 public Download() {
56 }
57
58 /** Method to add an argument to this download. Only adds the argument if it isn't already present.
59 * @param argument The <strong>Argument</strong> to add.
60 */
61 public void addArgument(Argument argument) {
62 if(element == null && !contains(argument)) {
63 add(argument);
64 argument.setOwner(name);
65 }
66 }
67
68 /** Method to compare two downloads for ordering.
69 * @param object The download we are comparing to, as an <strong>Object</strong>.
70 * @return An <i>int</i> specifying the download order, using values as set out in String.
71 * @see java.lang.String#compareTo
72 */
73 public int compareTo(Object object) {
74 if(object == null) {
75 return -1;
76 }
77 return toString().compareTo(object.toString());
78 }
79
80 /** Probably not used.
81 */
82 public DOMProxyListEntry create(Element element) {
83 return null;
84 }
85
86 /** Method to determine if two downloads are equal.
87 * @param object The download to test against, as an <strong>Object</strong>.
88 * @return <i>true</i> if the download names match, <i>false</i> otherwise.
89 */
90 public boolean equals(Object object) {
91 return (compareTo(object) == 0);
92 }
93
94 /** Method to retrieve an argument by its name.
95 * @param name The name of the argument as a <strong>String</strong>.
96 * @return The <strong>Argument</strong> requested, or <i>null</i> if no such argument.
97 */
98 public Argument getArgument(String name) {
99 // The name given may still include the '-'
100 if(name.startsWith("-")) {
101 name = name.substring(1);
102 }
103 ArrayList arguments = getArguments(true, true);
104 for(int i = 0; i < arguments.size(); i++) {
105 Argument argument = (Argument)arguments.get(i);
106 if(argument.getName().equals(name)) {
107 return argument;
108 }
109 }
110 return null;
111 }
112
113 /** Retrieve all of the arguments available to this base download, including its super downloads arguments. Some complexity is added by allowing the caller to choose whether they want normal arguments, custom arguments, or both.
114 * @return an ArrayList of all of the arguments, starting with those for this download and ending with the arguments for basplug or similiar root download
115 */
116 public ArrayList getArguments(boolean include_normal, boolean include_custom) {
117 ArrayList arguments = new ArrayList();
118 if(include_normal && include_custom) {
119 arguments.addAll(this);
120 }
121 else {
122 int size = size();
123 for(int i = 0; i < size; i++) {
124 Argument argument = (Argument) get(i);
125 if(argument.isCustomArgument()) {
126 if(include_custom && !arguments.contains(argument)) {
127 arguments.add(argument);
128 }
129 }
130 else {
131 if(include_normal && !arguments.contains(argument)) {
132 arguments.add(argument);
133 }
134 }
135 argument = null;
136 }
137 }
138 if(super_download != null) {
139 ArrayList remainder = super_download.getArguments(include_normal, include_custom);
140 remainder.removeAll(arguments);
141 arguments.addAll(remainder);
142 }
143 return arguments;
144 }
145
146 public String getDescription() {
147 return description;
148 }
149
150 public Element getElement() {
151 return element;
152 }
153
154 /** Method to retrieve a download name.
155 * @return A <strong>String</strong> containing the downloads name.
156 */
157 public String getName() {
158 if(name == null && element != null) {
159 name = element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
160 }
161 return name;
162 }
163
164 public boolean isAbstract() {
165 return is_abstract;
166 }
167
168 public boolean isAssigned() {
169 return (element != null && !element.getAttribute(StaticStrings.ASSIGNED_ATTRIBUTE).equals(StaticStrings.FALSE_STR));
170 }
171
172 public void setAssigned(boolean assigned) {
173 if(element != null) {
174 element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, (assigned ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
175 }
176 }
177
178
179 /** Method to set the value of desc.
180 * @param description The new value of desc as a <strong>String</strong>.
181 */
182 public void setDescription(String description) {
183 this.description = description;
184 }
185
186 public void setElement(Element element) {
187 this.element = element;
188 }
189
190 public void setIsAbstract(boolean is_abstract) {
191 this.is_abstract = is_abstract;
192 }
193
194 /** Method to set the value of name.
195 * @param name The new value of name as a <strong>String</strong>.
196 */
197 public void setName(String name) {
198 this.name = name;
199 }
200
201 /** Method to set the value of the super_download.
202 * @param super_download The new value of super_download as a <strong>Download</strong>, or <i>null</i> if this class has no inheritance.
203 */
204 public void setSuper(Download super_download) {
205 this.super_download = super_download;
206 }
207}
Note: See TracBrowser for help on using the repository browser.