Ignore:
Timestamp:
2003-08-18T13:55:21+12:00 (21 years ago)
Author:
jmt12
Message:

Fix 203B143

File:
1 edited

Legend:

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

    r4686 r5153  
    4242import org.greenstone.gatherer.msm.MetadataSetManager;
    4343import org.greenstone.gatherer.msm.MSMUtils;
     44import org.greenstone.gatherer.util.StaticStrings;
    4445import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
    4546import org.greenstone.gatherer.util.Utility;
     
    8081    }
    8182
    82     /** Value may include path ie news/newssw */
     83    /** Value may include path ie news\newssw */
    8384    public GValueNode addValue(String value) {
    84     StringTokenizer tokenizer = new StringTokenizer(value, "\\");
    85     GValueNode subject = (GValueNode) root;
    86     while(tokenizer.hasMoreTokens() && subject != null) {
    87         String token = tokenizer.nextToken();
    88         subject = addValue(token, subject, null);
    89         ///ystem.err.println("Found or created a node " + token);
    90     }
    91     return subject;
     85    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);
     90        GValueNode subject = (GValueNode) root;
     91        while(tokenizer.hasMoreTokens() && subject != null) {
     92        String token = tokenizer.nextToken();
     93        subject = addValue(token, subject, null);
     94        }
     95        return subject;
     96    }
     97    catch (Exception error) {
     98        error.printStackTrace();
     99    }
     100    return null;
     101    }
     102
     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();
    92122    }
    93123
     
    245275    }
    246276
     277    /**
    247278    public void updateValue(String new_value, String old_value) {
    248279    ///ystem.err.println("Updating '" + old_value + "' to '" + new_value + "'");
     
    254285    }
    255286    }
     287    */
    256288
    257289    /** Called to update a certain value of metadata within a specific
     
    294326        }
    295327        value = value.substring(next.toString().length());
    296         if(value.startsWith("\\")) {
    297             value = value.substring(1);
     328        if(value.startsWith(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR)) {
     329            value = value.substring(2);
    298330            index = getHIndex(next, value, index);
    299331        }
Note: See TracChangeset for help on using the changeset viewer.