1 9 10 package org.dom4j.samples; 11 12 import org.dom4j.Document; 13 import org.dom4j.DocumentFactory; 14 import org.dom4j.io.SAXReader; 15 16 24 public class VisitorDemo2 extends VisitorDemo { 25 26 27 protected String documentFactoryClassName; 28 29 public static void main(String [] args) { 30 run(new VisitorDemo2(), args); 31 } 32 33 public VisitorDemo2() { 34 } 35 36 public void run(String [] args) throws Exception { 37 if (args.length < 1) { 38 printUsage("<XML document URL> [<Document Factory Class Name>]"); 39 return; 40 } 41 42 String xmlFile = args[0]; 43 44 documentFactoryClassName = (args.length > 1) ? args[1] : null; 45 46 Document document = parse(xmlFile); 47 process(document); 48 } 49 50 protected SAXReader createSAXReader() throws Exception { 51 println("Using SAX parser: " 52 + System.getProperty("org.xml.sax.driver", "default")); 53 54 SAXReader answer = new SAXReader(); 55 if (documentFactoryClassName != null) { 56 try { 57 Class theClass = Class.forName(documentFactoryClassName); 58 DocumentFactory factory = (DocumentFactory) theClass 59 .newInstance(); 60 if (factory != null) { 61 println("DocumentFactory: " + factory); 62 answer.setDocumentFactory(factory); 63 } 64 } catch (Exception e) { 65 println("ERROR: Failed to create an instance of DocumentFactory: " 66 + documentFactoryClassName); 67 println("Exception: " + e); 68 e.printStackTrace(); 69 } 70 } 71 return answer; 72 } 73 } 74 75 113 | Popular Tags |