Changeset 6345


Ignore:
Timestamp:
2004-01-06T11:43:53+13:00 (20 years ago)
Author:
cs025
Message:

Minor changes to build and collection managers

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  
    6868    // set up the indexers
    6969    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);
    7573
    7674    // prepare a file crawler on the etc directory, and a crawl observer to respond to
     
    8886  public ClassifierManager getClassifierManager()
    8987  { 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);
    9097  }
    9198
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r6099 r6345  
    33import java.util.Date;
    44import java.util.Calendar;
     5import java.util.List;
     6import java.util.ArrayList;
     7import java.util.Map;
     8import java.util.HashMap;
     9import java.util.Iterator;
    510import java.util.GregorianCalendar;
    611
    712import java.io.File;
    813import java.io.IOException;
     14
     15import java.net.URL;
    916
    1017import javax.xml.parsers.*;
     
    2128
    2229import org.greenstone.gsdl3.gs3build.collection.*;
     30import org.greenstone.gsdl3.gs3build.classifier.*;
     31import org.greenstone.gsdl3.gs3build.indexers.*;
    2332
    2433import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
    2534import org.greenstone.gsdl3.gs3build.util.GS3SQLConnectionFactory;
     35import org.greenstone.gsdl3.gs3build.util.DOMUtils;
    2636
    2737/**
     
    3545public class CollectionManager
    3646{
    37   GregorianCalendar  lastBuildDate; // pretty obvious
    38   String             adminEmail;    // the email address of the administrator of the
    39                                         // collection
    40   int                buildDocNo;    // used to generate document identifiers
    41   CollectionMetadata metadata;      // collection-level metadata
    42   GS3SQLConnection   database;      // the database to store everything in
     47  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
    4353  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  }
    44157
    45158  /**
     
    52165 
    53166    this.database = GS3SQLConnectionFactory.createConnection(collection);
     167    if (this.database != null) {
     168      this.database.clearCollection(collection);
     169      this.database = null;
     170    }
    54171    if (this.database == null) {
    55172      this.database = GS3SQLConnectionFactory.createConnection("test");
     
    61178    if (collectRoot == null)
    62179    { System.out.println("Unable to locate GSDL3HOME");
    63     //      System.exit(1);
    64     return;
     180      //      System.exit(1);
     181      return;
    65182    }
    66183
     
    71188    { this.collectionHome = collectRoot + System.getProperty("file.separator") + "web/sites/localsite/collect" + System.getProperty("file.separator") + collection;
    72189    }
     190    this.collectionName = collection;
    73191
    74192    File buildDirectory = new File(this.collectionHome, "building");
     
    83201
    84202    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");
    87207   
    88208    // get the File and read it in
     
    93213      Document document = builder.parse(collectionConfig);
    94214
     215      CollectionClassifier classifier = null;
     216
     217      Map                  indexerMap = new HashMap();
     218
    95219      // TODO: report an error
    96220      if (document == null)
     
    115239
    116240    // 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);
    119254    }
    120255    else if (name.equals("browse"))
    121256    {
    122257    }
    123     else if (name.equals("classify"))
     258    else if (name.equals("classifier"))
    124259    {
     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);
    125268    }
    126269    // TODO: other elements - make a factory-method approach here...
     
    128271    {
    129272    }
     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);   
    130281      }
    131282    }
Note: See TracChangeset for help on using the changeset viewer.