/* * Created on 29.10.2004 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package net.sf.tomp.xml.include.test; import java.io.File; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.sf.tomp.xml.type.Transformations; import net.sf.tomp.xml.type.TransformationsFromType; import net.sf.tomp.xml.type.Type; import net.sf.tomp.xml.type.TypeDatabaseImpl; import net.sf.tomp.xml.type.TypeTransformation; import net.sf.tomp.xml.type.Variant; import net.sf.tomp.xtcl.Context; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; /** * @author tomp * * TODO To change the template for this generated type comment go to Window - * Preferences - Java - Code Style - Code Templates */ public class Main { private static final String TYPE_DB_FILENAME = "c:/devel/xtclbrowser/type-database.xml"; /** * Starts as a standalone file server and waits for Enter. */ public static void main(String[] args) throws Exception { Main t = new Main(); t.init(); t.testGetTransformations(); t.testGetTransformationsFrom(); t.testGetTransformationsFromTo(); } private Context context; private TypeDatabaseImpl typeDatabase; private Type[] types = new Type[30]; /** * @return Returns the context. */ public Context getContext() { return context; } /** * @return Returns the typeDatabase. */ public TypeDatabaseImpl getTypeDatabase() { return typeDatabase; } public String getTypeDatabaseFileName() { return TYPE_DB_FILENAME; } protected XMLReader getXMLReader() throws SAXException { XMLReader parser = null; try { parser = XMLReaderFactory.createXMLReader(); } catch (SAXException e) { parser = XMLReaderFactory.createXMLReader( //"org.apache.xerces.parsers.SAXParser" "org.apache.crimson.parser.XMLReaderImpl"); } return parser; } protected void init() throws Exception { // init the Context context = new Context(); context.setRealPath(new File(".")); // inti the TypeDatabase typeDatabase = new TypeDatabaseImpl(); typeDatabase.setXTFilterFactory(context.getXTFilterFactory()); // load Type Database XMLReader reader = getXMLReader(); reader.setContentHandler(typeDatabase); reader.parse(getTypeDatabaseFileName()); } /** * @param context * The context to set. */ public void setContext(Context context) { this.context = context; } /** * @param typeDatabase * The typeDatabase to set. */ public void setTypeDatabase(TypeDatabaseImpl typeDatabase) { this.typeDatabase = typeDatabase; } public void testGetTransformations() throws Exception { System.out.println("=== testGetTransformations() ==="); Transformations ts = typeDatabase.getTransformations(); List tl = new ArrayList(); for (Iterator i = ts.typesIterator(); i.hasNext();) { Type type = (Type) i.next(); tl.add(type); System.out.println(type); } types = (Type[]) tl.toArray(new Type[0]); System.out.println(); } public void testGetTransformationsFrom() throws Exception { System.out.println("=== testGetTransformationsFrom " + types[0] + " ==="); Transformations ts = typeDatabase.getTransformations(); // test transf. Type 'from' Type to = typeDatabase .getType("doctype-public:-//OASIS//DTD DocBook XML V4.1.2//EN"); TransformationsFromType tft = ts.getTransformationsFrom(types[0]); Type typ = tft.getTyp(); System.out.println(typ); System.out.println(to); TypeTransformation tto = tft .getTransformationTo(to, Variant.NO_VARIANT); System.out.println(tto); System.out.println(); } public void testGetTransformationsFromTo() throws Exception { System.out.println("=== testGetTransformationsFromTo ==="); int i1 = 0; for (Iterator fromI = typeDatabase.getTypesIterator(); fromI.hasNext();) { int i2 = 0; Type from = (Type) fromI.next(); for (Iterator toI = typeDatabase.getTypesIterator(); toI.hasNext();) { Type to = (Type) toI.next(); System.out.println("" + i1 + " -> " + i2); System.out.println(from + " -> " + to); TypeTransformation tto = typeDatabase.getTransformation(from, to, Variant.NO_VARIANT); System.out.println(tto); System.out.println(); i2++; } i1++; } } }