- Timestamp:
- 2003-05-27T15:40:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java
r4296 r4364 57 57 58 58 public class MetadataXML { 59 60 61 62 63 64 65 66 59 //private boolean can_wait = true; 60 private Gatherer gatherer = null; 61 private Hashtable known_indexes = null; 62 //private int spare_processes = 25; 63 //private MetadataXML mummy = null; 64 private SaveProgressDialog spd = null; 65 //private Vector complete = null; 66 //private Vector processes = null; 67 67 68 68 static public String METADATA_FILE = "metadata.xml"; 69 69 70 70 // not actually used anywhere 71 71 /* static public IXMLElement read(String filename) { 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 72 IXMLElement xml = null; 73 IXMLParser parser = null; 74 IXMLReader reader = null; 75 try { 76 parser = XMLParserFactory.createDefaultXMLParser(); 77 File in_file = new File(filename); 78 FileReader in_reader = new FileReader(in_file); 79 BufferedReader in = new BufferedReader(in_reader, Utility.BUFFER_SIZE); 80 String content = ""; 81 String next_line = null; 82 while((next_line = in.readLine()) != null) { 83 // Throw away the document type, as I don't want to deal 84 // with dtd's. If someone has tampered with these files to 85 // the point that this parser can't read them then too bad. 86 if(!next_line.startsWith("<!DOCTYPE")) { 87 content = content + next_line; 88 } 89 } 90 in.close(); 91 reader = StdXMLReader.stringReader(content); 92 parser.setReader(reader); 93 xml = (IXMLElement) parser.parse(); 94 } 95 catch (Exception e) { 96 } 97 return xml; 98 98 } 99 99 */ 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 100 public static void write(Gatherer gatherer, String etc_dir) { 101 if(gatherer != null && gatherer.c_man != null && gatherer.c_man.getCollection() != null && gatherer.c_man.getCollection().msm != null) { 102 Vector elements = gatherer.c_man.getCollection().msm.getElements(true); 103 for(int i = 0; i < elements.size(); i++) { 104 ElementWrapper element = (ElementWrapper)elements.get(i); 105 ///ystem.err.print("Checking " + element + " for HFile: "); 106 GValueModel model = gatherer.c_man.getCollection().msm.getValueTree(element); 107 if(model != null && (element.getNamespace().equals(MetadataSetManager.HIDDEN) || model.isHierarchy())) { 108 ///ystem.err.println("Found. Writing file."); 109 write(model, gatherer.c_man.getCollection().msm, etc_dir); 110 } 111 else { 112 ///ystem.err.println("No file found."); 113 } 114 } 115 } 116 } 117 117 118 119 120 121 122 118 private String getHIndex(Gatherer gatherer, GValueModel model, String value) { 119 String index = null; 120 index = (String) known_indexes.get(value); 121 if(index == null) { 122 index = model.getHIndex(value); 123 123 ///ystem.err.println("Adding to known indexes: " + value + " -> " + index); 124 125 126 127 124 known_indexes.put(value, index); 125 } 126 return index; 127 } 128 128 129 130 131 132 133 134 135 136 137 138 129 static private String safe(String unsafe) { 130 String safe_str = ""; 131 for(int i = 0; i < unsafe.length(); i++) { 132 char c = unsafe.charAt(i); 133 if(c != ' ') { 134 safe_str = safe_str + c; 135 } 136 } 137 return safe_str; 138 } 139 139 140 141 142 143 144 145 140 static private void write(Writer w, String text) 141 throws Exception { 142 text = text + "\r\n"; 143 char buffer[] = text.toCharArray(); 144 w.write(buffer, 0, buffer.length); 145 } 146 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 147 static public void write(GValueModel model, MetadataSetManager msm, String etc_dir) { 148 try { 149 File out_file = new File(etc_dir + model.toString() + ".txt"); 150 FileOutputStream fos = new FileOutputStream(out_file); 151 OutputStreamWriter osw = new OutputStreamWriter(fos); 152 BufferedWriter bw = new BufferedWriter(osw, Utility.BUFFER_SIZE); 153 Vector all_values = model.traverseTree(); 154 for(int i = 0; i < all_values.size(); i++) { 155 GValueNode node = (GValueNode)all_values.get(i); 156 TreePath path = new TreePath(node.getPath()); 157 String value = GValueTree.formatPath(null, path, true); 158 String index = model.getHIndex(value); 159 String alias = node.getAlias(index); 160 if(value.indexOf("\\") != -1) { 161 value = value.substring(value.lastIndexOf("\\") + 1); 162 } 163 write(bw, index + "\t\"" + alias + "\"\t\"" + Utility.stripNL(value) + "\""); 164 } 165 165 // Very important we do this, or else buffer may not have 166 166 // flushed. 167 168 169 170 171 172 173 167 bw.flush(); 168 bw.close(); 169 } 170 catch(Exception error) { 171 error.printStackTrace(); 172 } 173 } 174 174 175 176 175 static final private long showTime(String message, long time) { 176 if(time == -1) { 177 177 ///ystem.err.println(message + System.currentTimeMillis()); 178 179 178 } 179 else { 180 180 ///ystem.err.println(message + (System.currentTimeMillis() - time)); 181 182 183 181 } 182 return System.currentTimeMillis(); 183 } 184 184 } 185 186
Note:
See TracChangeset
for help on using the changeset viewer.