Ignore:
Timestamp:
2003-10-03T14:07:35+12:00 (21 years ago)
Author:
mdewsnip
Message:

Many more small improvements and tooltips added. Still more to come!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java

    r5523 r5564  
    1 package org.greenstone.gatherer.util;
    21/**
    32 *#########################################################################
     
    2625 *########################################################################
    2726 */
    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;
     27package org.greenstone.gatherer.util;
     28
     29import java.io.*;
     30import java.util.*;
     31import javax.swing.tree.*;
    4232import org.greenstone.gatherer.Gatherer;
    43 import org.greenstone.gatherer.gui.SaveProgressDialog;
    4433import org.greenstone.gatherer.msm.ElementWrapper;
    45 import org.greenstone.gatherer.msm.Metadata;
    4634import org.greenstone.gatherer.msm.MetadataSetManager;
    4735import org.greenstone.gatherer.util.Utility;
    4836import org.greenstone.gatherer.valuetree.GValueModel;
    4937import org.greenstone.gatherer.valuetree.GValueNode;
    50 import org.w3c.dom.Element;
    5138
    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 
     39public class MetadataXML
     40{
    10641    static private void write(Writer w, String text)
    10742    throws Exception {
     
    12964        write(bw, "\"" + Utility.stripNL(value) + "\"\t" + index + "\t\"" + Utility.stripNL(value) + "\"");
    13065        }
    131                 // Very important we do this, or else buffer may not have
    132                 // flushed.
     66        // Very important we do this, or else buffer may not have
     67        // flushed.
    13368        bw.flush();
    13469        bw.close();
     
    13873    }
    13974    }
    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.JTree
    147      * @see javax.swing.tree.TreePath
    148      */
    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     }
    17775}
Note: See TracChangeset for help on using the changeset viewer.