/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: John Thompson, Greenstone Digital Library, University of Waikato * * Copyright (C) 1999 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.util; import java.io.*; import java.util.*; import javax.swing.tree.*; import org.greenstone.gatherer.msm.ElementWrapper; import org.greenstone.gatherer.msm.MetadataSetManager; import org.greenstone.gatherer.util.StaticStrings; import org.greenstone.gatherer.util.Utility; import org.greenstone.gatherer.valuetree.GValueModel; import org.greenstone.gatherer.valuetree.GValueNode; public class MetadataXML { static private void write(Writer w, String text) throws Exception { text = text + "\r\n"; char buffer[] = text.toCharArray(); w.write(buffer, 0, buffer.length); } static public void write(ElementWrapper element, GValueModel model, MetadataSetManager msm, String etc_dir) { try { File out_file = new File(etc_dir + element.getName() + ".txt"); FileOutputStream fos = new FileOutputStream(out_file); OutputStreamWriter osw = new OutputStreamWriter(fos); BufferedWriter bw = new BufferedWriter(osw, Utility.BUFFER_SIZE); Vector all_values = model.traverseTree(); for(int i = 0; i < all_values.size(); i++) { GValueNode node = (GValueNode)all_values.get(i); TreePath path = new TreePath(node.getPath()); String full_value = node.getFullPath(true); String index = model.getHIndex(full_value); write(bw, "\"" + Utility.stripNL(full_value) + "\"\t" + index + "\t\"" + Utility.stripNL(full_value) + "\""); } // Very important we do this, or else buffer may not have // flushed. bw.flush(); bw.close(); } catch(Exception error) { error.printStackTrace(); } } }