/*
XML.java
*
* You may use and distribute under the terms of either the GNU Lesser
* General Public License, either version 2 of the license or,
* at your choice, any later version. Alternatively, you may use and
* distribute under the terms of the XPL.
*
* See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of
* the licenses.
*
* This software 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 README
* file for more details.
*
*/
/*
* Written by Tuukka Hastrup
* Very heavily modified by Tuomas Lukka
*/
/** An XML importer/exporter.
*
* Export:
* - with data view cursor, point to a cell containing the filename
*
- running the action XML.EXPORT will now export the whole space
*
*
* Import:
* - with data view cursor, point to a cell containing the filename
*
- if there's a cell from that cell poswards on d.1, this cell
* will be used as a root for the imported space, otherwise a new
* cell is created there
*
- running the action XML.IMPORT will now import the whole space.
* XXX Notice that if there was a connection from home cell
* negwards on d.1 to be imported, it's not there because that's where
* the filename cell is!
*/
package org.gzigzag.module;
import org.gzigzag.*;
import java.io.*;
import java.net.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
//import org.openxml.x3p.*;
import org.apache.xml.serialize.*;
import java.util.*;
import java.awt.Point;
public class XML {
public static final String rcsid = "$Id: XML.java,v 1.1 2002/10/07 12:37:35 tuukkah Exp $";
public static boolean dbg = true;
static final void p(String s) { if(dbg) System.out.println(s); }
static final void pa(String s) { System.out.println(s); }
static public XMLReader getXMLReader() {
return new org.apache.xerces.parsers.SAXParser();
}
static public Document getDocument() {
return new org.apache.xerces.dom.DOMImplementationImpl().
createDocument(null, "ZZSpace", null);
}
static public XMLSerializer getXMLSerializer(Writer writ) {
return getXMLSerializer(writ, "UTF-8");
}
static public XMLSerializer getXMLSerializer(Writer writ, String enc) {
return new org.apache.xml.serialize.XMLSerializer(writ,
new org.apache.xml.serialize.OutputFormat("doc",
enc, true));
}
ZZSpace zz;
static public ZZModule module = new ZZModule() {
public void action(String id, ZZCell code,
ZZCell target,
ZZView v, ZZView cv,
String key, Point pt,
ZZScene xi) {
if(id.equals("EXPORT")) {
synchronized(code.getSpace()) {
(new XML()).export(new File(target.getText()), code.getSpace());
}
} else if(id.equals("IMPORT")) {
(new XML()).load(new File(target.getText()), target.getOrNewCell("d.1", 1));
}
}
};
AttributesImpl ats(String[] a) {
AttributesImpl ai = new AttributesImpl();
for(int i=0; i