Changeset 6870


Ignore:
Timestamp:
2004-02-24T11:09:11+13:00 (20 years ago)
Author:
kjdon
Message:

now uses GSXML static strings for elem and att names, uses GSFile methods to find directories and config files for a collection, uses site name as well as coll name, sql database name is now a combination of sitename and collname

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r6735 r6870  
    3434import org.greenstone.gsdl3.gs3build.util.GS3SQLConnectionFactory;
    3535import org.greenstone.gsdl3.gs3build.util.DOMUtils;
     36
     37import org.greenstone.gsdl3.util.GSFile;
     38import org.greenstone.gsdl3.util.GSXML;
    3639
    3740/**
     
    5255  GS3SQLConnection   database;       // the database to store everything in
    5356  String             collectionHome;
     57    String           siteHome;
    5458  String             collectionName;
    55 
     59    String           qualifiedCollectionName; // used as the database name
     60
     61   
    5662  class CollectionClassifier
    5763  { File file;
     
    111117   *  Create the collection manager for a given collection
    112118   *
    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
    114121   */
    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);
    119151    /*    if (this.database != null) {
    120152      this.database.clearCollection(collection);
     
    124156    if (this.database == null) {
    125157      this.database = GS3SQLConnectionFactory.createConnection("test");
    126       this.database.initCollection(collection);
     158      this.database.initCollection(this.qualifiedCollectionName);
    127159    }
    128160
    129161    this.metadata = new CollectionMetadata();
    130162
    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));
    146165    if (!buildDirectory.exists()) {
    147166      buildDirectory.mkdir();
    148167    }
    149168
    150     File archiveDirectory = new File(this.collectionHome, "archives");
     169    File archiveDirectory = new File(GSFile.collectionArchiveDir(this.collectionHome));
    151170    if (!archiveDirectory.exists()) {
    152171      archiveDirectory.mkdir();
     
    169188      System.out.println(name);
    170189
    171       if (name.equals("classifier"))
     190      if (name.equals(GSXML.CLASSIFIER_ELEM))
    172191      {
    173192    NamedNodeMap atts = children.item(c).getAttributes();
    174     Node attribute = atts.getNamedItem("type");
     193    Node attribute = atts.getNamedItem(GSXML.TYPE_ATT);
    175194    if (attribute == null) {
    176195      continue;
     
    190209
    191210  public void configureCollection(BuildManager buildManager)
    192   { File collectionConfig = new File(collectionHome, "/etc/collectionConfig.xml");
     211  { File collectionConfig = new File(GSFile.collectionConfigFile(this.collectionHome));
    193212   
    194213    // get the File and read it in
     
    207226      Element rootElement = document.getDocumentElement();
    208227
    209       if (rootElement.getTagName() != "collectionConfig")
     228      if (rootElement.getTagName() != GSXML.COLLECTION_CONFIG_ELEM)
    210229      { // TODO: throw exception
    211230      }
     
    223242
    224243    // the name is a plugin element
    225     if (name.equals("search")) {
     244    if (name.equals(GSXML.SEARCH_ELEM)) {
    226245      // pick up attributes from the <search> tag now...
    227246      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);
    232257      String searchName = null;
    233 
    234258      if (searchAttribute != null) {
    235         searchName = searchAttribute.getNodeValue();
     259          searchName = searchAttribute.getNodeValue();
    236260      }
    237261
     
    249273      buildManager.addIndexer(indexer);
    250274    }
    251     else if (name.equals("browse"))
     275    else if (name.equals(GSXML.BROWSE_ELEM))
    252276    { this.configureBrowsers(buildManager, children.item(c));
    253277    }
     
    276300
    277301  public String getEtcDirectory()
    278   { return this.collectionHome + File.separator + "etc";
     302 
     303  { return GSFile.collectionEtcDir(this.collectionHome);
    279304  }
    280305
    281306  public String getImportDirectory()
    282   { return this.collectionHome + File.separator + "import";
     307  { return GSFile.collectionImportDir(this.collectionHome);
    283308  }
    284309
    285310  public String getBuildDirectory()
    286   { return this.collectionHome + File.separator + "building";
     311  { return GSFile.collectionBuildDir(this.collectionHome);
    287312  }
    288313
    289314  public String getArchiveDirectory()
    290   { return this.collectionHome + File.separator + "archives";
     315  { return GSFile.collectionArchiveDir(this.collectionHome);
    291316  }
    292317
Note: See TracChangeset for help on using the changeset viewer.