Changeset 6870
- Timestamp:
- 2004-02-24T11:09:11+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java
r6735 r6870 34 34 import org.greenstone.gsdl3.gs3build.util.GS3SQLConnectionFactory; 35 35 import org.greenstone.gsdl3.gs3build.util.DOMUtils; 36 37 import org.greenstone.gsdl3.util.GSFile; 38 import org.greenstone.gsdl3.util.GSXML; 36 39 37 40 /** … … 52 55 GS3SQLConnection database; // the database to store everything in 53 56 String collectionHome; 57 String siteHome; 54 58 String collectionName; 55 59 String qualifiedCollectionName; // used as the database name 60 61 56 62 class CollectionClassifier 57 63 { File file; … … 111 117 * Create the collection manager for a given collection 112 118 * 113 * @param <code>String</code> the name of the collection 119 * @param site the name of the site 120 * @param collection <code>String</code> the name of the collection 114 121 */ 115 public CollectionManager(String collection) 116 { String collectRoot = System.getProperty("GSDL3HOME"); 117 118 this.database = GS3SQLConnectionFactory.createConnection(collection); 122 public CollectionManager(String site, String collection) { 123 124 String gsdl3Root = System.getProperty("GSDL3HOME"); 125 if (gsdl3Root == null) { 126 System.out.println("Error: Unable to locate GSDL3HOME"); 127 System.exit(1); 128 //return; 129 } 130 131 this.siteHome = GSFile.siteHome(gsdl3Root, site); 132 File site_dir = new File(this.siteHome); 133 if (!site_dir.exists()) { 134 System.out.println("Error: Non-existant site ("+site+") specified"); 135 System.exit(1); 136 } 137 site_dir = null; 138 this.collectionHome = GSFile.collectionBaseDir(this.siteHome, collection); 139 140 File collect_dir = new File(this.collectionHome); 141 if (!collect_dir.exists()) { 142 System.out.println("Error: Non-existant collection ("+collection+") specified in site "+site); 143 System.exit(1); 144 } 145 collect_dir = null; 146 147 this.collectionName = collection; 148 this.qualifiedCollectionName = site+"_"+collection; 149 150 this.database = GS3SQLConnectionFactory.createConnection(this.qualifiedCollectionName); 119 151 /* if (this.database != null) { 120 152 this.database.clearCollection(collection); … … 124 156 if (this.database == null) { 125 157 this.database = GS3SQLConnectionFactory.createConnection("test"); 126 this.database.initCollection( collection);158 this.database.initCollection(this.qualifiedCollectionName); 127 159 } 128 160 129 161 this.metadata = new CollectionMetadata(); 130 162 131 if (collectRoot == null) 132 { System.out.println("Unable to locate GSDL3HOME"); 133 // System.exit(1); 134 return; 135 } 136 137 if (collectRoot.endsWith(System.getProperty("file.separator"))) 138 { this.collectionHome = collectRoot + "web/sites/localsite/collect" + System.getProperty("file.separator") + collection; 139 } 140 else 141 { this.collectionHome = collectRoot + System.getProperty("file.separator") + "web/sites/localsite/collect" + System.getProperty("file.separator") + collection; 142 } 143 this.collectionName = collection; 144 145 File buildDirectory = new File(this.collectionHome, "building"); 163 164 File buildDirectory = new File(GSFile.collectionBuildDir(this.collectionHome)); 146 165 if (!buildDirectory.exists()) { 147 166 buildDirectory.mkdir(); 148 167 } 149 168 150 File archiveDirectory = new File( this.collectionHome, "archives");169 File archiveDirectory = new File(GSFile.collectionArchiveDir(this.collectionHome)); 151 170 if (!archiveDirectory.exists()) { 152 171 archiveDirectory.mkdir(); … … 169 188 System.out.println(name); 170 189 171 if (name.equals( "classifier"))190 if (name.equals(GSXML.CLASSIFIER_ELEM)) 172 191 { 173 192 NamedNodeMap atts = children.item(c).getAttributes(); 174 Node attribute = atts.getNamedItem( "type");193 Node attribute = atts.getNamedItem(GSXML.TYPE_ATT); 175 194 if (attribute == null) { 176 195 continue; … … 190 209 191 210 public void configureCollection(BuildManager buildManager) 192 { File collectionConfig = new File( collectionHome, "/etc/collectionConfig.xml");211 { File collectionConfig = new File(GSFile.collectionConfigFile(this.collectionHome)); 193 212 194 213 // get the File and read it in … … 207 226 Element rootElement = document.getDocumentElement(); 208 227 209 if (rootElement.getTagName() != "collectionConfig")228 if (rootElement.getTagName() != GSXML.COLLECTION_CONFIG_ELEM) 210 229 { // TODO: throw exception 211 230 } … … 223 242 224 243 // the name is a plugin element 225 if (name.equals( "search")) {244 if (name.equals(GSXML.SEARCH_ELEM)) { 226 245 // pick up attributes from the <search> tag now... 227 246 NamedNodeMap searchAttributes = children.item(c).getAttributes(); 228 Node searchAttribute = searchAttributes.getNamedItem("type"); 229 String searchType = searchAttribute.getNodeValue(); 230 231 searchAttribute = searchAttributes.getNamedItem("name"); 247 Node searchAttribute = searchAttributes.getNamedItem(GSXML.TYPE_ATT); 248 String searchType = null; 249 if (searchAttribute != null) { 250 searchType = searchAttribute.getNodeValue(); 251 } else { 252 System.out.println("no "+GSXML.TYPE_ATT+" attribute found for the "+GSXML.SEARCH_ELEM+" element, assuming mg"); 253 searchType = MGIndexer.MG_INDEX_TYPE; 254 } 255 256 searchAttribute = searchAttributes.getNamedItem(GSXML.NAME_ATT); 232 257 String searchName = null; 233 234 258 if (searchAttribute != null) { 235 searchName = searchAttribute.getNodeValue();259 searchName = searchAttribute.getNodeValue(); 236 260 } 237 261 … … 249 273 buildManager.addIndexer(indexer); 250 274 } 251 else if (name.equals( "browse"))275 else if (name.equals(GSXML.BROWSE_ELEM)) 252 276 { this.configureBrowsers(buildManager, children.item(c)); 253 277 } … … 276 300 277 301 public String getEtcDirectory() 278 { return this.collectionHome + File.separator + "etc"; 302 303 { return GSFile.collectionEtcDir(this.collectionHome); 279 304 } 280 305 281 306 public String getImportDirectory() 282 { return this.collectionHome + File.separator + "import";307 { return GSFile.collectionImportDir(this.collectionHome); 283 308 } 284 309 285 310 public String getBuildDirectory() 286 { return this.collectionHome + File.separator + "building";311 { return GSFile.collectionBuildDir(this.collectionHome); 287 312 } 288 313 289 314 public String getArchiveDirectory() 290 { return this.collectionHome + File.separator + "archives";315 { return GSFile.collectionArchiveDir(this.collectionHome); 291 316 } 292 317
Note:
See TracChangeset
for help on using the changeset viewer.