Changeset 8123
- Timestamp:
- 2004-09-16T13:42:46+12:00 (20 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/metadata
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/metadata/DocXMLFile.java
r8122 r8123 33 33 } 34 34 35 MetadataSet extracted_metadata_set = MetadataSetManager.getMetadataSet(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE); 36 35 37 // Read all the Archive elements in the file 36 38 NodeList archive_elements_nodelist = document.getElementsByTagName(ARCHIVE_ELEMENT); … … 57 59 String metadata_element_name_full = current_metadata_element.getAttribute("name"); 58 60 61 // If the metadata has a namespace it isn't extracted metadata, so we're not interested 62 String metadata_set_namespace = MetadataTools.getMetadataSetNamespace(metadata_element_name_full); 63 if (!metadata_set_namespace.equals("")) { 64 continue; 65 } 66 67 // Extracted metadata! 68 String metadata_element_name = metadata_element_name_full; 69 59 70 // Note which file this Section is for 60 if (metadata_element_name _full.equals("gsdlsourcefilename")) {71 if (metadata_element_name.equals("gsdlsourcefilename")) { 61 72 gsdlsourcefilename_value = XMLTools.getElementTextValue(current_metadata_element); 62 73 … … 85 96 } 86 97 87 // We don't d ealwith bibliographic data88 if (metadata_element_name _full.equals("SourceSegment")) {98 // We don't do much with bibliographic data 99 if (metadata_element_name.equals("SourceSegment")) { 89 100 bibliographic_data = true; 90 break; 101 } 102 103 // Ignore lower-case metadata elements (gsdlsourcefilename, gsdlassocfile etc.) 104 // and those starting with '/' (/srclink) 105 char first_character = metadata_element_name.charAt(0); 106 if (Character.isLowerCase(first_character) || first_character == '/') { 107 continue; 108 } 109 110 MetadataElement metadata_element = extracted_metadata_set.getMetadataElement(metadata_element_name); 111 if (metadata_element == null) { 112 // This element isn't defined in ex.mds, so create it for this session 113 System.err.println("Extracted metadata element not defined: " + metadata_element_name); 114 extracted_metadata_set.addMetadataElementForThisSession(metadata_element_name); 91 115 } 92 116 } … … 175 199 176 200 MetadataElement metadata_element = extracted_metadata_set.getMetadataElement(metadata_element_name); 177 if (metadata_element == null) {178 // This element isn't defined in ex.mds, so create it for this session179 System.err.println("Extracted metadata element not defined: " + metadata_element_name);180 metadata_element = extracted_metadata_set.addMetadataElementForThisSession(metadata_element_name);181 }182 201 183 202 // Value trees are not stored for extracted metadata, so create a new value tree node now -
trunk/gli/src/org/greenstone/gatherer/metadata/MetadataElement.java
r8122 r8123 2 2 3 3 4 import java.io.File; 4 5 import org.greenstone.gatherer.util.XMLTools; 5 6 import org.w3c.dom.*; … … 112 113 return metadata_element_name_full; 113 114 } 115 116 117 public void writeHierarchyFile(File hierarchy_file) 118 { 119 metadata_value_tree_model.writeHierarchyFile(hierarchy_file); 120 } 114 121 } -
trunk/gli/src/org/greenstone/gatherer/metadata/MetadataSetManager.java
r8120 r8123 116 116 metadata_sets.add(metadata_set); 117 117 } 118 119 120 static public void unloadMetadataSet(MetadataSet metadata_set) 121 { 122 // Find the metadata set in the list of loaded sets, and remove it 123 for (int i = 0; i < metadata_sets.size(); i++) { 124 if (metadata_set == (MetadataSet) metadata_sets.get(i)) { 125 metadata_sets.remove(i); 126 break; 127 } 128 } 129 } 130 131 132 static public void writeHierarchyFiles(File directory) 133 { 134 // Make sure the directory (etc) exists 135 if (directory.exists() == false) { 136 return; 137 } 138 139 // Write a hierarchy file for each loaded metadata element, except extracted metadata 140 ArrayList every_metadata_set_element = getEveryMetadataSetElement(); 141 for (int i = 0; i < every_metadata_set_element.size(); i++) { 142 MetadataElement metadata_element = (MetadataElement) every_metadata_set_element.get(i); 143 if (metadata_element.isExtractedMetadata() == false) { 144 File hierarchy_file = new File(directory, metadata_element.getFullName() + ".txt"); 145 metadata_element.writeHierarchyFile(hierarchy_file); 146 } 147 } 148 } 118 149 } -
trunk/gli/src/org/greenstone/gatherer/metadata/MetadataValueTreeModel.java
r7978 r8123 2 2 3 3 4 import java.io.*; 4 5 import java.util.*; 5 6 import javax.swing.tree.*; … … 108 109 return metadata_value_tree_node; 109 110 } 111 112 113 public void writeHierarchyFile(File hierarchy_file) 114 { 115 try { 116 // Write the value tree out to a hierarchy file, for the Hierarchy classifier 117 FileOutputStream file_output_stream = new FileOutputStream(hierarchy_file); 118 OutputStreamWriter output_stream_writer = new OutputStreamWriter(file_output_stream, "UTF-8"); 119 BufferedWriter buffered_writer = new BufferedWriter(output_stream_writer); 120 121 writeHierarchyFileInternal((MetadataValueTreeNode) root, "", buffered_writer); 122 123 buffered_writer.flush(); 124 buffered_writer.close(); 125 } 126 catch (Exception ex) { 127 ex.printStackTrace(); 128 } 129 } 130 131 132 private void writeHierarchyFileInternal(MetadataValueTreeNode parent_metadata_value_tree_node, String index, BufferedWriter buffered_writer) 133 throws Exception 134 { 135 // Perform a depth-first traversal of the value tree, writing the metadata values out to the hfile 136 for (int i = 0; i < parent_metadata_value_tree_node.getChildCount(); i++) { 137 MetadataValueTreeNode child_metadata_value_tree_node = (MetadataValueTreeNode) parent_metadata_value_tree_node.getChildAt(i); 138 String metadata_value_full = child_metadata_value_tree_node.getFullValue(); 139 String index_string = (index.equals("") ? "" + (i + 1) : index + "." + (i + 1)); 140 String metadata_value = child_metadata_value_tree_node.getValue(); 141 String hierarchy_string = "\"" + metadata_value_full + "\"\t" + index_string + "\t\"" + metadata_value + "\"\n"; 142 buffered_writer.write(hierarchy_string, 0, hierarchy_string.length()); 143 144 // Apply recursively 145 writeHierarchyFileInternal(child_metadata_value_tree_node, index_string, buffered_writer); 146 } 147 } 110 148 } -
trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFileManager.java
r8120 r8123 242 242 } 243 243 } 244 245 246 static public void unloadMetadataXMLFile(File metadata_xml_file_file) 247 { 248 System.err.println("Unloading metadata.xml file " + metadata_xml_file_file); 249 250 // Find the metadata.xml file in the list of loaded files, and remove it 251 for (int i = 0; i < metadata_xml_files.size(); i++) { 252 MetadataXMLFile metadata_xml_file = (MetadataXMLFile) metadata_xml_files.get(i); 253 if (metadata_xml_file_file.getAbsolutePath().equals(metadata_xml_file.getAbsolutePath())) { 254 metadata_xml_files.remove(i); 255 break; 256 } 257 } 258 } 244 259 }
Note:
See TracChangeset
for help on using the changeset viewer.