/* Copyright 2000 by Ralph Hartley This software is licenced under the terms of the Gnu Public Licence */ import java.io.*; import java.util.*; import org.w3c.dom.*; import org.apache.xerces.dom.DocumentImpl; import org.apache.xerces.dom.DocumentTypeImpl; import org.apache.xerces.dom.DOMImplementationImpl; import org.w3c.dom.Document; import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.Serializer; import org.apache.xml.serialize.SerializerFactory; import org.apache.xml.serialize.XMLSerializer; public class Cmap2Xml implements Serializable{ private static final long serialVersionUID = -48513234512356439L; TreeMap stations = new TreeMap(); TreeSet shots = new TreeSet(); Document doc; Element base; static String dtdurl = "http://www.psc.cavers/cavexml/cavexml.dtd"; static Version version = new Version(); static String unit = "feetdecimal"; static int style = 1; public Cmap2Xml() { doc = new DocumentImpl(); // Couldn't figure out how to pu in correct document type. Fix later. // DocumentType type = new DocumentTypeImpl(doc,"CaveXML",dtdurl,""); // doc.appendChild(type); Element root = doc.createElement("CaveSurvey"); doc.appendChild(root); Element prov = doc.createElement("ProvenanceImport"); prov.setAttribute("format","CMAP"); prov.setAttribute("converter","Cmap2Xml"); prov.setAttribute("version",version.getVersion()); prov.setAttribute("date",getDate()); root.appendChild(prov); Element def1 = doc.createElement("Default"); def1.setAttribute("element","Distance"); def1.setAttribute("unit",unit); prov.appendChild(def1); Element names = doc.createElement("NameSet"); names.setAttribute("ID","CMAPnames"); names.setAttribute("program","CMAP"); def1.appendChild(names); Element def2 = doc.createElement("Default"); def2.setAttribute("element","Station"); def2.setAttribute("nameset","CMAPnames"); def1.appendChild(def2); base = def2; } static String getDate() { Calendar cal = new GregorianCalendar(); String year = ""+cal.get(Calendar.YEAR); String month = ""+cal.get(Calendar.MONTH); String day = ""+cal.get(Calendar.DATE); if (month.length()==1) month = "0"+month; if (day.length()==1) day = "0"+day; return(year+"-"+month+"-"+day); } public void addFile(File file) throws IOException { readCmap(new FileInputStream(file)); } static boolean hasNonWhite(String str) { for (int i=0;i