- Timestamp:
- 2003-10-03T14:07:35+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java
r5523 r5564 1 package org.greenstone.gatherer.util;2 1 /** 3 2 *######################################################################### … … 26 25 *######################################################################## 27 26 */ 28 import java.awt.Point; 29 import java.io.BufferedReader; 30 import java.io.BufferedWriter; 31 import java.io.File; 32 import java.io.FileInputStream; 33 import java.io.FileOutputStream; 34 import java.io.FileReader; 35 import java.io.OutputStreamWriter; 36 import java.io.Writer; 37 import java.util.ArrayList; 38 import java.util.Collections; 39 import java.util.Hashtable; 40 import java.util.Vector; 41 import javax.swing.tree.TreePath; 27 package org.greenstone.gatherer.util; 28 29 import java.io.*; 30 import java.util.*; 31 import javax.swing.tree.*; 42 32 import org.greenstone.gatherer.Gatherer; 43 import org.greenstone.gatherer.gui.SaveProgressDialog;44 33 import org.greenstone.gatherer.msm.ElementWrapper; 45 import org.greenstone.gatherer.msm.Metadata;46 34 import org.greenstone.gatherer.msm.MetadataSetManager; 47 35 import org.greenstone.gatherer.util.Utility; 48 36 import org.greenstone.gatherer.valuetree.GValueModel; 49 37 import org.greenstone.gatherer.valuetree.GValueNode; 50 import org.w3c.dom.Element;51 38 52 public class MetadataXML { 53 //private boolean can_wait = true; 54 private Gatherer gatherer = null; 55 private Hashtable known_indexes = null; 56 //private int spare_processes = 25; 57 //private MetadataXML mummy = null; 58 private SaveProgressDialog spd = null; 59 //private Vector complete = null; 60 //private Vector processes = null; 61 62 static public String METADATA_FILE = "metadata.xml"; 63 64 /** 65 public static void write(Gatherer gatherer, String etc_dir) { 66 if(gatherer != null && gatherer.c_man != null && gatherer.c_man.getCollection() != null && gatherer.c_man.getCollection().msm != null) { 67 Vector elements = gatherer.c_man.getCollection().msm.getElements(true); 68 for(int i = 0; i < elements.size(); i++) { 69 ElementWrapper element = (ElementWrapper)elements.get(i); 70 ///ystem.err.print("Checking " + element + " for HFile: "); 71 GValueModel model = gatherer.c_man.getCollection().msm.getValueTree(element); 72 if(model != null && (element.getNamespace().equals(MetadataSetManager.HIDDEN) || model.isHierarchy())) { 73 ///ystem.err.println("Found. Writing file."); 74 write(model, gatherer.c_man.getCollection().msm, etc_dir); 75 } 76 else { 77 ///ystem.err.println("No file found."); 78 } 79 } 80 } 81 } 82 */ 83 84 private String getHIndex(Gatherer gatherer, GValueModel model, String value) { 85 String index = null; 86 index = (String) known_indexes.get(value); 87 if(index == null) { 88 index = model.getHIndex(value); 89 ///ystem.err.println("Adding to known indexes: " + value + " -> " + index); 90 known_indexes.put(value, index); 91 } 92 return index; 93 } 94 95 static private String safe(String unsafe) { 96 String safe_str = ""; 97 for(int i = 0; i < unsafe.length(); i++) { 98 char c = unsafe.charAt(i); 99 if(c != ' ') { 100 safe_str = safe_str + c; 101 } 102 } 103 return safe_str; 104 } 105 39 public class MetadataXML 40 { 106 41 static private void write(Writer w, String text) 107 42 throws Exception { … … 129 64 write(bw, "\"" + Utility.stripNL(value) + "\"\t" + index + "\t\"" + Utility.stripNL(value) + "\""); 130 65 } 131 132 66 // Very important we do this, or else buffer may not have 67 // flushed. 133 68 bw.flush(); 134 69 bw.close(); … … 138 73 } 139 74 } 140 141 /** Returns the given tree path as path formatted string (ie subject\subject\subject).142 * @param tree The <strong>JTree</strong> the TreePath came from. Used to determine if the root node should be encoded as well.143 * @param path A <strong>TreePath</strong> that you wish to encode to String.144 * @param full <i>true</i> if this is the full path (ie a leaf node), <i>false</i> otherwise.145 * @return A <strong>String</strong> encoding the information from the TreePath.146 * @see javax.swing.JTree147 * @see javax.swing.tree.TreePath148 */149 // static public String formatPath(JTree tree, TreePath path, boolean full) {150 // String text = "";151 // int i = 0;152 // if(tree == null || (!tree.isRootVisible() && !full)) {153 // i = 1;154 // }155 // for( ; i < path.getPathCount(); i++) {156 // GValueNode node = (GValueNode)path.getPathComponent(i);157 // text = text + node.toString();158 // if(node.getChildCount() > 0) {159 // text = text + "\\";160 // }161 // }162 // if(full && text.endsWith("\\")) {163 // return text.substring(0, text.length() - 1);164 // }165 // return text;166 // }167 168 static final private long showTime(String message, long time) {169 if(time == -1) {170 ///ystem.err.println(message + System.currentTimeMillis());171 }172 else {173 ///ystem.err.println(message + (System.currentTimeMillis() - time));174 }175 return System.currentTimeMillis();176 }177 75 }
Note:
See TracChangeset
for help on using the changeset viewer.