summaryrefslogtreecommitdiffstats
path: root/org/madore/damlengine/DamlEngine.java
blob: 696f50926c58f568f3acc0d0ef2868aaa24da20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.madore.damlengine;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.apache.xerces.dom.DOMImplementationSourceImpl;
import org.apache.xerces.jaxp.DocumentBuilderFactoryImpl;

public final class DamlEngine {

    private static Document doc;

    private DamlEngine() { }  // Forbid instantiation

    public static void processDocument() {
	// ...
    }

    public static void main(String[] args)
	throws Exception {

	final Resolver resolver = new Resolver();
	final DOMImplementationSourceImpl source
	    = new DOMImplementationSourceImpl();
	final DOMImplementation impl
	    = source.getDOMImplementation("XML 3.0 Core 3.0 LS 3.0");
        final DocumentBuilderFactory dbf = new DocumentBuilderFactoryImpl();
        dbf.setNamespaceAware(true);
        dbf.setValidating(false);
	final DocumentBuilder db = dbf.newDocumentBuilder();
	db.setEntityResolver((EntityResolver)resolver);
	final TransformerFactory tf = TransformerFactory.newInstance();
	final Transformer t = tf.newTransformer();
	t.setOutputProperty(OutputKeys.METHOD, "xml");
	t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
			    "-//W3C//DTD XHTML 1.0 Strict//EN");
	t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
			    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");

	if ( args.length == 0 ) {
	    System.err.println("expecting filename as argument");
	}

	for (String fname : args) {
	    doc = db.parse(fname);
	    processDocument();
	    t.transform(new DOMSource(doc), new StreamResult(System.out));
	}

    }

}