Changeset 5832


Ignore:
Timestamp:
2003-11-13T13:55:46+13:00 (20 years ago)
Author:
kjdon
Message:

now have changed the format parsing so that it allows format over mulitple lines too

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java

    r5819 r5832  
    758758        String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE);
    759759        // If this is element is in english, and it is the first one found, we don't need to write the language argument.
    760         // we should always write the language string
    761760        //if(!language_str.equals(ENGLISH_LANGUAGE_STR) || known_metadata == null || known_metadata.contains(name_str)) {
     761        // changed so that we always write the language string
    762762        text.append(LBRACKET_CHARACTER);
    763763        text.append(LANGUAGE_ARGUMENT);
     
    765765        text.append(RBRACKET_CHARACTER);
    766766        text.append(SPACE_CHARACTER);
    767             //}
     767        //}
    768768        if(known_metadata != null) {
    769769            known_metadata.add(name_str);
     
    840840            }
    841841            if(command_element == null && command_type.equals(FORMAT_STR)) {
    842             command_element = parseFormat(command_str);
     842            command_element = parseFormat(command_str, in);
    843843            }
    844844            if(command_element == null && (command_type.equals(INDEX_STR)  || command_type.equals(COMMENTED_INDEXES_STR))) {
     
    958958    }
    959959
    960     private Element parseFormat(String command_str) {
     960    private Element parseFormat(String command_str, BufferedReader in) {
    961961    Element command_element = null;
    962962    try {
     
    967967        tokenizer.nextToken();
    968968        command_element.setAttribute(NAME_ATTRIBUTE, tokenizer.nextToken());
    969         String format_value = tokenizer.nextToken();
     969        String value_str = tokenizer.nextToken();
    970970        // If the value is true or false we add it as an attribute
    971         if(format_value.equalsIgnoreCase(TRUE_STR) || format_value.equalsIgnoreCase(FALSE_STR)) {
    972             command_element.setAttribute(VALUE_ATTRIBUTE, format_value.toLowerCase());
     971        if(value_str.equalsIgnoreCase(TRUE_STR) || value_str.equalsIgnoreCase(FALSE_STR)) {
     972            command_element.setAttribute(VALUE_ATTRIBUTE, value_str.toLowerCase());
    973973        }
    974974        // Otherwise it gets added as a text node
    975975        else {
    976             // Strip any speech marks
    977             if(format_value.startsWith(SPEECH_CHARACTER) && format_value.endsWith(SPEECH_CHARACTER)) {
    978             format_value = format_value.substring(1, format_value.length() - 1);
    979             }
    980             // Decode from Greenstone back into text
    981             format_value = Codec.transform(format_value, Codec.GREENSTONE_TO_DOM);
    982             // And add to DOM
    983             MSMUtils.setValue(command_element, format_value);
    984         }
    985         format_value = null;
     976
     977            // now we need to handle the case where the value is enclosed in quotes (single or double) and may extend across multiple lines
     978            String start_string = value_str.substring(0,1);
     979            if (start_string.equals("\"") || start_string.equals("\'")) {
     980            if (value_str.endsWith(start_string) && value_str.length()!=1) {
     981                // we remove the quotes from the ends
     982                value_str = value_str.substring(1, value_str.length() - 1);
     983            } else {
     984               
     985                // remove the first quote
     986                StringBuffer value_raw = new StringBuffer(value_str.substring(1));
     987                // add the new line back in
     988                value_raw.append(StaticStrings.NEW_LINE_CHAR);
     989                int pos = value_raw.indexOf(start_string);
     990                int old_pos = 0;
     991                while (pos != -1 && value_raw.charAt(pos-1)=='\\') {
     992                old_pos = pos+1;
     993                pos = value_raw.indexOf(start_string, old_pos);
     994                }
     995                while(pos == -1) {
     996                String next_line = in.readLine();
     997                if(next_line != null) {
     998                    value_raw.append(next_line);
     999                    value_raw.append(StaticStrings.NEW_LINE_CHAR);
     1000                }
     1001                next_line = null;
     1002                pos = value_raw.indexOf(start_string, old_pos);
     1003                while (pos != -1 && value_raw.charAt(pos-1)=='\\') {
     1004                    old_pos = pos+1;
     1005                    pos = value_raw.indexOf(start_string, old_pos);
     1006                }
     1007                }
     1008               
     1009                value_str = value_raw.substring(0, value_raw.lastIndexOf(start_string));
     1010                value_raw = null;
     1011               
     1012            } // else
     1013            } // if starts with a quote
     1014                   
     1015            if(value_str != null) {
     1016            // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value
     1017            value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM);
     1018            MSMUtils.setValue(command_element, value_str);
     1019            }
     1020            else {
     1021            command_element = null;
     1022            }
     1023            start_string = null;
     1024        }
     1025        value_str = null;
     1026       
    9861027        }
    9871028        tokenizer = null;
    9881029    }
    989     catch(Exception exception) {
     1030    catch (Exception exception) {
    9901031    }
    9911032    return command_element;
     
    11651206            } else {
    11661207           
    1167             Gatherer.println("cdm.CollectionConfiguration.parseMEtadata: we have found a starting quote but not an ending quote, so now read lines until we get to an end quote");
     1208            // remove the first quote
    11681209            StringBuffer value_raw = new StringBuffer(value_str.substring(1));
     1210            // add the new line back in
     1211            value_raw.append(StaticStrings.NEW_LINE_CHAR);
     1212
    11691213            int pos = value_raw.indexOf(start_string);
    11701214            int old_pos = 0;
Note: See TracChangeset for help on using the changeset viewer.