- Timestamp:
- 2003-05-27T15:57:37+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/Subcollection.java
r4293 r4366 53 53 import org.w3c.dom.Element; 54 54 /** This class encapsulates one subcollection entry in the collection configuration file. 55 * @author John Thompson, Greenstone Digital Library, University of Waikato56 * @version 2.357 */55 * @author John Thompson, Greenstone Digital Library, University of Waikato 56 * @version 2.3 57 */ 58 58 public class Subcollection 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 90 // Now element (which may be Filename) 91 92 93 94 91 this.element = pattern.substring(0, pattern.indexOf("/")); 92 if(this.element.toLowerCase().equals("filename")) { 93 this.element = null; 94 } 95 95 // Extract Perl expression 96 97 98 99 100 101 102 103 104 105 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 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 107 } 108 } 109 /** Constructor. 110 110 * @param name A <strong>String</strong> which is a unique identifier of a subcollection. 111 111 * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise. 112 112 * @param exp A <strong>String</strong> containing a Perl expression which is used as the filter for this subcollection. 113 113 */ 114 115 116 117 118 119 120 121 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 122 * @param name A <strong>String</strong> which is a unique identifier of a subcollection. 123 123 * @param include A <i>boolean</i> which is <i>true</i> if the condition is an include one, <i>false</i> otherwise. … … 126 126 * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression. 127 127 */ 128 129 130 131 132 133 134 135 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 136 * @param object The other subcollection to compare to, as an <strong>Object</strong>. 137 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 138 */ 139 140 141 142 143 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 144 * @param object The other subcollection to compare to, as an <strong>Object</strong>. 145 145 * @return A <i>boolean</i> which is <i>true</i> if the subcollections are equal, <i>false</i> otherwise. 146 146 */ 147 148 149 150 151 152 153 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 154 * @return The value of element as an <strong>String</strong>. 155 155 */ 156 157 158 159 156 public String getElement() { 157 return element; 158 } 159 /** Method to get the value of expression. 160 160 * @return The value of exp as a <strong>String</strong>. 161 161 */ 162 163 164 165 162 public String getExpression() { 163 return exp; 164 } 165 /** Method to get the value of flags. 166 166 * @return The value of flags as a <strong>String</strong>. 167 167 */ 168 169 170 171 168 public String getFlags() { 169 return flags; 170 } 171 /** Method to get the value of include. 172 172 * @param boolean The value of include as a <i>boolean</i>. 173 173 */ 174 175 176 177 174 public boolean getInclude() { 175 return include; 176 } 177 /** Method to get the value of name. 178 178 * @param String The value of name as a <strong>String</string>. 179 179 */ 180 181 182 183 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 184 * @return A <strong>String</strong> which is either the fully qualified name of a metadata element, or "Filename". 185 185 */ 186 187 188 189 190 191 192 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 193 * @return A <strong>String</strong> which could be used as a subcollection entry in collect.cfg. 194 194 */ 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 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 219 * @param name A <strong>String</strong> which is a unique identifier of a subcollection. 220 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. … … 223 223 * @param flags A <strong>String</strong> of flags to be taken into account when matching the expression. 224 224 */ 225 226 227 228 229 230 231 232 233 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 234 * @param old_name The current name of the element as a <strong>String</strong>. 235 235 * @param new_name The new name of the element as a <strong>String</strong>. 236 236 */ 237 238 239 240 241 237 public void updateElement(String old_name, String new_name) { 238 if(element.equals(old_name)) { 239 element = new_name; 240 } 241 } 242 242 } 243 243
Note:
See TracChangeset
for help on using the changeset viewer.