Ignore:
Timestamp:
2003-05-27T15:40:47+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

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

    r4296 r4364  
    5757
    5858public class MetadataXML {
    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;
     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;
    6767
    68     static public String METADATA_FILE = "metadata.xml";
     68    static public String METADATA_FILE = "metadata.xml";
    6969
    7070    // not actually used anywhere
    7171    /*   static public IXMLElement read(String filename) {
    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;
     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;
    9898     }
    9999    */
    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     }
     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    }
    117117
    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);
     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);
    123123                ///ystem.err.println("Adding to known indexes: " + value + " -> " + index);
    124                 known_indexes.put(value, index);
    125           }
    126           return index;
    127     }
     124        known_indexes.put(value, index);
     125    }
     126    return index;
     127    }
    128128
    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     }
     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    }
    139139
    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     }
     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    }
    146146
    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                 }
     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        }
    165165                // Very important we do this, or else buffer may not have
    166166                // flushed.
    167                 bw.flush();
    168                 bw.close();
    169           }
    170           catch(Exception error) {
    171                 error.printStackTrace();
    172           }
    173     }
     167        bw.flush();
     168        bw.close();
     169    }
     170    catch(Exception error) {
     171        error.printStackTrace();
     172    }
     173    }
    174174
    175     static final private long showTime(String message, long time) {
    176           if(time == -1) {
     175    static final private long showTime(String message, long time) {
     176    if(time == -1) {
    177177                ///ystem.err.println(message + System.currentTimeMillis());
    178           }
    179           else {
     178    }
     179    else {
    180180                ///ystem.err.println(message + (System.currentTimeMillis() - time));
    181           }
    182           return System.currentTimeMillis();
    183     }
     181    }
     182    return System.currentTimeMillis();
     183    }
    184184}
    185 
    186 
Note: See TracChangeset for help on using the changeset viewer.