- Timestamp:
- 2003-08-22T10:06:59+12:00 (21 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/cdm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionConfiguration.java
r5230 r5254 35 35 import org.greenstone.gatherer.msm.MSMUtils; 36 36 import org.greenstone.gatherer.util.DOMTree; 37 import org.greenstone.gatherer.util.Codec; 37 38 import org.greenstone.gatherer.util.StaticStrings; 38 39 import org.greenstone.gatherer.util.Utility; 39 40 import org.w3c.dom.*; 40 /** This class provides either access to a pseudo-G3 document, or parses a collect.cfg file in such a way as to provide an xml-type view of its content. This later version is useful as it allows the manipulation and free form editing of a legacy collect.cfg file while still allowing the various CDM data managers to base themselves directly on this model (whereas they used to be independant ListModels which clobbered the ordering of unparsed commands). 41 /** This class provides either access to a pseudo-G3 document, or parses a collect.cfg file in such a way as to provide an xml-type view of its content. This later version is useful as it allows the manipulation and free form editing of a legacy collect.cfg file while still allowing the various CDM data managers to base themselves directly on this model (whereas they used to be independant ListModels which clobbered the ordering of unparsed commands). 41 42 * @author John Thompson, Greenstone Digital Library, University of Waikato 42 43 * @version 2.3d 43 44 */ 44 public class CollectionConfiguration 45 public class CollectionConfiguration 45 46 extends StaticStrings { 46 47 … … 60 61 } 61 62 62 /** Find the best insertion position for the given DOM Element. This should try to match command tag, and if found should then try to group by name or type (eg CollectionMeta), or append to end is no such grouping exists (eg PlugIns). Failing a command match it will check against the command order for the best insertion location. 63 /** Find the best insertion position for the given DOM Element. This should try to match command tag, and if found should then try to group by name or type (eg CollectionMeta), or append to end is no such grouping exists (eg PlugIns). Failing a command match it will check against the command order for the best insertion location. 63 64 * @param element the command Element to be inserted 64 65 * @return the Element which the given command should be inserted before, or null to append to end of list … … 130 131 else { 131 132 Element last_element = (Element) matching_elements.item(matching_elements.getLength() - 1); 132 return last_element.getNextSibling(); 133 } 134 } 135 133 return last_element.getNextSibling(); 134 } 135 } 136 136 137 } 137 138 else { … … 222 223 } 223 224 else if(command_element_name.equals(COLLECTIONMETADATA_ELEMENT)) { 224 return self.metadataToString(command_element );225 return self.metadataToString(command_element, show_extracted_namespace); 225 226 } 226 227 else if(command_element_name.equals(COLLECTIONMETADATA_CREATOR_ELEMENT)) { 227 return self.metadataToString(command_element );228 return self.metadataToString(command_element, show_extracted_namespace); 228 229 } 229 230 else if(command_element_name.equals(COLLECTIONMETADATA_MAINTAINER_ELEMENT)) { 230 return self.metadataToString(command_element );231 return self.metadataToString(command_element, show_extracted_namespace); 231 232 } 232 233 else if(command_element_name.equals(COLLECTIONMETADATA_PUBLIC_ELEMENT)) { 233 return self.metadataToString(command_element );234 return self.metadataToString(command_element, show_extracted_namespace); 234 235 } 235 236 else if(command_element_name.equals(COLLECTIONMETADATA_BETA_ELEMENT)) { 236 return self.metadataToString(command_element );237 return self.metadataToString(command_element, show_extracted_namespace); 237 238 } 238 239 else if(command_element_name.equals(PLUGIN_ELEMENT)) { … … 291 292 arguments.put(name, null); 292 293 name = null; 293 } 294 } 294 295 } 295 296 return arguments; 296 297 } 297 298 298 static private ArrayList known_metadata; 299 static private ArrayList known_metadata; 299 300 300 301 static private CollectionConfiguration self; … … 598 599 document_element = null; 599 600 return element; 600 } 601 } 601 602 602 603 private String indexesToString(Element command_element, boolean show_extracted_namespace) { … … 693 694 if(j < language_elements_length - 1) { 694 695 text.append(SPACE_CHARACTER); 695 } 696 } 696 697 } 697 698 return text.toString(); … … 727 728 } 728 729 729 static public String metadataToString(Element command_element ) {730 static public String metadataToString(Element command_element, boolean text_value) { 730 731 // If there is no value attribute, then we don't write anything 731 732 String value_str = MSMUtils.getValue(command_element); … … 766 767 } 767 768 name_str = null; 769 770 // The value string we retrieved will be encoded for xml, so we now decode it - to text if text_value set. This parameter was originally show_extracted_namespace, but sincethis is only true for 'toString()' commands from within the CDM, its good enough to determine if this toString() will be used to display on screen, or write to collect.cfg 771 if(text_value == CollectionMeta.TEXT) { 772 value_str = Codec.transform(value_str, Codec.DOM_TO_TEXT); 773 } 774 else { 775 value_str = Codec.transform(value_str, Codec.DOM_TO_GREENSTONE); 776 } 777 768 778 // We don't wrap the email addresses in quotes, nor any string without spaces 769 779 if(value_str.indexOf(SPACE_CHARACTER) == -1) { … … 906 916 String name = (String) names.next(); 907 917 String value = (String) arguments.get(name); // Can be null 918 // The metadata argument gets added as the content attribute 919 if(name.equals(METADATA_ARGUMENT) && value != null) { 920 // The metadata argument must be the fully qualified name of a metadata element, so if it doesn't yet have a namespace, append the extracted metadata namespace. 921 if(value.indexOf(MSMUtils.NS_SEP) == -1) { 922 value = Utility.EXTRACTED_METADATA_NAMESPACE + MSMUtils.NS_SEP + value; 923 } 924 //command_element.setAttribute(CONTENT_ATTRIBUTE, value); 925 } 908 926 // Everything else is an Option Element 909 927 Element option_element = document.createElement(OPTION_ELEMENT); … … 913 931 if(value.startsWith(SPEECH_CHARACTER) && value.endsWith(SPEECH_CHARACTER)) { 914 932 value = value.substring(1, value.length() - 1); 915 }916 // The metadata argument gets added as the content attribute917 if(name.equals(METADATA_ARGUMENT) && value != null) {918 // The metadata argument must be the fully qualified name of a metadata element, so if it doesn't yet have a namespace, append the extracted metadata namespace.919 if(value.indexOf(MSMUtils.NS_SEP) == -1) {920 value = Utility.EXTRACTED_METADATA_NAMESPACE + MSMUtils.NS_SEP + value;921 }922 //command_element.setAttribute(CONTENT_ATTRIBUTE, value);923 933 } 924 934 MSMUtils.setValue(option_element, value); … … 1139 1149 } 1140 1150 if(value_str != null) { 1151 // Ready the value str (which can contain all sorts of funky characters) for writing as a DOM value 1152 value_str = Codec.transform(value_str, Codec.GREENSTONE_TO_DOM); 1141 1153 command_element.setAttribute(NAME_ATTRIBUTE, name_str); 1142 1154 command_element.setAttribute(LANGUAGE_ATTRIBUTE, language_str); 1143 MSMUtils.setValue(command_element, Utility.encodeXML(value_str));1155 MSMUtils.setValue(command_element, value_str); 1144 1156 } 1145 1157 else { … … 1176 1188 command_element = document.createElement(COLLECTIONMETADATA_PUBLIC_ELEMENT); 1177 1189 } 1178 if(command_element != null && value_str != null) {1190 if(command_element != null) { 1179 1191 command_element.setAttribute(NAME_ATTRIBUTE, name_str); 1180 1192 command_element.setAttribute(LANGUAGE_ATTRIBUTE, ENGLISH_LANGUAGE_STR); … … 1275 1287 search_element = null; 1276 1288 } 1277 } 1289 } 1278 1290 } 1279 1291 catch(Exception exception) { … … 1350 1362 catch(Exception exception) { 1351 1363 } 1352 return command_element; 1364 return command_element; 1353 1365 } 1354 1366 … … 1402 1414 catch(Exception exception) { 1403 1415 } 1404 return command_element; 1416 return command_element; 1405 1417 } 1406 1418 … … 1564 1576 * @param str the String to be written 1565 1577 */ 1566 private void write(BufferedWriter writer, String str) 1578 private void write(BufferedWriter writer, String str) 1567 1579 throws IOException { 1568 1580 writer.write(str, 0, str.length()); -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionMeta.java
r4932 r5254 37 37 import org.greenstone.gatherer.cdm.Index; 38 38 import org.greenstone.gatherer.msm.MSMUtils; 39 import org.greenstone.gatherer.util.Codec; 39 40 import org.greenstone.gatherer.util.StaticStrings; 40 41 import org.greenstone.gatherer.util.Utility; … … 46 47 public class CollectionMeta 47 48 implements DOMProxyListEntry { 49 50 static final public boolean TEXT = true; 51 static final public boolean GREENSTONE = false; 52 48 53 private Element element; 49 54 private String text; … … 113 118 * @return The value of value as a <strong>String</strong>. 114 119 */ 115 public String getValue() { 116 // We have to replace the string made of '\' 'n' with the '\n' character! Also watch for other greenstone magic 117 return Utility.decodeGreenstone(MSMUtils.getValue(element)); 120 public String getValue(boolean text_value) { 121 String raw_value = MSMUtils.getValue(element); 122 // Decode the raw value depending on whether the user asked for the TEXT or GREENSTONE version 123 if(text_value == TEXT) { 124 return Codec.transform(raw_value, Codec.DOM_TO_TEXT); 125 } 126 else { 127 return Codec.transform(raw_value, Codec.DOM_TO_GREENSTONE); 128 } 118 129 } 119 130 … … 143 154 * @param value the new value as a String. 144 155 */ 145 public void setValue(String value) { 146 MSMUtils.setValue(element, Utility.encodeGreenstone(value)); 156 public void setValue(String raw_value) { 157 // Only raw html text can be given to setValue so we need to encode it 158 MSMUtils.setValue(element, Codec.transform(raw_value, Codec.TEXT_TO_DOM)); 147 159 text = null; // Reset text 148 160 }
Note:
See TracChangeset
for help on using the changeset viewer.