Changeset 9170


Ignore:
Timestamp:
2005-02-24T14:44:42+13:00 (19 years ago)
Author:
mdewsnip
Message:

Removed a whole lot of dead code.

Location:
trunk/gli/src/org/greenstone/gatherer/gems
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java

    r8978 r9170  
    266266    }
    267267
    268     public boolean hasValueTree() {
    269     return element.getAttribute(StaticStrings.VALUE_TREE_ATTRIBUTE).equalsIgnoreCase(StaticStrings.TRUE_STR);
    270     }
    271 
    272268    /** Increment the number of occurances of this metadata element.
    273269     * @see org.greenstone.gatherer.msm.MSMUtils
  • trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java

    r9085 r9170  
    424424
    425425
    426     /** Method to traverse the given value tree, and build up a hashtable of mappings between the value path key names and the Subject nodes of the tree.
    427      * @param current The root <strong>Node</strong> of a subtree of the AssignedValues tree.
    428      * @param prefix The value path key <strong>String</string>, which shows the path from the root of the AssignedValue tree to <i>current</i>s parent using '\' as a separator.
    429      * @param values A <strong>Hashtable</strong> containing the mapping discovered so far in our tree traversal.
    430      */
    431     static final private void getValueMappings(Node current, String prefix, Hashtable values) {
    432     if(current != null) {
    433         String name = current.getNodeName();
    434         String new_prefix = prefix;
    435         // If we've found the outer layer of a new value, add it to our mapping
    436         if(name.equals("Subject")) {
    437         Node value_node = getNodeFromNamed(current, "Value");
    438         String value = getValue(value_node);
    439         if(new_prefix != null) {
    440             new_prefix = new_prefix + "\\" + value;
    441         }
    442         else {
    443             new_prefix = value;
    444         }
    445         values.put(new_prefix, current);
    446         }
    447         if(name.equals("Subject") || name.equals("AssignedValues")) {
    448         for(Node child = current.getFirstChild(); child != null;
    449             child = child.getNextSibling()) {
    450             getValueMappings(child, new_prefix, values);
    451         }
    452         }
    453     }
    454     }
    455 
    456 
    457     /** Parses the value tree template file.
    458      * @return The Document parsed.
    459      */
    460     static final public Document getValueTreeTemplate() {
    461     return Utility.parse(GEMS.METADATA_VALUE_TEMPLATE, true);
    462     }
    463 
    464 
    465426    /** Determine if the named attribute is language specific for this collection. This information is found in a DOM attribute of the document element, as a comma separated list of attribute names.
    466427     * @param document the Document for which we wish to check the language requirements
     
    686647    }
    687648    }
    688  
    689 
    690     /** Method to determine if two Value nodes are equal.
    691      * @param av A <strong>Node</strong> representing a value.
    692      * @param bv The <strong>Node</strong> we want to compare it to.
    693      * @return A <i>boolean</i> which is <i>true</i> if the two value nodes are equal, <i>false</i> otherwise.
    694      */
    695     static final private boolean valuesEqual(Node av, Node bv) {
    696     // Check we are comparing apples and apples...
    697     if(av.getNodeName().equals("Value") &&
    698        bv.getNodeName().equals("Value")) {
    699         // Retrieve and then compare their text values.
    700         Node at = av.getFirstChild();
    701         Node bt = bv.getFirstChild();
    702         if(at.getNodeValue().equals(bt.getNodeValue())) {
    703         return true;
    704         }
    705     }
    706     return false;
    707     }
    708649}
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java

    r9103 r9170  
    6060    public String old_filename = null;
    6161    private File     file     = null;
    62     /** A mapping from metadata elements to the root element of the value trees for that element. */
    63     private Hashtable value_trees = null;
    6462    /** The list of metadata elements which are, of course, children of the root node. */
    6563    private ArrayList elements = null;
     
    8583   
    8684    this.file = new File(metadata_template);
    87     this.value_trees = new Hashtable();
    8885    this.document = Utility.parse(metadata_template, true);
    8986
     
    9693    public MetadataSet(File file) {
    9794    this.file = file;
    98     this.value_trees = new Hashtable();
    9995    this.document = XMLTools.parseXMLFile(file);
    10096
     
    106102     */
    107103    public MetadataSet(MetadataSet original) {
    108     this.value_trees = new Hashtable();
    109104    // We have to create a new document.
    110105    document = new DocumentImpl(original.getDocument().getDoctype());
     
    114109    //elements = root.getElementsByTagName("Element");
    115110    file = original.getFile();
    116     // Now for each element read in its value tree if present.
    117     for(int i = elements.size() - 1; i >= 0; i--) {
    118         ElementWrapper value_element_wrapper = new ElementWrapper((Element)elements.get(i));
    119         GValueModel value_tree = original.getValueTree(value_element_wrapper);
    120         Document value_document = value_tree.getDocument();
    121         Document value_document_copy = new DocumentImpl(value_document.getDoctype());
    122         Element value_element = value_document.getDocumentElement();
    123         Element value_element_copy = (Element) value_document_copy.importNode(value_element, true);
    124         value_document_copy.appendChild(value_element_copy);
    125         GValueModel value_tree_copy = new GValueModel(value_element_wrapper, value_document_copy);
    126         value_trees.put(value_element_wrapper, value_tree_copy);
    127     }
    128111    }
    129112 
     
    136119        setChanged = val;
    137120    }
    138       /** Conditional copy constructor.
    139      * @param original The original metadata set to copy from.
    140      * @param condition An <i>int</i> which matches one of the tree pruning filter types.
    141      */
    142     public MetadataSet(MetadataSet original, int condition) {
    143     this(original);
    144     // Now based on condition, we may have to remove some nodes from
    145     // this model.
    146     switch(condition) {
    147     case ALL_VALUES:
    148         // Do nothing.
    149         break;
    150     case SUBJECTS_ONLY:
    151         // For each element retrieve its AssignedValues element.
    152         for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
    153         ElementWrapper value_element = (ElementWrapper)keys.nextElement();
    154         GValueModel value_tree = (GValueModel)value_trees.get(value_element);
    155         Document value_tree_document = value_tree.getDocument();
    156         Element value_tree_root_element = value_tree_document.getDocumentElement();
    157         // Traverse tree and remove leaf nodes.
    158         MSMUtils.traverseTree(value_tree_root_element, MSMUtils.NONE, true);
    159         }
    160         break;
    161     case NO_VALUES:
    162         // Remove assigned values trees.
    163         value_trees.clear();
    164         break;
    165     }
    166     }
     121
    167122
    168123    public void setCollection(String coll) {
     
    213168    }
    214169
    215    
    216     /** Method to add a new metadata element to this metadata set, if and only if the element is not already present.
    217      * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
    218      * @param model A <strong>GValueModel</strong> value tree
    219      * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
    220      */
    221     public String addElement(Element others_element, GValueModel model) {
    222     if(!containsElement(others_element.getAttribute("name"))) {
    223         // First get ownership of the new element, then add it.
    224         Element our_element = (Element)document.importNode(others_element, true);
    225         // add the value tree
    226         root.appendChild(our_element);
    227         if (model != null) {
    228         addValueTree(new ElementWrapper(our_element), model);   
    229         }   
    230         return null;
    231     }
    232     else {
    233         return "MSMPrompt.Name_Exists";
    234     }
    235     }
    236 
    237     /** Method to add a new metadata element with the specified new name to this metadata set, if and only if the name is not already in use.
    238      * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
    239      * @param new_name The new name to be given this element, as a <strong>String</strong>.
    240      * @param model A <strong>GValueModel</strong> value tree
    241      * @return <i>null</i> if the add is successful, otherwise a <strong>String</strong> containing an error message (phrase key).
    242      */
    243     public String addElement(Element others_element, String new_name, GValueModel model) {
    244     if(!containsElement(new_name)) {
    245         // First get ownership of the new element, then add it.
    246         Element our_element =
    247         (Element) document.importNode(others_element, true);
    248         // Change name
    249         our_element.setAttribute("name", new_name);
    250         // we also want to change the english identifier of this element
    251         MSMUtils.setIdentifier(our_element, new_name);
    252         // Add it to teh set
    253         root.appendChild(our_element);
    254         // add the value tree
    255         if (model != null) {
    256         addValueTree(new ElementWrapper(our_element), model);
    257         }
    258         return null;
    259     }
    260     else {
    261         return "MSMPrompt.Name_Exists";
    262     }
    263     }
    264     /** Add a value tree to a given metadata element.
    265      * @param element The <strong>ElementWrapper</strong> containing the element you wish to add a value tree for.
    266      * @param model A <strong>GValueModel</strong> value tree
    267      */
    268     public void addValueTree(ElementWrapper element, GValueModel model) {
    269     ///ystem.err.println("Adding value tree for " + element.toString());
    270     value_trees.put(element, model);
    271     }
    272170
    273171    public int compare(Element e1, Element e2) {
     
    466364    return root;
    467365    }
    468     /** Retrieve the value tree from this set that matches the given element.
    469      * @param element The target <strong>ElementWrapper</strong>.
    470      * @return A <strong>GValueModel</strong> value tree, or <i>null</i> if no such element or value tree.
    471      */
    472     public GValueModel getValueTree(ElementWrapper element) {
    473     GValueModel value_tree = null;
    474     // Stinking hashtable get doesn't use the overridden equals. So I'll do a loop, which should be pretty small ie O(n) for n metadata elements.
    475     for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
    476         ElementWrapper sibling = (ElementWrapper) keys.nextElement();
    477         if(sibling.equals(element)) {
    478         value_tree = (GValueModel) value_trees.get(sibling);
    479         break;
    480         }
    481     }
    482     // If we've found no value tree, create a new one.
    483     if(value_tree == null) {
    484         value_tree = new GValueModel(element);
    485         value_trees.put(element, value_tree);
    486     }
    487     return value_tree;
    488     }
     366
    489367    /** Remove a mds level attribute.
    490368     * @param name The name of the attribute to remove.
     
    501379    try {
    502380        ElementWrapper element_wrapped = new ElementWrapper(element);
    503         removeValueTree(element_wrapped);
    504381
    505382        if(parent == null)
     
    531408   
    532409
    533     /** Used to remove the value tree for a specific element.
    534      * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove.
    535      * @return The <strong>GValueModel</strong> we just removed
    536      */
    537     public GValueModel removeValueTree(ElementWrapper element) {
    538     for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); )
    539         {
    540         ElementWrapper sibling = (ElementWrapper) keys.nextElement();
    541         if(sibling.equals(element))
    542             {
    543             GValueModel value_tree = (GValueModel) value_trees.get(sibling);
    544             value_trees.remove(sibling);
    545             return value_tree;
    546             }
    547         }
    548     return null;
    549     }
    550410    /** Set one of the mds level attributes.
    551411     * @param name The attribute to change.
     
    683543        this.root = document.getDocumentElement();
    684544        this.elements = XMLTools.getChildElementsByTagName(root, "Element");
    685         // Now for each element read in its value tree if present.
    686         for(int i = elements.size() - 1; i >= 0; i--) {
    687         ElementWrapper value_element = new ElementWrapper((Element)elements.get(i));
    688         File value_file = new File(file.getParentFile(), value_element.getName() + ".mdv");
    689         ///ystem.err.println("Searching for " + value_file.getAbsolutePath());
    690         if(value_file.exists()) {
    691             Document value_document;
    692             if (use_classloader) {
    693             value_document = Utility.parse(value_file.toString(), true);
    694             }
    695             else {
    696             value_document = XMLTools.parseXMLFile(value_file);
    697             }
    698             if(value_document != null) {
    699             value_trees.put(value_element, new GValueModel(value_element, value_document));
    700             }
    701             else {
    702             DebugStream.println("Error! Missing mdv file: " + value_file.getAbsolutePath());
    703             }
    704         }
    705         }
    706545    }
    707546    else {
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java

    r9085 r9170  
    120120        System.err.println("Error: no such set \'" + current_set + "\'");
    121121        }
    122     }
    123 
    124 
    125     /** Add a value tree to a given metadata element represented as a GValueModel
    126      * @param model The <strong>GValueTree</strong> model
    127      */
    128     public void addValueTree(GValueModel model) {
    129     ElementWrapper element = model.getElement();
    130     String namespace = element.getNamespace();
    131     MetadataSet mds = (MetadataSet) mds_hashtable.get(namespace);
    132     if(mds != null) {
    133         mds.addValueTree(element, model);
    134     }
    135122    }
    136123
     
    314301 
    315302
    316     /** Get the value tree that matches the given element.
    317      * @param element The ElementWrapper representing the element.
    318      * @return The GValueModel representing the value tree or null.
    319      */
    320     public GValueModel getValueTree(ElementWrapper element) {
    321     GValueModel value_tree = null;
    322     if(element != null) {
    323         String namespace = element.getNamespace();
    324         if(namespace.length() > 0) {
    325         MetadataSet mds = (MetadataSet) mds_hashtable.get(namespace);
    326         if(mds != null) {
    327             value_tree = mds.getValueTree(element);
    328         }
    329         }
    330     }
    331     return value_tree;
    332     }
    333 
    334 
    335303    public MetadataSet loadMetadataSet(File metadata_set_file)
    336304    {
     
    430398
    431399
    432     /*Following write() and write() and save() were taken from msm/metadatasetmanager.java and converted to
    433      *the gems standard
    434      */
    435      private void write(ElementWrapper element, GValueModel model, String etc_dir) {
    436     try {
    437         File out_file = new File(etc_dir + element.getName() + ".txt");
    438         FileOutputStream fos = new FileOutputStream(out_file);
    439         OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
    440         BufferedWriter bw = new BufferedWriter(osw, Utility.BUFFER_SIZE);
    441         Vector all_values = model.traverseTree();
    442         for(int i = 0; i < all_values.size(); i++) {
    443         GValueNode node = (GValueNode)all_values.get(i);
    444         String full_value = node.getFullPath(false);
    445         String index = model.getHIndex(full_value);
    446 
    447         write(bw, "\"" + full_value + "\"\t" + index + "\t\"" + node.toString(GValueNode.GREENSTONE) + "\"");
    448         }
    449         // Very important we do this, or else buffer may not be flushed
    450         bw.flush();
    451         bw.close();
    452     }
    453     catch(Exception error) {
    454         error.printStackTrace();
    455     }
    456     }
    457 
    458     private void write(Writer w, String text)
    459     throws Exception {
    460     text = text + "\r\n";
    461     char buffer[] = text.toCharArray();
    462     w.write(buffer, 0, buffer.length);
    463     }
    464 
    465400    public void save() {
    466401    File file = new File(Utility.METADATA_DIR);
  • trunk/gli/src/org/greenstone/gatherer/gems/TransformCharacterTextField.java

    r9079 r9170  
    2727package org.greenstone.gatherer.gems;
    2828
    29 /**************************************************************************************
    30  * Written:     04/07/03
    31  * Revised:     
    32  **************************************************************************************/
    3329import java.util.*;
    3430import javax.swing.*;
    3531import javax.swing.text.*;
     32
     33
    3634/** A JTextField that doesn't allow certain characters, either blocking or replacing them
    3735 * @author John Thompson, Greenstone Digital Library, University of Waikato
     
    6462    }
    6563
    66 //      public void blockCharacter(char x) {
    67 //      mappings.put(new Character(x), null);
    68 //      }
    69 
    7064    public void replaceCharacter(char x, char y) {
    7165    mappings.put(new Character(x), new Character(y));
    7266    }
    73 
    74 //      public void restoreCharacter(char x) {
    75 //      mappings.remove(new Character(x));
    76 //      }
    7767
    7868    public void setBlockAllExceptMappings(boolean block_all_except_mappings) {
Note: See TracChangeset for help on using the changeset viewer.