Changeset 5805 for trunk


Ignore:
Timestamp:
2003-11-07T13:20:43+13:00 (20 years ago)
Author:
jmt12
Message:

Several changes needed to make pipe the hierarchy separator while keeping backslash as what the user sees

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

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/Codec.java

    r5707 r5805  
    3737 */
    3838public class Codec {
    39    
     39
    4040   static final public String DOM_TO_GREENSTONE = "DOM_TO_GREENSTONE";
    4141   static final public String DOM_TO_TEXT = "DOM_TO_TEXT";
     
    4949
    5050    static final private int MAX_CACHE_SIZE = 100;
    51    
     51
    5252    static private HashMap TRANSFORMS;
    5353    static private HashMap3D CACHE;
    5454
    55    
     55
    5656    /** Static function called to construct TRANSFORMS mappings */
    5757    static {
    5858    TRANSFORMS = new HashMap();
    59    
     59
    6060    // Translate DOM encoded text into Greenstone encoding
    6161    String[] dom_to_greenstone = {
     
    6969    TRANSFORMS.put(DOM_TO_GREENSTONE, dom_to_greenstone);
    7070    dom_to_greenstone = null;
    71    
     71
    7272    // Transform DOM encoded text into plain text
    7373    String[] dom_to_text = {
     
    7878       "&lt;", "<",
    7979       "&quot;", "\"",
    80        "&amp;", "&"
     80       "&amp;", "&",
     81       "\\|", "\\\\"
    8182    };
    8283    TRANSFORMS.put(DOM_TO_TEXT, dom_to_text);
     
    104105        "&#091;", "\\[",
    105106        "&#093;", "\\]",
    106         "\\\\\\\\", "\\\\"
     107        "\\|", "\\\\"
    107108    };
    108109    TRANSFORMS.put(GREENSTONE_TO_TEXT, greenstone_to_text);
     
    116117    TRANSFORMS.put(REMOVE_SQUARE_BRACKET, remove_square_bracket);
    117118    remove_square_bracket = null;
    118    
     119
    119120    // Transform plain html text into something that can be placed in a DOM
    120121    String[] text_to_dom = {
     
    123124        ">", "&gt;",
    124125        "\"", "&quot;",
    125         "\'", "&apos;"
     126        "\'", "&apos;",
     127        "\\\\", "\\|",
    126128    };
    127129    TRANSFORMS.put(TEXT_TO_DOM, text_to_dom);
     
    130132    // Transform plain html text into greenstone encoding
    131133    String[] text_to_greenstone = {
    132         "\\\\", "\\\\\\\\",
     134        "\\\\", "\\|",
    133135        "\\[", "&#091;",
    134136        "\\]", "&#093;",
     
    192194    static final private char UPPER_U_CHAR = 'U';
    193195    static final private char SEMICOLON_CHAR = ';';
    194  
     196
    195197    static public String transformUnicode(String raw) {
    196198    StringBuffer processed = new StringBuffer();
  • trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java

    r5581 r5805  
    3232import org.greenstone.gatherer.msm.ElementWrapper;
    3333import org.greenstone.gatherer.msm.MetadataSetManager;
     34import org.greenstone.gatherer.util.StaticStrings;
    3435import org.greenstone.gatherer.util.Utility;
    3536import org.greenstone.gatherer.valuetree.GValueModel;
     
    5556        GValueNode node = (GValueNode)all_values.get(i);
    5657        TreePath path = new TreePath(node.getPath());
    57         String value = node.getFullPath(false);
    58         String index = model.getHIndex(value);
    59         String alias = node.getAlias(index);
    60         if(value.indexOf(GValueModel.PATH_SEP) != -1) {
    61             value = value.substring(value.lastIndexOf(GValueModel.PATH_SEP) + GValueModel.PATH_SEP.length());
    62         }
    63         write(bw, "\"" + Utility.stripNL(value) + "\"\t" + index + "\t\"" + Utility.stripNL(value) + "\"");
     58        String full_value = node.getFullPath(true);
     59        String index = model.getHIndex(full_value);
     60
     61        write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(full_value) + "\"");
    6462        }
    65         // Very important we do this, or else buffer may not have 
     63        // Very important we do this, or else buffer may not have
    6664        // flushed.
    6765        bw.flush();
  • trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r5746 r5805  
    128128    static final public String OPTIONS_ATTRIBUTE                          = "options";
    129129    static final public String PERL_ARGUMENT                              = "-perl";
     130    static final public String PIPE_STR                                   = "|";
    130131    static final public String PLUGIN_ELEMENT                             = "Plugin";
    131132    static final public String PLUGIN_STR                                 = "plugin";
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java

    r5785 r5805  
    3333import org.greenstone.gatherer.msm.MSMUtils;
    3434import org.greenstone.gatherer.util.PatternTokenizer;
     35import org.greenstone.gatherer.util.StaticStrings;
    3536import org.greenstone.gatherer.util.Utility;
    3637import org.w3c.dom.*;
     
    3940 * @version 2.1
    4041 */
    41 public class GValueModel 
     42public class GValueModel
    4243    extends DefaultTreeModel {
    43 
    44     static final public String PATH_SEP = "\\\\";
    45     static final public String PATH_SEP_PATTERN = "\\\\\\\\";
    4644
    4745    private ElementWrapper element;
     
    7472
    7573    /** Value may include path ie news\newssw */
    76     public GValueNode addValue(String value) {     
     74    public GValueNode addValue(String value) {
    7775       try {
    7876        // Tokenize the string using the escaped character
    79         PatternTokenizer tokenizer = new PatternTokenizer(value, PATH_SEP);
     77        PatternTokenizer tokenizer = new PatternTokenizer(value, StaticStrings.PIPE_STR);
    8078        GValueNode subject = (GValueNode) root;
    8179        while(tokenizer.hasMoreTokens() && subject != null) {
     
    107105        new_subject.appendChild(new_alias);
    108106        Text new_alias_text = document.createTextNode(alias);
    109         new_alias.appendChild(new_alias_text);                 
    110         } 
     107        new_alias.appendChild(new_alias_text);
     108        }
    111109        value_node = new GValueNode(new_subject);
    112110        ///ystem.err.println("(GValueModel) addValue()... " + value_node);
    113        
    114         // Figure out where this node will be inserted in subjects 
     111
     112        // Figure out where this node will be inserted in subjects
    115113        // children.
    116114        int position = -1;
     
    148146     * @param value The value whose index you wish to determine as a <strong>String</strong>.
    149147     * @return A <strong>String</strong> containing an index such as "1", "2.1" or "18.2.5".
    150      */ 
     148     */
    151149    public String getHIndex(String value) {
    152150    ///ystem.err.println("getHIndex(" + value + ")");
     
    244242    }
    245243
    246     /** Called to update a certain value of metadata within a specific
    247      * subject within a sbject hierarchy.
    248      * Note that this simply in turn calls removeValue() to deal with the
    249      * old value, then addValue() to account for the new.
    250      * @param new_value A String representing the updated value.
    251      * @param old_value A String representing the old value.
    252      * @param subject An Element representing the subject you wish to update
    253      * this value in.
    254      */
    255     /* private GValueNode updateValue(String new_value, String old_value, GValueNode subject) {
    256     return addValue(new_value, subject, null);
    257     } */
    258 
    259244    private GValueModel copy() {
    260245    Element document_element = ((GValueNode) root).getElement();
     
    268253        }
    269254    }
    270     return new GValueModel(element, document_copy);                 
     255    return new GValueModel(element, document_copy);
    271256    }
    272257
    273258    private String getHIndex(GValueNode node, String value, String index) {
     259        ///ystem.err.println("Get the HIndex for: " + value);
    274260    for(int i = node.size(); i != 0; i--) {
    275261        GValueNode next = (GValueNode)node.get(i - 1);
    276262        String next_str = next.toString();
     263        ///ystem.err.println("Does " + value + " start with " + next_str + "?");
    277264        if(value.startsWith(next_str)) {
    278265        if(index == null) {
     
    283270        }
    284271        value = value.substring(next.toString().length());
    285         if(value.startsWith(PATH_SEP)) {
    286             value = value.substring(2);
     272        ///ystem.err.println("We matched the start so value is now: " + value);
     273        if(value.startsWith(StaticStrings.PIPE_STR) || value.startsWith(StaticStrings.ESCAPE_STR)) {
     274            value = value.substring(1);
    287275            index = getHIndex(next, value, index);
    288276        }
     277        ///ystem.err.println("Returning " + index);
    289278        return index;
    290279        }
    291280    }
     281    ///ystem.err.println("Returning " + index);
    292282    return index;
    293283    }
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java

    r5785 r5805  
    5959/** This class is instantiated using a metadata element. From this parent element, which refers to a specific Element in the mds DOM model, the AssignedValues child is used as the root of a tree data-structure encompassing all of the nodes within the AssignedValues tree. This class also provide methods for adding, updating and removing nodes within this tree, as well as implementing all of the methods necessary for this node to be used as the basis of a tree model.
    6060 */
    61 public class GValueNode 
     61public class GValueNode
    6262    extends DefaultMutableTreeNode {
    6363
     
    6565   static final public int GREENSTONE = 1;
    6666   static final public int TEXT = 2;
    67    
     67
    6868    private String element_name = null;
    6969    private String default_value = null;
     
    127127    Element element = (Element) userObject;
    128128    for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) {
    129         // And if we find such a node 
     129        // And if we find such a node
    130130        if(pos_node.getNodeName().equals("Alias")) {
    131131        // Retrieve its text node
     
    137137        }
    138138        }
    139     }         
     139    }
    140140    return "";
    141141    }
     
    187187    GValueNode node = (GValueNode) getParent();
    188188    while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) {
    189         path.insert(0, StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR);
     189        path.insert(0, StaticStrings.PIPE_STR);
    190190        path.insert(0, node.toString());
    191191        node = (GValueNode) node.getParent();
     
    274274    }
    275275
    276     /** Ensure that the children nodes of this tree are instantiated, and record the initial mappings for legacy sake. 
     276    /** Ensure that the children nodes of this tree are instantiated, and record the initial mappings for legacy sake.
    277277     * @param mapping A <strong>HashMap</strong> into which to write the initial mappings.
    278278     * @param prefix The prefix to use for indexes, as a <strong>String</strong>.
     
    306306    /** Resets the user object of the reciever to <I>object</I>. */
    307307    public void setUserObject(Object object) {
    308     // Can't ever change Elements from here. Have to use editor. */       
     308    // Can't ever change Elements from here. Have to use editor. */
    309309    }
    310310
     
    323323    /** Returns a <I>String</I> representation of the reciever. If this
    324324     * happens to be the AssignedValues 'root' then we do something slightly
    325      * different, otherwise we return the value of the <I>#Text</I> child of 
     325     * different, otherwise we return the value of the <I>#Text</I> child of
    326326     * the <I>Value</I> of this <I>Subject</I> node!
    327327     */
     
    329329    return toString(GValueNode.TEXT);
    330330    }
    331    
     331
    332332    public String toString(int decode_type) {
    333333    if(default_value != null) {
     
    376376    remove((MutableTreeNode)getChildAt(index));
    377377    }
    378      
     378
    379379    /** Removes node from the receiver. */
    380380    public void remove(MutableTreeNode node) {
     
    386386    parent_node.removeChild(child_element);
    387387    }
    388          
     388
    389389    /** Removes the receiver from its parent. */
    390390    public void removeFromParent() {
     
    399399    Element element = (Element) userObject;
    400400    for(Node pos_node = element.getFirstChild(); pos_node != null; pos_node = pos_node.getNextSibling()) {
    401         // And if we find such a node 
     401        // And if we find such a node
    402402        if(pos_node.getNodeName().equals(name)) {
    403403        // And the new value is non-null, retrieve its text node and change it.
Note: See TracChangeset for help on using the changeset viewer.