Changeset 4540
- Timestamp:
- 2003-06-10T15:32:55+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/cdm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java
r4494 r4540 143 143 text = text + "."; 144 144 Index index = (Index)name; 145 text = text + index.toString (false) + " ";145 text = text + index.toStringConfig() + " "; 146 146 } 147 147 else if(name instanceof SubIndex) { -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMetaManager.java
r4512 r4540 221 221 ///ystem.err.println("Detected '.' prefix."); 222 222 String key_str = (String)key; 223 key = null; 223 224 key_str = key_str.substring(1); 224 key = manager.indexes.getIndex(key_str); 225 Index ind = Index.parseIndexConfig(key_str, manager); 226 if (ind != null) { 227 228 key = manager.indexes.getIndex(ind.toString(false)); 229 } 230 225 231 // If that didn't work, then it might be a subindex so have a bash at retrieving that instead. 226 232 if(key == null) { -
trunk/gli/src/org/greenstone/gatherer/cdm/Index.java
r4494 r4540 52 52 import java.util.Collections; 53 53 import java.util.Comparator; 54 import java.util.StringTokenizer; 54 55 import java.util.Vector; 55 56 import org.greenstone.gatherer.cdm.CollectionMeta; 56 57 import org.greenstone.gatherer.msm.MSMUtils; 58 import org.greenstone.gatherer.util.Utility; 57 59 import org.w3c.dom.Element; 58 60 /** This class encapsulates a single indexing pair. … … 76 78 /** An values of items in the index level enumeration. */ 77 79 static public final String LEVEL[] = {"document","paragraph","section"}; 80 78 81 /** Constructor. 79 82 * @param level The level of this index as a <strong>String</string>. … … 121 124 return result; 122 125 } 126 /** Method to get the data source of this index. 127 * @return A <strong>String</string> which is a comma separated list of either fully qualified names of an assigned metadata elements, or "text". 128 * Note, greenstone extracted metadata do not have the ex. 129 */ 130 public String getDataConfig() { 131 String result = ""; 132 Collections.sort(sources, new IndexComparator()); 133 for(int i = 0; i < sources.size(); i++) { 134 String source = sources.get(i).toString(); 135 if (source.startsWith("ex.")) { 136 // remove the ex. bit 137 source = source.substring(3); 138 } 139 result = result + source; 140 if(i < sources.size() - 1) { 141 result = result + ","; 142 } 143 } 144 return result; 145 } 146 123 147 /** Method to get the value of level. 124 148 * @return The value of level as a <strong>String</strong>. … … 146 170 } 147 171 return ""; 172 148 173 } 149 174 /** Method to turn this object into a string representation ready to be placed in the collection configuration file. … … 162 187 return LEVEL[level] + ":" + getData(); 163 188 } 189 190 /** Retrieve a textual representation of this index, specifically for the configuration files. Extracted metadata is shown to teh user and stored as ex.MD, however in the config file it should have no namespace */ 191 public String toStringConfig() { 192 193 return LEVEL[level] + ":" + getDataConfig(); 194 } 195 196 /** Method to parse a configuration file index specification into an Index 197 * object. returns null if invalid syntax */ 198 public static Index parseIndexConfig(String entry, CollectionDesignManager manager) { 199 // all (mg) indexes must start with level: 200 if(entry.indexOf(":") == -1) { 201 return null; 202 } 203 204 String level_str = entry.substring(0, entry.indexOf(":")); 205 String sources_raw = entry.substring(entry.indexOf(":") + 1); 206 Vector sources = new Vector(); 207 StringTokenizer st = new StringTokenizer(sources_raw, ","); 208 while(st.hasMoreTokens()) { 209 String token = st.nextToken(); 210 // We may have to replace old : with whatever namespace separator we are using. 211 token = token.replace(':', MSMUtils.NS_SEP); 212 // if there is no namespace, we need to add one, except for text 213 if (token.indexOf(MSMUtils.NS_SEP)==-1) { 214 if (!token.equals("text")) { 215 token = Utility.EXTRACTED_METADATA_NAMESPACE+MSMUtils.NS_SEP+token; 216 } 217 } 218 219 sources.add(token); 220 } 221 Index index = null; 222 for(int i = 0; i < Index.LEVEL.length; i++) { 223 if(level_str.equals(Index.LEVEL[i])) { 224 return new Index(i, sources, manager); 225 226 } 227 } 228 // somethings gone wrong 229 return null; 230 231 } 232 164 233 /** A custom comparator for comparing Indexes. */ 165 234 private class IndexComparator -
trunk/gli/src/org/greenstone/gatherer/cdm/IndexManager.java
r4533 r4540 217 217 while(ct.hasMoreTokens()) { 218 218 String entry = ct.nextToken(); 219 if(entry.indexOf(":") != -1) { 220 String level_str = entry.substring(0, entry.indexOf(":")); 221 String sources_raw = entry.substring(entry.indexOf(":") + 1); 222 Vector sources = new Vector(); 223 StringTokenizer st = new StringTokenizer(sources_raw, ","); 224 while(st.hasMoreTokens()) { 225 String token = st.nextToken(); 226 // We may have to replace old : with whatever namespace separator we are using. 227 token = token.replace(':', MSMUtils.NS_SEP); 228 sources.add(token); 229 } 230 for(int i = 0; i < Index.LEVEL.length; i++) { 231 if(level_str.equals(Index.LEVEL[i])) { 232 addIndex(new Index(i, sources, manager)); 233 } 234 } 235 } 236 else { 219 Index index = Index.parseIndexConfig(entry, manager); 220 if (index != null) { 221 addIndex(index); 222 223 } else { // return false if there is one error?? 237 224 return false; 238 225 } 239 226 } 227 240 228 return true; 241 229 } … … 244 232 ct.nextToken(); 245 233 String entry = ct.nextToken(); 246 if(entry.indexOf(":") != -1) { 247 String level_str = entry.substring(0, entry.indexOf(":")); 248 String sources_raw = entry.substring(entry.indexOf(":") + 1); 249 Vector sources = new Vector(); 250 StringTokenizer st = new StringTokenizer(sources_raw, ","); 251 while(st.hasMoreTokens()) { 252 sources.add(st.nextToken()); 253 } 254 for(int i = 0; i < Index.LEVEL.length; i++) { 255 if(level_str.equals(Index.LEVEL[i])) { 256 setDefault(new Index(i, sources, manager)); 257 } 258 } 259 } 260 else { 261 return false; 262 } 263 return true; 264 } 234 Index index = Index.parseIndexConfig(entry, manager); 235 if (index != null) { 236 setDefault(index); 237 return true; 238 } 239 return false; 240 } 241 265 242 return false; 266 243 } … … 316 293 for(int i = 0; i < size(); i++) { 317 294 Index index = (Index) get(i); 318 text = text + index.toString (false);295 text = text + index.toStringConfig(); 319 296 if(i < size() - 1) { 320 297 text = text + " "; 321 298 } 322 299 } 323 324 300 // Now the default index if there is one, or just the first index 301 // if there isn't 325 302 if(default_index != null) { 326 text = text + "\ndefaultindex " + default_index.toString (false) + "\n";303 text = text + "\ndefaultindex " + default_index.toStringConfig() + "\n"; 327 304 } 328 305 text = text + "\n"; … … 330 307 return text; 331 308 } 309 310 311 312 313 332 314 /** Overloaded to call get with both a key and an empty argument array. 333 315 * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
Note:
See TracChangeset
for help on using the changeset viewer.