Changeset 5153


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

Fix 203B143

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

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/parsers/GreenstoneMetadataParser.java

    r5070 r5153  
    4747import org.greenstone.gatherer.msm.MSMUtils;
    4848import org.greenstone.gatherer.util.DecodeHTMLReader;
     49import org.greenstone.gatherer.util.StaticStrings;
    4950import org.greenstone.gatherer.util.Utility;
    5051import org.greenstone.gatherer.valuetree.GValueModel;
     
    281282        if(metadatum != null) {
    282283            // 6c. Try to add metadata. If there is no matching metadata element:
    283             ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(metadatum.element);
     284            ElementWrapper element = Gatherer.c_man.getCollection().msm.getElement(metadatum.element, true);
    284285            // Arg. The element returned may come from the Greenstone dls, which of course should never be involved during importing. To solve check the namespace isn't "" and if it is nullify the element. Nullify. NULLIFY, Bwuhahahaha...
    285286            if(element != null && element.getNamespace().equals("")) {
     
    905906    /** Retrieve the value associated with a certain index. This is harder than it first sounds as you must take into account the parent indexes of this one.
    906907     * @param index The index whose value you wish to calculate, as a <strong>String</strong>.
    907      * @return The fully quantified path to the value that matches index, also as a <strong>String</strong>. Delimitiation between subject layers is denoted by the character '/'
     908     * @return The fully quantified path to the value that matches index, also as a <strong>String</strong>. Delimitiation between subject layers is denoted by the string "\\"
    908909     */
    909910    public String getValue(String index) {
     
    924925        ///ystem.err.println("\tHierarchy information required -->");
    925926        value.append(getValue(index.substring(0, dot_index)));
    926         value.append("\\");
     927        value.append(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR);
    927928        ///ystem.err.println("\t<-- Hierarchy information complete");
    928929        }
  • trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r5084 r5153  
    3333public class StaticStrings {
    3434    static final public char   NEW_LINE_CHARACTER                         = '\n';
     35    static final public char   STAR_CHAR                                  = '*';
    3536    static final public String ALLFIELDS_STR                              = "allfields";
    3637    static final public String ARCPLUG_STR                                = "ArcPlug";
     
    3839    static final public String AT_CHARACTER                               = "@";
    3940    static final public String CCS_STR                                    = "ccs";
     41    static final public String CLASSES_FOLDER                             = "classes";
    4042    static final public String CLASSIFY_ELEMENT                           = "Classify";
    4143    static final public String CLASSIFY_STR                               = "classify";
     
    6668    static final public String CUSTOM_ATTRIBUTE                           = "custom";
    6769    static final public String DEBUG_ARGUMENT                             = "-debug";
     70    static final public String DICTIONARY_FILENAME                        = "dictionary";
    6871    static final public String EMPTY_STR                                  = "";
    6972    static final public String ENGLISH_LANGUAGE_STR                       = "en";
    7073    static final public String ENUM_STR                                   = "enum";
     74    static final public String ESCAPE_PATTERN                             = "\\\\";
     75    static final public String ESCAPE_STR                                 = "\\";
    7176    static final public String EXCLAIMATION_CHARACTER                     = "!";
    7277    static final public String EXCLUDE_STR                                = "exclude";
     
    7782    static final public String FORMAT_STR                                 = "format";
    7883    static final public String GSDL_ARGUMENT                              = "-gsdl";
     84    static final public String HIERARCHY_ATTRIBUTE                        = "hierarchy";
    7985    static final public String HIERARCHY_STR                              = "hierarchy";
    8086    static final public String HTTP_PROTOCOL_STR                          = "http://";
    8187    static final public String HELP_ARGUMENT                              = "-help";
     88    static final public String IMPORT_FOLDER                              = "import";
    8289    static final public String INCLUDE_STR                                = "include";
    8390    static final public String INDEX_ELEMENT                              = "Index";
     
    96103    static final public String LANGUAGES_STR                              = "languages";
    97104    static final public String LBRACKET_CHARACTER                         = "[";
     105    static final public String LBRACKET_PATTERN                           = "\\[";
    98106    static final public String LEVEL_ATTRIBUTE                            = "level";
    99107    static final public String LEVELS_ELEMENT                             = "Levels";
     
    103111    static final public String LOAD_ARGUMENT                              = "-load";
    104112    static final public String METADATA_ARGUMENT                          = "-metadata";
     113    static final public String METADATA_SET_EXTENSION                     = ".mds";
    105114    static final public String METADATA_STR                               = "metadata";
    106115    static final public String METADATA_TYPE_STR                          = "metadatum"; // Because -someone- complained we have metadata (plural) and metadatum (singular) confused...
     
    109118    static final public String MGPP_ATTRIBUTE                             = "mgpp_enabled";
    110119    static final public String MINUS_CHARACTER                            = "-";
     120    static final public String MODEL_COLLECTION_NAME                      = "modelcol";
    111121    static final public String NAME_ATTRIBUTE                             = "name";
    112122    static final public String NEWLINE_CHARACTER                          = "\\";
     
    118128    static final public String PLUGIN_ELEMENT                             = "Plugin";
    119129    static final public String PLUGIN_STR                                 = "plugin";
     130    static final public String PROPERTIES_FILE_EXTENSION                  = ".properties";
    120131    static final public String PSEUDO_COLLECTCONFIGURATION_XML            = "xml/CollectionConfig.xml";
    121132    static final public String QUOTE_CHARACTER                            = "\"";
    122133    static final public String RBRACKET_CHARACTER                         = "]";
     134    static final public String RBRACKET_PATTERN                           = "\\]";
    123135    static final public String RECPLUG_STR                                = "RecPlug";
    124136    static final public String SEARCHTYPE_ELEMENT                         = "SearchType";
     
    127139    static final public String SEPARATOR_CHARACTER                        = "/";
    128140    static final public String SKIN_ARGUMENT                              = "-skinlf";
     141    static final public String SINGLE_ESCAPE_ONLY_PATTERN                 = "[^\\\\]+\\\\[^\\\\]+";
    129142    static final public String SPACE_CHARACTER                            = " ";
    130143    static final public String SPECIAL_ATTRIBUTE                          = "special";
     
    143156    static final public String TRUE_STR                                   = "true";
    144157    static final public String TYPE_ATTRIBUTE                             = "type";
     158    static final public String UNDERSCORE_CHARACTER                       = "_";
    145159    static final public String UNKNOWN_ELEMENT                            = "Unknown";
     160    static final public String USE_METADATA_FILES_ARGUMENT                = "use_metadata_files";
    146161    static final public String URL_SEPARATOR_CHARACTER                    = "/";
    147162    static final public String VALUE_ATTRIBUTE                            = "value";
     163    static final public String VALUE_TREE_ATTRIBUTE                       = "remember_values";
    148164}
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r4933 r5153  
    5353 */
    5454public class Utility {
     55    static final public Dimension BUTTON_SIZE = new Dimension(160, 35);
     56    static final public Dimension LABEL_SIZE = new Dimension(125, 35);
    5557    /** The default size of a gatherer progress bar, in either the download view or the build view. */
    5658    static final public Dimension PROGRESS_BAR_SIZE = new Dimension(580,65);
     
    102104    static final public String GREENSTONEDIRECTORYMETADATA_TEMPLATE = "xml/metadata.xml";
    103105    /** Definition of an important directory name, in this case the private web cache directory for the collection. */
    104     static final public String GCACHE_DIR = "gcache" + File.separator;
     106    static final public String GCACHE_DIR = "cache" + File.separator;
    105107    static final public String GLI_ARCHIVE = "GLI.jar";
    106108    /** Definition of an important directory name, in this case the location of help documentation. */
    107109    static final public String HELP_DIR = BASE_DIR + "help" + File.separator;
    108110    /** Definition of an important directory name, in this case the import directory for the collection. */
    109     static final public String IMPORT_DIR = "gimport" + File.separator;
     111    static final public String IMPORT_DIR = "import" + File.separator;
    110112    /** Definition of an important directory name, in this case the index directory for the collection. */
    111113    static final public String INDEX_DIR = "index" + File.separator;
     
    117119    /** Definition of an important directory name, in this case the location of the default metadata sets. */
    118120    static final public String METADATA_DIR = BASE_DIR + "metadata" + File.separator;
    119     static final public String METADATA_EXTRACTED = "extracted.mds";
    120121    /** The location the gatherer expects to find metadata set information. */
    121122    static final public String METADATA_SET_TEMPLATE = "xml/template.mds";
     
    123124    static final public String METADATA_XML = "metadata.xml";
    124125    static final public String NAME_ELEMENT = "Name";
    125     /** Definition of an important directory name, in this case the import directory for the collection. */
    126     static final public String OLD_IMPORT_DIR = "import" + File.separator;
    127126    /** The default name of the perl executable under unix. */
    128127    static final public String PERL_EXECUTABLE_UNIX = "perl";
     
    196195    return new TreePath(temp);
    197196    }
    198     /** Decodes a string of text so its safe to use in a Greenstone configuration file. Esentially replaces "\n" with a newline.
    199      * @param raw The <strong>String</strong> before decoding, read from the configuration file..
    200      * @return A <strong>String</strong> ready to be placed in a component.
    201      */
    202     static public String decodeGreenstone(String raw) {
    203     raw = raw.replaceAll("&apos;", "\'");
    204     raw = raw.replaceAll("&gt;", ">");
    205     raw = raw.replaceAll("&lt;", "<");
    206     raw = raw.replaceAll("&quot;", "\"");
    207     raw = raw.replaceAll("&#39;", "\'");
    208     raw = raw.replaceAll("\\\\n", "\n");
    209     return raw;
    210     }
    211197    /** Takes a rfc2616 'safe' String and translates it back into its 'unsafe' form. Basically the native c wget decode_string() function, but without pointer stuff. If searches through the String looking for the pattern %xy where x and y are hexidecimal digits and where xy maps to a character.<BR> If x or y are not hexidecimal or % is followed by a \0 then the pattern is left as is.
    212198     * @param encoded The url-safe <strong>String</strong> to be decoded.
     
    263249     * @return A <strong>String</strong> which is safe to write to the configuration file.
    264250     */
     251    static final private char AMPERSTAMP_CHAR = '&';
     252    static final private char ESCAPE_CHAR = '\\';
     253    static final private char GREATER_THAN_CHAR = '>';
     254    static final private char LESS_THAN_CHAR = '<';
     255    static final private char NEWLINE_CHAR = '\n';
     256    static final private char QUOTE_CHAR = '\'';
     257    static final private char SPEECH_CHAR = '\"';
     258    static final private String ENCODED_AMPERSTAMP_STR = "&amp;";
     259    static final private String ENCODED_GREATER_THAN_STR = "&gt;";
     260    static final private String ENCODED_LESS_THAN_STR = "&lt;";
     261    static final private String ENCODED_SPEECH_STR = "&quot;";
     262    static final private String ESCAPED_NEWLINE_STR = "\\n";
     263
     264    /** Decodes a string of text so its safe to use in a Greenstone configuration file. Esentially replaces "\n" with a newline.
     265     * @param raw The <strong>String</strong> before decoding, read from the configuration file..
     266     * @return A <strong>String</strong> ready to be placed in a component.
     267     */
     268    static public String decodeGreenstone(String raw) {
     269    raw = raw.replaceAll("&apos;", "\'");
     270    raw = raw.replaceAll("&gt;", ">");
     271    raw = raw.replaceAll("&lt;", "<");
     272    raw = raw.replaceAll("&quot;", "\"");
     273    raw = raw.replaceAll("&#39;", "\'");
     274    raw = raw.replaceAll("\\\\n", "\n");
     275    return raw;
     276    }
     277
    265278    static public String encodeGreenstone(String raw) {
    266     raw = raw.replaceAll("<", "&lt;");
    267     raw = raw.replaceAll(">", "&gt;");
    268     return raw.replaceAll("\n", "\\\\n");
     279    // Once again regex fails to provide the power necessary for me to change strings. What I need to do is replace "<" and ">" with "&lt;" and "&gt;", and replace "\<" and "\>" with "<" and ">".
     280    StringBuffer processed = new StringBuffer();
     281    int index = 0;
     282    while(index < raw.length()) {
     283        char c = raw.charAt(index);
     284        switch(c) {
     285        // Replace a normal new line character with "\n"
     286            case NEWLINE_CHAR:
     287            processed.append(ESCAPED_NEWLINE_STR);
     288            break;
     289        // Replace "\<" with "<", or with "\&lt;" if this is for XML. Similar requirements for "\>".
     290            case ESCAPE_CHAR:
     291            if(index + 1 < raw.length()) {
     292            char d = raw.charAt(index + 1);
     293            if(d == LESS_THAN_CHAR) {
     294                processed.append(LESS_THAN_CHAR);
     295                index++;
     296                break;
     297            }
     298            else if(d == GREATER_THAN_CHAR) {
     299                processed.append(GREATER_THAN_CHAR);
     300                index++;
     301                break;
     302            }
     303            }
     304            // I have no idea how this would happen, but I better watch for it anyway
     305            processed.append(c);
     306            break;
     307        // Replace "<" with "&lt;"
     308            case LESS_THAN_CHAR:
     309            processed.append(ENCODED_LESS_THAN_STR);
     310            break;
     311        // Replace ">" with "&gt;"
     312            case GREATER_THAN_CHAR:
     313            processed.append(ENCODED_GREATER_THAN_STR);
     314            break;
     315            default:
     316            processed.append(c);
     317        }
     318        index++;
     319    }
     320    return processed.toString();
     321    }
     322    /** When retrieve text for, or from the collect.cfg file it may contain characters that can't go into a DOM such as "<" and ">". We also might already have encoded versions "&lt;" and "&gt;". Thus we must encode the former, and double encode the latter. */
     323    static public String encodeXML(String raw) {
     324    StringBuffer processed = new StringBuffer();
     325    int index = 0;
     326    while(index < raw.length()) {
     327        char c = raw.charAt(index);
     328        switch(c) {
     329        case GREATER_THAN_CHAR:
     330        processed.append(ENCODED_GREATER_THAN_STR);
     331        break;
     332        case LESS_THAN_CHAR:
     333        processed.append(ENCODED_LESS_THAN_STR);
     334        break;
     335        case AMPERSTAMP_CHAR:
     336        processed.append(ENCODED_AMPERSTAMP_STR);
     337        break;
     338        default:
     339        processed.append(c);
     340        }
     341        index++;
     342    }
     343    return processed.toString();
    269344    }
    270345
  • 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        }
  • trunk/gli/src/org/greenstone/gatherer/valuetree/GValueNode.java

    r4407 r5153  
    3535 *########################################################################
    3636 */
    37 
    38  
    39 
    40 
    41 
    42 
    4337package org.greenstone.gatherer.valuetree;
    4438/**
     
    6155import org.greenstone.gatherer.msm.ElementWrapper;
    6256import org.greenstone.gatherer.msm.MSMUtils;
     57import org.greenstone.gatherer.util.StaticStrings;
    6358import org.greenstone.gatherer.util.Utility;
    6459import org.w3c.dom.Document;
     
    188183    GValueNode node = (GValueNode) getParent();
    189184    while(node != null && !node.getElement().getNodeName().equalsIgnoreCase("AssignedValues")) {
    190         path.insert(0, "\\");
    191         path.insert(0, node.toString());
     185        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);
    192190        node = (GValueNode) node.getParent();
    193191    }
Note: See TracChangeset for help on using the changeset viewer.