Changeset 5294


Ignore:
Timestamp:
2003-08-27T15:03:07+12:00 (21 years ago)
Author:
jmt12
Message:

Fixing escaped path problem

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

Legend:

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

    r5244 r5294  
    4141    static final public String DOM_TO_TEXT = "DOM_TO_TEXT";
    4242    static final public String GREENSTONE_TO_DOM = "GREENSTONE_TO_DOM";
     43    static final public String GREENSTONE_TO_TEXT = "GREENSTONE_TO_TEXT";
    4344    static final public String TEXT_TO_DOM = "TEXT_TO_DOM";
     45    static final public String TEXT_TO_GREENSTONE = "TEXT_TO_GREENSTONE";
    4446    static final public String TEXT_TO_SHELL_UNIX = "TEXT_TO_SHELL_UNIX";
    4547    static final public String TEXT_TO_SHELL_WINDOWS = "TEXT_TO_SHELL_WINDOWS";
     
    8688    greenstone_to_dom = null;
    8789
     90    // Transform Greenstone encoded text to plain text
     91    String[] greenstone_to_text = {
     92        "\\\\\"", "\"",
     93        "\\\\\'", "\'",
     94        "\\\\n", "\n",
     95        """, "\"",
     96        "'", "\'",
     97        "\\\\\\[", "\\[",
     98        "\\\\\\]", "\\]",
     99        "\\\\\\\\", "\\\\"
     100    };
     101    TRANSFORMS.put(GREENSTONE_TO_TEXT, greenstone_to_text);
     102    greenstone_to_text = null;
     103
    88104    // Transform plain html text into something that can be placed in a DOM
    89105    String[] text_to_dom = {
     
    92108        ">", ">",
    93109        "\"", """,
    94         "\'", "'"};
     110        "\'", "'"
     111    };
    95112    TRANSFORMS.put(TEXT_TO_DOM, text_to_dom);
    96113    text_to_dom = null;
    97114
    98 // Transform plain html text into something that can be placed in a shell command
     115    // Transform plain html text into greenstone encoding
     116    String[] text_to_greenstone = {
     117        "\\\\", "\\\\\\\\",
     118        "\\[", "\\\\[",
     119        "\\]", "\\\\]",
     120        "\"", """,
     121        "\'", "'",
     122        "\n", "\\\\n"
     123    };
     124    TRANSFORMS.put(TEXT_TO_GREENSTONE, text_to_greenstone);
     125    text_to_greenstone = null;
     126
     127    // Transform plain html text into something that can be placed in a shell command
    99128    String[] text_to_shell_unix = {
    100129        "\"", "\\\\\"",
     
    225254        System.err.println("Processed: '" + processed + "'");
    226255
     256        transform = "GREENSTONE_TO_TEXT";
     257        System.err.println("Test " + transform);
     258        raw = "These \\[ \\] should be escaped, and so should \\\\ that. These " ' \\n are encoded.";
     259        System.err.println("Raw:       '" + raw + "'");
     260        processed = transform(raw, transform);
     261        System.err.println("Processed: '" + processed + "'");
     262
    227263        transform = "TEXT_TO_DOM";
    228264        System.err.println("Test " + transform);
    229265        raw = "A &lt;\nand a <a href=\"here.html\"><font size='2'>URL</font></a>";
     266        System.err.println("Raw:       '" + raw + "'");
     267        processed = transform(raw, transform);
     268        System.err.println("Processed: '" + processed + "'");
     269
     270        transform = "TEXT_TO_GREENSTONE";
     271        System.err.println("Test " + transform);
     272        raw = "These [ ] should be escaped, and so should \\ that. These \" \' \n are encoded.";
    230273        System.err.println("Raw:       '" + raw + "'");
    231274        processed = transform(raw, transform);
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueModel.java

    r5153 r5294  
    77 * University of Waikato, New Zealand.
    88 *
    9  * <BR><BR>
    10  *
    119 * Author: John Thompson, Greenstone Digital Library, University of Waikato
    1210 *
    13  * <BR><BR>
    14  *
    1511 * Copyright (C) 1999 New Zealand Digital Library Project
    16  *
    17  * <BR><BR>
    1812 *
    1913 * This program is free software; you can redistribute it and/or modify
     
    2216 * (at your option) any later version.
    2317 *
    24  * <BR><BR>
    25  *
    2618 * This program is distributed in the hope that it will be useful,
    2719 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2820 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2921 * GNU General Public License for more details.
    30  *
    31  * <BR><BR>
    3222 *
    3323 * You should have received a copy of the GNU General Public License
     
    4232import org.greenstone.gatherer.msm.MetadataSetManager;
    4333import org.greenstone.gatherer.msm.MSMUtils;
     34import org.greenstone.gatherer.util.Codec;
     35import org.greenstone.gatherer.util.PatternTokenizer;
    4436import org.greenstone.gatherer.util.StaticStrings;
    4537import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
     
    5345    extends DefaultTreeModel {
    5446
     47    static final public String PATH_SEP = "\\\\";
     48    static final public String PATH_SEP_PATTERN = "\\\\\\\\";
     49
    5550    private ElementWrapper element;
    5651
     
    8479    public GValueNode addValue(String value) {
    8580    try {
    86         // Remove any single escape characters
    87         value = stripEscapes(value);
    88         // Now we can tokenize the string using the double escaped characters
    89         StringTokenizer tokenizer = new StringTokenizer(value, StaticStrings.ESCAPE_STR);
     81        // Tokenize the string using the escaped character
     82        PatternTokenizer tokenizer = new PatternTokenizer(value, PATH_SEP);
    9083        GValueNode subject = (GValueNode) root;
    9184        while(tokenizer.hasMoreTokens() && subject != null) {
     
    10194    }
    10295
    103     /** Replace all current double escapes with single escapes, and remove all currently single escapes. */
    104     static final private char ESCAPE_CHARACTER = '\\';
    105     private String stripEscapes(String raw) {
    106     StringBuffer processed_buffer = new StringBuffer();
    107     int raw_length = raw.length();
    108     for(int i = 0; i < raw_length; i++) {
    109         char c = raw.charAt(i);
    110         switch(c) {
    111         case ESCAPE_CHARACTER:
    112         if(i < raw_length - 1 && raw.charAt(i+1) == ESCAPE_CHARACTER) {
    113             i = i + 1;
    114             processed_buffer.append(c);
    115         }
    116         break;
    117         default:
    118         processed_buffer.append(c);
    119         }
    120     }
    121     return processed_buffer.toString();
    122     }
    123 
    12496    public GValueNode addValue(String value, GValueNode subject, String alias) {
    12597    // To add a value we must first ensure it isn't already present in -this- nodes children. The bummer is that the nice getElements functions search the whole tree so...
    126     GValueNode value_node = subject.getValue(Utility.stripNL(value));
     98    GValueNode value_node = subject.getValue(value);
    12799    if(value_node == null) {
    128100        // Now add the new value.
     
    275247    }
    276248
    277     /**
    278     public void updateValue(String new_value, String old_value) {
    279     ///ystem.err.println("Updating '" + old_value + "' to '" + new_value + "'");
    280     StringTokenizer tokenizer = new StringTokenizer(new_value, "\\");
    281     GValueNode subject = (GValueNode) root;
    282     while(tokenizer.hasMoreTokens()) {
    283         String token = tokenizer.nextToken();
    284         subject = updateValue(token, old_value, subject);
    285     }
    286     }
    287     */
    288 
    289249    /** Called to update a certain value of metadata within a specific
    290250     * subject within a sbject hierarchy.
     
    326286        }
    327287        value = value.substring(next.toString().length());
    328         if(value.startsWith(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR)) {
     288        if(value.startsWith(PATH_SEP)) {
    329289            value = value.substring(2);
    330290            index = getHIndex(next, value, index);
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java

    r5153 r5294  
    5555import org.greenstone.gatherer.msm.ElementWrapper;
    5656import org.greenstone.gatherer.msm.MSMUtils;
     57import org.greenstone.gatherer.util.Codec;
    5758import org.greenstone.gatherer.util.StaticStrings;
    5859import org.greenstone.gatherer.util.Utility;
     
    176177     * @return A <strong>String</strong> representing the path, ie "Titles\Modern\The Green Mile"
    177178     */
    178     public String getFullPath() {
     179    public String getFullPath(boolean as_text) {
    179180    if(default_value != null) {
    180181        return default_value;
     
    184185    while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) {
    185186        path.insert(0, StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR);
    186         String temp = node.toString();
    187         temp = temp.replaceAll(StaticStrings.LBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.LBRACKET_PATTERN);
    188         temp = temp.replaceAll(StaticStrings.RBRACKET_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.RBRACKET_PATTERN);
    189         path.insert(0, temp);
     187        path.insert(0, node.toString());
    190188        node = (GValueNode) node.getParent();
    191189    }
    192     return path.toString();
     190    if(as_text) {
     191        return Codec.transform(path.toString(), Codec.GREENSTONE_TO_TEXT);
     192    }
     193    else {
     194        return path.toString();
     195    }
    193196    }
    194197
     
    226229        map();
    227230    }
    228     GValueNode result = null;
    229     for(int i = 0; result == null && i < children.size(); i++) {
    230         Object child = children.get(i);
    231         if(child.toString().equalsIgnoreCase(value)) {
    232         result = (GValueNode) child;
    233         }
    234     }
    235     return result;
     231    for(int i = 0; i < children.size(); i++) {
     232        GValueNode child = (GValueNode) children.get(i);
     233        if(child.toString(false).equalsIgnoreCase(value)) {
     234        return child;
     235        }
     236    }
     237    return null;
    236238    }
    237239
     
    320322     */
    321323    public String toString() {
     324    return toString(true);
     325    }
     326   
     327    public String toString(boolean as_text) {
    322328    if(default_value != null) {
    323329        return default_value;
     
    327333    String result = null;
    328334    if(name.equals("Subject")) {
    329         result = MSMUtils.getValue(element);
     335        if(as_text) {
     336        result = Codec.transform(MSMUtils.getValue(element), Codec.GREENSTONE_TO_TEXT);
     337        }
     338        else {
     339        result = MSMUtils.getValue(element);
     340        }
    330341    }
    331342    else if(name.equals("AssignedValues")) {
    332343        result = getMetadataElementName();
    333344    }
    334     return Utility.stripNL(result);
     345    return result;
    335346    }
    336347
Note: See TracChangeset for help on using the changeset viewer.