Changeset 5672


Ignore:
Timestamp:
2003-10-17T04:50:35+13:00 (21 years ago)
Author:
jmt12
Message:

Not only did I rewrite the toString method to require a parameter specifying what sort of string should be returned, RAW, DOM or GREENSTONE, I also fixed a stupid bug when removing child nodes, which has made the MEM a thousand times more stable (OK so its probably closer to 5. Perhaps 2, yes 2 times more stable)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java

    r5581 r5672  
    6262    extends DefaultMutableTreeNode {
    6363
     64   static final public int DOM = 0;
     65   static final public int GREENSTONE = 1;
     66   static final public int TEXT = 2;
     67   
    6468    private String element_name = null;
    6569    private String default_value = null;
     
    221225    }
    222226
    223     public GValueNode getValue(String value) {
    224     if(default_value != null) {
    225         return this;
    226     }
    227     if(children == null) {
    228         map();
    229     }
    230     for(int i = 0; i < children.size(); i++) {
    231         GValueNode child = (GValueNode) children.get(i);
    232         if(child.toString(false).equalsIgnoreCase(value)) {
    233         return child;
    234         }
    235     }
    236     return null;
    237     }
     227   public GValueNode getValue(String value) {
     228      ///ystem.err.println("GValueNode.getValue(" + value + ")");
     229      if(default_value != null) {
     230     return this;
     231      }
     232      if(children == null) {
     233     map();
     234      }
     235      for(int i = 0; i < children.size(); i++) {
     236     GValueNode child = (GValueNode) children.get(i);
     237     ///ystem.err.println("Comparing value and '" + child.toString(GValueNode.DOM));
     238     if(child.toString(GValueNode.DOM).equalsIgnoreCase(value)) {
     239        return child;
     240     }
     241      }
     242      return null;
     243   }
    238244
    239245    /** Adds <I>child</I> to the receiever at <I>index</I>. <I>child</I> will
     
    321327     */
    322328    public String toString() {
    323     return toString(true);
     329    return toString(GValueNode.TEXT);
    324330    }
    325331   
    326     public String toString(boolean as_text) {
     332    public String toString(int decode_type) {
    327333    if(default_value != null) {
    328334        return default_value;
     
    332338    String result = null;
    333339    if(name.equals("Subject")) {
    334         if(as_text) {
    335         result = Codec.transform(MSMUtils.getValue(element), Codec.GREENSTONE_TO_TEXT);
    336         }
    337         else {
    338         result = MSMUtils.getValue(element);
    339         }
     340       result = MSMUtils.getValue(element);
     341       switch(decode_type) {
     342          case GValueNode.GREENSTONE:
     343         // We want this as greenstone format
     344         ///ystem.err.print(result);
     345         result = Codec.transform(result, Codec.DOM_TO_GREENSTONE);
     346         ///ystem.err.println(" -> D2G decode -> " + result);
     347         break;
     348          case GValueNode.TEXT:
     349         ///ystem.err.print(result);
     350         result = Codec.transform(result, Codec.DOM_TO_TEXT);
     351         ///ystem.err.println(" -> D2T decode -> " + result);
     352         break;
     353          default:
     354         ///ystem.err.println(result + " -> nothing to do.");
     355       }
    340356    }
    341357    else if(name.equals("AssignedValues")) {
     
    364380    public void remove(MutableTreeNode node) {
    365381    children.remove(node);
    366     parent = null;
     382    node.setParent(null);
    367383    // Remove from DOM
    368     Node child_node = (Node) userObject;
    369     Node parent_node = child_node.getParentNode();
    370     parent_node.removeChild(child_node);
     384    Element child_element = ((GValueNode)node).getElement();
     385    Node parent_node = child_element.getParentNode();
     386    parent_node.removeChild(child_element);
    371387    }
    372388         
Note: See TracChangeset for help on using the changeset viewer.