Changeset 5832
- Timestamp:
- 2003-11-13T13:55:46+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
r5819 r5832 758 758 String language_str = command_element.getAttribute(LANGUAGE_ATTRIBUTE); 759 759 // 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 string761 760 //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 762 762 text.append(LBRACKET_CHARACTER); 763 763 text.append(LANGUAGE_ARGUMENT); … … 765 765 text.append(RBRACKET_CHARACTER); 766 766 text.append(SPACE_CHARACTER); 767 767 //} 768 768 if(known_metadata != null) { 769 769 known_metadata.add(name_str); … … 840 840 } 841 841 if(command_element == null && command_type.equals(FORMAT_STR)) { 842 command_element = parseFormat(command_str );842 command_element = parseFormat(command_str, in); 843 843 } 844 844 if(command_element == null && (command_type.equals(INDEX_STR) || command_type.equals(COMMENTED_INDEXES_STR))) { … … 958 958 } 959 959 960 private Element parseFormat(String command_str ) {960 private Element parseFormat(String command_str, BufferedReader in) { 961 961 Element command_element = null; 962 962 try { … … 967 967 tokenizer.nextToken(); 968 968 command_element.setAttribute(NAME_ATTRIBUTE, tokenizer.nextToken()); 969 String format_value= tokenizer.nextToken();969 String value_str = tokenizer.nextToken(); 970 970 // 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()); 973 973 } 974 974 // Otherwise it gets added as a text node 975 975 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 986 1027 } 987 1028 tokenizer = null; 988 1029 } 989 catch (Exception exception) {1030 catch (Exception exception) { 990 1031 } 991 1032 return command_element; … … 1165 1206 } else { 1166 1207 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 1168 1209 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 1169 1213 int pos = value_raw.indexOf(start_string); 1170 1214 int old_pos = 0;
Note:
See TracChangeset
for help on using the changeset viewer.