source: trunk/gli/src/org/greenstone/gatherer/util/MetadataXML.java@ 6069

Last change on this file since 6069 was 6069, checked in by jmt12, 20 years ago

Have rearranged where and how strings are feed through the Codec. After several hours work and a dozen paper trials I discovered the TEXT_TO_DOM conversion was completely pointless (DOM does it itself). Also the quotes only need to be dealt to if they are being sent to the collect.cfg file. Hopefully I've got it all going now - including using that pesky pipe character that I would rather not have to deal with. And everything seems to be ok - I tested all the dangerous characters including square brackets and amperstamp. I also tried hierarchies, and then as the piece'd'resistance I tried a hierarchies with dangerous characters. All good. I'm all about the working metadata.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.util;
28
29import java.io.*;
30import java.util.*;
31import javax.swing.tree.*;
32import org.greenstone.gatherer.msm.ElementWrapper;
33import org.greenstone.gatherer.msm.MetadataSetManager;
34import org.greenstone.gatherer.util.StaticStrings;
35import org.greenstone.gatherer.util.Utility;
36import org.greenstone.gatherer.valuetree.GValueModel;
37import org.greenstone.gatherer.valuetree.GValueNode;
38
39public class MetadataXML
40{
41 static private void write(Writer w, String text)
42 throws Exception {
43 text = text + "\r\n";
44 char buffer[] = text.toCharArray();
45 w.write(buffer, 0, buffer.length);
46 }
47
48 static public void write(ElementWrapper element, GValueModel model, MetadataSetManager msm, String etc_dir) {
49 try {
50 File out_file = new File(etc_dir + element.getName() + ".txt");
51 FileOutputStream fos = new FileOutputStream(out_file);
52 OutputStreamWriter osw = new OutputStreamWriter(fos);
53 BufferedWriter bw = new BufferedWriter(osw, Utility.BUFFER_SIZE);
54 Vector all_values = model.traverseTree();
55 for(int i = 0; i < all_values.size(); i++) {
56 GValueNode node = (GValueNode)all_values.get(i);
57 TreePath path = new TreePath(node.getPath());
58 String full_value = node.getFullPath(false);
59 String index = model.getHIndex(full_value);
60
61 write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(node.toString(GValueNode.GREENSTONE)) + "\"");
62 }
63 // Very important we do this, or else buffer may not have
64 // flushed.
65 bw.flush();
66 bw.close();
67 }
68 catch(Exception error) {
69 error.printStackTrace();
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.