Changeset 6345
- Timestamp:
- 2004-01-06T11:43:53+13:00 (20 years ago)
- Location:
- trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/BuildManager.java
r6292 r6345 68 68 // set up the indexers 69 69 this.indexerManager = new IndexerManager(this.docList); 70 IndexerInterface iface = new MGIndexer(); 71 iface.configure(IndexerManager.outputDir, this.outputDir); 72 iface.configure(MGIndexer.MG_INDEX, "document:text"); 73 iface.configure(MGIndexer.MG_INDEX, "section:text"); 74 this.indexerManager.addIndexer(iface); 70 71 // configure the collection 72 this.collectionManager.configureCollection(this); 75 73 76 74 // prepare a file crawler on the etc directory, and a crawl observer to respond to … … 88 86 public ClassifierManager getClassifierManager() 89 87 { return this.classifierManager; 88 } 89 90 public IndexerManager getIndexerManager() 91 { return this.indexerManager; 92 } 93 94 public void addIndexer(IndexerInterface iface) 95 { iface.configure(IndexerManager.outputDir, this.outputDir); 96 this.indexerManager.addIndexer(iface); 90 97 } 91 98 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java
r6099 r6345 3 3 import java.util.Date; 4 4 import java.util.Calendar; 5 import java.util.List; 6 import java.util.ArrayList; 7 import java.util.Map; 8 import java.util.HashMap; 9 import java.util.Iterator; 5 10 import java.util.GregorianCalendar; 6 11 7 12 import java.io.File; 8 13 import java.io.IOException; 14 15 import java.net.URL; 9 16 10 17 import javax.xml.parsers.*; … … 21 28 22 29 import org.greenstone.gsdl3.gs3build.collection.*; 30 import org.greenstone.gsdl3.gs3build.classifier.*; 31 import org.greenstone.gsdl3.gs3build.indexers.*; 23 32 24 33 import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection; 25 34 import org.greenstone.gsdl3.gs3build.util.GS3SQLConnectionFactory; 35 import org.greenstone.gsdl3.gs3build.util.DOMUtils; 26 36 27 37 /** … … 35 45 public class CollectionManager 36 46 { 37 GregorianCalendar lastBuildDate; // pretty obvious38 String adminEmail; // the email address of the administrator of the39 40 int buildDocNo; // used to generate document identifiers41 CollectionMetadata metadata; // collection-level metadata42 GS3SQLConnection database; // the database to store everything in47 GregorianCalendar lastBuildDate; // pretty obvious 48 String adminEmail; // the email address of the administrator of the 49 // collection 50 int buildDocNo; // used to generate document identifiers 51 CollectionMetadata metadata; // collection-level metadata 52 GS3SQLConnection database; // the database to store everything in 43 53 String collectionHome; 54 String collectionName; 55 56 class CollectionClassifier 57 { File file; 58 String type; 59 List fields; 60 String sort; 61 62 public CollectionClassifier(String type, Node node) 63 { this.type = type; 64 this.fields = new ArrayList(); 65 66 NodeList children = node.getChildNodes(); 67 for (int c = 0; c < children.getLength(); c ++) { 68 Node child = children.item(c); 69 70 if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { 71 String name = child.getNodeName(); 72 73 if (name.equals("file")) { 74 NamedNodeMap atts = children.item(c).getAttributes(); 75 Node attribute = atts.getNamedItem("URL"); 76 String urlString = attribute.getNodeValue(); 77 if (urlString == null) 78 continue; 79 80 this.file = new File(urlString); 81 } 82 else if (name.equals("field")) { 83 String fieldName = DOMUtils.getNodeChildText(children.item(c)); 84 this.fields.add(fieldName.toString()); 85 } 86 else if (name.equals("sort")) { 87 String sortName = DOMUtils.getNodeChildText(children.item(c)); 88 this.sort = sortName; 89 } 90 } 91 } 92 } 93 94 public ClassifierInterface getClassifier() 95 { 96 if (this.type.toLowerCase().equals("hierarchy")) { 97 return new HierarchyClassifier(this.file, this.fields, this.sort); 98 } 99 100 return null; 101 } 102 } 103 104 class CollectionIndexer 105 { String level; 106 String type; 107 String name; 108 List fields; 109 String sort; 110 111 public CollectionIndexer(String type, String indexName, Node node) 112 { this.type = type.toLowerCase(); 113 this.fields = new ArrayList(); 114 this.name = indexName; 115 this.level = IndexerManager.DEFAULT_LEVEL; 116 117 NodeList children = node.getChildNodes(); 118 for (int c = 0; c < children.getLength(); c ++) { 119 Node child = children.item(c); 120 121 if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) { 122 String name = child.getNodeName(); 123 124 if (name.equals("level")) { 125 String levelName = DOMUtils.getNodeChildText(children.item(c)); 126 this.level = levelName; 127 } 128 else if (name.equals("field")) { 129 String fieldName = DOMUtils.getNodeChildText(children.item(c)); 130 this.fields.add(fieldName.toString()); 131 } 132 } 133 } 134 if (this.fields.size() == 0) { 135 this.fields.add(IndexerManager.DEFAULT_FIELD); 136 } 137 } 138 139 public void prepareIndexer(Map indexerMap) 140 { IndexerInterface indexer = null; 141 142 if (!indexerMap.containsKey(this.type)) { 143 if (this.type.toLowerCase().equals("mg")) { 144 indexer = new MGIndexer(); 145 } 146 if (indexer != null) { 147 indexerMap.put(this.type, indexer); 148 } 149 } 150 151 indexer = (IndexerInterface) indexerMap.get(this.type); 152 if (indexer != null) { 153 indexer.addIndex(this.level, this.fields.get(0).toString()); 154 } 155 } 156 } 44 157 45 158 /** … … 52 165 53 166 this.database = GS3SQLConnectionFactory.createConnection(collection); 167 if (this.database != null) { 168 this.database.clearCollection(collection); 169 this.database = null; 170 } 54 171 if (this.database == null) { 55 172 this.database = GS3SQLConnectionFactory.createConnection("test"); … … 61 178 if (collectRoot == null) 62 179 { System.out.println("Unable to locate GSDL3HOME"); 63 // System.exit(1);64 return;180 // System.exit(1); 181 return; 65 182 } 66 183 … … 71 188 { this.collectionHome = collectRoot + System.getProperty("file.separator") + "web/sites/localsite/collect" + System.getProperty("file.separator") + collection; 72 189 } 190 this.collectionName = collection; 73 191 74 192 File buildDirectory = new File(this.collectionHome, "building"); … … 83 201 84 202 this.buildDocNo = 1; 85 86 File collectionConfig = new File(collectionHome, "/etc/collectionConfig.xml"); 203 } 204 205 public void configureCollection(BuildManager buildManager) 206 { File collectionConfig = new File(collectionHome, "/etc/collectionConfig.xml"); 87 207 88 208 // get the File and read it in … … 93 213 Document document = builder.parse(collectionConfig); 94 214 215 CollectionClassifier classifier = null; 216 217 Map indexerMap = new HashMap(); 218 95 219 // TODO: report an error 96 220 if (document == null) … … 115 239 116 240 // the name is a plugin element 117 if (name.equals("search")) 118 { 241 if (name.equals("index")) 242 { NamedNodeMap atts = children.item(c).getAttributes(); 243 Node attribute = atts.getNamedItem("type"); 244 String type = attribute.getNodeValue(); 245 246 attribute = atts.getNamedItem("name"); 247 String indexName = attribute.getNodeValue(); 248 249 // create the local indexer representation 250 CollectionIndexer indexer = new CollectionIndexer(type, indexName, children.item(c)); 251 252 // prepare it... 253 indexer.prepareIndexer(indexerMap); 119 254 } 120 255 else if (name.equals("browse")) 121 256 { 122 257 } 123 else if (name.equals("classif y"))258 else if (name.equals("classifier")) 124 259 { 260 NamedNodeMap atts = children.item(c).getAttributes(); 261 Node attribute = atts.getNamedItem("type"); 262 String type = attribute.getNodeValue(); 263 classifier = new CollectionClassifier(type, children.item(c)); 264 265 // attach the classifier 266 ClassifierInterface classify = classifier.getClassifier(); 267 buildManager.getClassifierManager().addClassifier(classify); 125 268 } 126 269 // TODO: other elements - make a factory-method approach here... … … 128 271 { 129 272 } 273 } 274 275 Iterator indexers = indexerMap.values().iterator(); 276 while (indexers.hasNext()) { 277 IndexerInterface indexer = (IndexerInterface) indexers.next(); 278 279 // attach the classifier 280 buildManager.getIndexerManager().addIndexer(indexer); 130 281 } 131 282 }
Note:
See TracChangeset
for help on using the changeset viewer.