Changeset 7268


Ignore:
Timestamp:
2004-05-04T17:04:47+12:00 (20 years ago)
Author:
cs025
Message:

Updated Hierarchy classifiers; small other changes

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier
Files:
3 edited

Legend:

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

    r7188 r7268  
    5151   */
    5252  public AbstractHierarchyNode()
    53   { this.descriptor = null;
    54     this.name       = null;
    55     this.id         = null;
    56     this.prefix     = null;
     53  { this.descriptor = "";
     54    this.name       = "";
     55    this.id         = "";
     56    this.prefix     = "";
    5757    this.childNodes = new ArrayList();
    5858    this.childDocs  = new ArrayList();
     
    7878    child.setParent(this);
    7979
    80     /*
     80    /**
    8181    if (this.id == null) {
    8282      System.out.println(child.id.toString() + " added to root");
     
    8989
    9090  public boolean add(AbstractHierarchyNode child)
    91   { if (this.id != null &&
     91  { if (this.id != null && this.id.length() > 0 &&
    9292        !child.id.startsWith(this.id + "."))
    9393    { return false;
     
    256256  {
    257257    int classifyRef;
    258     GS3SQLAction action;
     258    GS3SQLAction action = null;
    259259    GS3SQLSelect select;
    260260    GS3SQLInsert insert;
     261
     262    // Get own full id
     263    String fullId = this.id.length() > 0 ? this.prefix+"."+this.id : this.prefix;
    261264
    262265    // check for an existing instance of this classifier
    263266    select = new GS3SQLSelect("classifiers");
    264267    select.addField("ClassifyRef");
    265     GS3SQLWhereItem whereItem = new GS3SQLWhereItem("ClassifyID", "=", this.prefix+"."+this.id);
     268    GS3SQLWhereItem whereItem = new GS3SQLWhereItem("ClassifyID", "=", fullId);
    266269    GS3SQLWhere where = new GS3SQLWhere(whereItem);
    267270    select.setWhere(where);
     
    282285    insert = new GS3SQLInsert("classifiers");
    283286
    284     String parentId = this.getParentId();
    285 
    286     if (parentId.length() > 0) {
    287       insert.addValue("ParentID", this.prefix+"."+this.getParentId());
     287    if (this.id == null || this.id.length() == 0) {
     288      insert.addValue("ParentID", "");
    288289    }
    289290    else {
    290       insert.addValue("ParentID", this.prefix);
     291      String parentId = this.getParentId();
     292
     293      if (parentId.length() > 0) {
     294        insert.addValue("ParentID", this.prefix+"."+this.getParentId());
     295      }
     296      else {
     297        insert.addValue("ParentID", this.prefix);
     298      }
    291299    }
    292300
    293301    action = insert;
    294302      }
    295       action.addValue("ClassifyID", this.prefix+"."+this.id);
     303      action.addValue("ClassifyID", fullId);
    296304      action.addValue("Name", this.name);
    297305      action.addValue("Description", this.descriptor);
    298       action.addValue("ClassifyOrder", this.id, GS3SQLField.INTEGER_TYPE);
     306
     307      String tailId = "0";
     308      if (this.id.length() > 0) {
     309    int lastDot = this.id.lastIndexOf('.');
     310    if (lastDot >= 0) {
     311      tailId = this.id.substring(lastDot+1);
     312    }
     313    else {
     314      tailId = this.id;
     315    }
     316      }
     317      action.addValue("ClassifyOrder", tailId, GS3SQLField.INTEGER_TYPE);
    299318      action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE);
    300319
     
    303322    }
    304323    catch (SQLException sqlEx) {
    305       System.err.println(sqlEx);
     324      if (action == null) {
     325    System.err.println(sqlEx);
     326      }
     327      else {
     328    System.err.println(sqlEx + " " + action.toString());
     329      }
    306330      return false;
    307331    }
     
    341365
    342366      if (!childNode.writeSQL(connection)) {
     367      System.out.println("Failed to write " );
    343368    return false;
    344369      }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/GS2HierarchyClassifier.java

    r6496 r7268  
    9797    { super(content);
    9898 
    99       this.rootNode = new GS2HierarchyNode();
    10099      String prefix = "CL"+hierarchyName;
     100      this.rootNode = new GS2HierarchyNode(prefix, hierarchyName, "", hierarchyName);
    101101
    102102      while (this.hasMoreLines()) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/HierarchyClassifier.java

    r7188 r7268  
    4747    public HierarchyNode()
    4848    { super();
     49    }
     50
     51    public HierarchyNode(String prefix, String name, String id, String descriptor)
     52    { super(prefix, name, id, descriptor);
    4953    }
    5054   
     
    7781    StringBuffer path;
    7882    StringBuffer match;
     83    String       prefix;
    7984    boolean inElement;
    8085    AbstractHierarchyNode rootNode = null;
    8186    AbstractHierarchyNode currentNode = null;
    82     List          rootNodes = null;
    83 
    84     HierarchyHandler()
     87
     88    HierarchyHandler(String classifierName)
    8589    { super();
    8690 
     
    8993      this.path        = null;
    9094      this.match       = null;
    91       this.rootNodes   = new ArrayList();
     95      this.prefix      = classifierName;
    9296    }
    9397
    9498    public void startElement(String URI, String localName, String qName, Attributes attributes)
    95     { if (localName.equals("Classification"))
     99    { if (localName.equals("Hierarchy"))
    96100      { // create a new node in the hierarchy
    97     HierarchyNode node = new HierarchyNode();
     101    HierarchyNode node = new HierarchyNode(prefix, "", "", "Classifier");
     102
     103    this.rootNode = node;
     104    this.currentNode = node;
     105      }
     106      else if (localName.equals("Classification"))
     107      { // create a new node in the hierarchy
     108    HierarchyNode node = new HierarchyNode(this.prefix, "", "", "");
    98109
    99110    // Initialise the tree
     
    127138    { if (localName.equals("Classification"))
    128139      { if (this.currentNode.getParent() == null) {
    129           this.rootNodes.add(this.currentNode);
     140      // TODO: Error state
     141          // this.rootNodes.add(this.currentNode);
    130142        }
    131143    this.currentNode = this.currentNode.getParent();
     
    133145      else if (localName.equals("Name"))
    134146      { this.currentNode.setName(XMLTools.cleanString(this.name.toString()));
     147      System.out.println("Name is " + this.name);
    135148        this.name = null;
    136149      }
     
    177190  private List             fields;
    178191  private String           sortBy;
    179 
    180   public HierarchyClassifier(URL basefile, List fields, String sortBy)
     192  private String           name;
     193
     194  public HierarchyClassifier(String name, URL basefile, List fields, String sortBy)
    181195  {
    182196    try
    183       { SAXParser parser = new SAXParser();
    184       HierarchyHandler handler = new HierarchyHandler();
     197    { SAXParser parser = new SAXParser();
     198      HierarchyHandler handler = new HierarchyHandler(name);
    185199      /*
    186200      XMLReader reader = XMLReaderFactory.createXMLReader();
Note: See TracChangeset for help on using the changeset viewer.