Changeset 6888


Ignore:
Timestamp:
2004-02-25T11:40:11+13:00 (20 years ago)
Author:
mdewsnip
Message:

Moved some code from the old util/MetadataXML.java in here, since it is the only place it is used.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/MetadataSetManager.java

    r6879 r6888  
    4141import javax.swing.*;
    4242import javax.swing.filechooser.*;
     43import javax.swing.tree.TreePath;
    4344import org.greenstone.gatherer.Configuration;
    4445import org.greenstone.gatherer.Dictionary;
     
    5758import org.greenstone.gatherer.valuetree.GValueModel;
    5859import org.greenstone.gatherer.valuetree.GValueNode;
    59 import org.greenstone.gatherer.util.MetadataXML;
    6060import org.greenstone.gatherer.util.Utility;
    6161import org.apache.xerces.parsers.*;
     
    995995                // If this is a hierarchy element, write hierarchy file.
    996996                if(value_element.getNamespace().equals(MetadataSetManager.HIDDEN) || value_tree.isHierarchy()) {
    997                 MetadataXML.write(value_element, value_tree, this, Gatherer.c_man.getCollectionEtc());
     997                write(value_element, value_tree, Gatherer.c_man.getCollectionEtc());
    998998                }
    999999            }
     
    13321332    return action;
    13331333    }
     1334
     1335
     1336    private void write(ElementWrapper element, GValueModel model, String etc_dir) {
     1337    try {
     1338        File out_file = new File(etc_dir + element.getName() + ".txt");
     1339        FileOutputStream fos = new FileOutputStream(out_file);
     1340        OutputStreamWriter osw = new OutputStreamWriter(fos);
     1341        BufferedWriter bw = new BufferedWriter(osw, Utility.BUFFER_SIZE);
     1342        Vector all_values = model.traverseTree();
     1343        for(int i = 0; i < all_values.size(); i++) {
     1344        GValueNode node = (GValueNode)all_values.get(i);
     1345        TreePath path = new TreePath(node.getPath());
     1346        String full_value = node.getFullPath(false);
     1347        String index = model.getHIndex(full_value);
     1348
     1349        write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(node.toString(GValueNode.GREENSTONE)) + "\"");
     1350        }
     1351        // Very important we do this, or else buffer may not be flushed
     1352        bw.flush();
     1353        bw.close();
     1354    }
     1355    catch(Exception error) {
     1356        error.printStackTrace();
     1357    }
     1358    }
     1359
     1360
     1361    private void write(Writer w, String text)
     1362    throws Exception {
     1363    text = text + "\r\n";
     1364    char buffer[] = text.toCharArray();
     1365    w.write(buffer, 0, buffer.length);
     1366    }
    13341367}
Note: See TracChangeset for help on using the changeset viewer.