source: trunk/gli/src/org/greenstone/gatherer/cdm/Subcollection.java@ 4675

Last change on this file since 4675 was 4675, checked in by jmt12, 21 years ago

Sunday's work

  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 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 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.cdm;
44/**************************************************************************************
45 * Title: Gatherer
46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
47 * Copyright: Copyright (c) 2001
48 * Company: The University of Waikato
49 * Written: 03/05/02
50 * Revised: 17/11/02 - Commenting
51 **************************************************************************************/
52import org.greenstone.gatherer.msm.MSMUtils;
53import org.w3c.dom.Element;
54/** This class encapsulates one subcollection entry in the collection configuration file.
55 * @author John Thompson, Greenstone Digital Library, University of Waikato
56 * @version 2.3
57 */
58public class Subcollection
59 implements Comparable {
60 /** A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise. */
61 private boolean include = true;
62 /** Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name. */
63 private String element = null;
64 /** A String containing a Perl expression which is used as the filter for this subcollection. */
65 private String exp = null;
66 /** A series of flags to be used when matching the expression. */
67 private String flags = null;
68 /** A String which is a unique identifier of a subcollection. */
69 private String name = null;
70 /** Constructor.
71 * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
72 * @param pattern A <strong>String</strong> containing the inclusion, the element to filter, a Perl expression which is used as the filter for this subcollection, and a series of argument flags.
73 */
74 public Subcollection(String name, String pattern) {
75 this.name = name;
76 // Have to do some work on pattern.
77 // Remove quote marks.
78 if(pattern.startsWith("\"") || pattern.startsWith("'")) {
79 pattern = pattern.substring(1, pattern.length() - 1);
80 }
81 // Test for exclusion
82 if(pattern.startsWith("!")) {
83 this.include = false;
84 pattern = pattern.substring(1, pattern.length());
85 }
86 else {
87 this.include = true;
88 }
89 if(pattern.indexOf("/") != -1) {
90 // Now element (which may be Filename)
91 this.element = pattern.substring(0, pattern.indexOf("/"));
92 if(this.element.toLowerCase().equals("filename")) {
93 this.element = null;
94 }
95 // Extract Perl expression
96 if(pattern.indexOf("/") != pattern.lastIndexOf("/")) {
97 this.exp = pattern.substring(pattern.indexOf("/") + 1,
98 pattern.lastIndexOf("/"));
99 this.flags = pattern.substring(pattern.lastIndexOf("/") + 1);
100 }
101 else {
102 this.exp = pattern.substring(pattern.indexOf("/") + 1);
103 }
104 }
105 else {
106 // Hmmm. Well I don't know what this is but it isn't a proper subcollection definition. Can't really 'return null' or something. So I'll just not set include, element, exp and flag expressions.
107 }
108 }
109 /** Constructor.
110 * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
111 * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise.
112 * @param exp A <strong>String</strong> containing a Perl expression which is used as the filter for this subcollection.
113 */
114 public Subcollection(String name, boolean include, String exp, String flags) {
115 this.element = null;
116 this.exp = exp;
117 this.flags = flags;
118 this.include = include;
119 this.name = name;
120 }
121 /** Constructor.
122 * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
123 * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise.
124 * @param element Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name.
125 * @param exp A <strong>String</strong> containing a Perl expression which is used as the filter for this subcollection.
126 * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression.
127 */
128 public Subcollection(String name, boolean include, String element, String exp, String flags) {
129 this.element = element;
130 this.exp = exp;
131 this.flags = flags;
132 this.include = include;
133 this.name = name;
134 }
135 /** Method to compare two subcollections.
136 * @param object The other subcollection to compare to, as an <strong>Object</strong>.
137 * @return An <i>int</i> which is greater than, equal to or less than zero if the this object is before, equal to, or after the target object respectively.
138 */
139 public int compareTo(Object object) {
140 Subcollection sub = (Subcollection) object;
141 return getName().compareTo(sub.getName());
142 }
143 /** Method to check two subcollections for equality.
144 * @param object The other subcollection to compare to, as an <strong>Object</strong>.
145 * @return A <i>boolean</i> which is <i>true</i> if the subcollections are equal, <i>false</i> otherwise.
146 */
147 public boolean equals(Object object) {
148 if(compareTo(object) == 0) {
149 return true;
150 }
151 return false;
152 }
153 /** Method to get the value of element.
154 * @return The value of element as an <strong>String</strong>.
155 */
156 public String getElement() {
157 return element;
158 }
159 /** Method to get the value of expression.
160 * @return The value of exp as a <strong>String</strong>.
161 */
162 public String getExpression() {
163 return exp;
164 }
165 /** Method to get the value of flags.
166 * @return The value of flags as a <strong>String</strong>.
167 */
168 public String getFlags() {
169 return flags;
170 }
171 /** Method to get the value of include.
172 * @param boolean The value of include as a <i>boolean</i>.
173 */
174 public boolean getInclude() {
175 return include;
176 }
177 /** Method to get the value of name.
178 * @param String The value of name as a <strong>String</string>.
179 */
180 public String getName() {
181 return name;
182 }
183 /** Method to get the name of the source of the strings used in pattern matching.
184 * @return A <strong>String</strong> which is either the fully qualified name of a metadata element, or "Filename".
185 */
186 public String getSource() {
187 if(element != null) {
188 return element;
189 }
190 return "Filename";
191 }
192 /** Method to display the contents of this class as it would appear in the collection configuration file.
193 * @return A <strong>String</strong> which could be used as a subcollection entry in collect.cfg.
194 */
195 public String toString() {
196 String text = "subcollection ";
197 text = text + name + " ";
198 text = text + "\"";
199 if(!include) {
200 text = text + "!";
201 }
202 if(element != null) {
203 text = text + element;
204 }
205 else {
206 text = text + "Filename";
207 }
208 text = text + "/";
209 text = text + exp;
210 text = text + "/";
211 if(flags != null) {
212 text = text + flags;
213 }
214 text = text + "\"\n";
215 return text;
216 }
217
218 /** Update certain fields of this subcollection.
219 * @param name A <strong>String</strong> which is a unique identifier of a subcollection.
220 * @param source Either the fully qualified name of the metadata whose value should be matched against the given expression, or <i>null</i> if you wish to match against the file name.
221 * @param exp A <strong>String</strong> containing a Perl expression which is used as the filter for this subcollection.
222 * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise.
223 * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression.
224 */
225 public void update(String name, String source, String exp, boolean include, String flags) {
226 this.name = name;
227 this.element = source;
228 this.exp = exp;
229 this.include = include;
230 this.flags = flags;
231 }
232
233 /** Method to update the name of a metadata element, if it changes.
234 * @param old_name The current name of the element as a <strong>String</strong>.
235 * @param new_name The new name of the element as a <strong>String</strong>.
236 */
237 public void updateElement(String old_name, String new_name) {
238 if(element.equals(old_name)) {
239 element = new_name;
240 }
241 }
242}
243
244
245
246
247
Note: See TracBrowser for help on using the repository browser.