1 50 51 package org.openlaszlo.iv.flash.xml; 52 53 import org.openlaszlo.iv.flash.context.*; 54 55 import org.openlaszlo.iv.flash.util.*; 56 57 import javax.xml.parsers.*; 58 import java.lang.reflect.*; 59 import org.w3c.dom.Node ; 60 61 66 public abstract class XMLFactory { 67 68 private static XMLFactory instance; 69 70 76 public abstract DocumentBuilder getDocumentBuilder() throws ParserConfigurationException; 77 78 85 public abstract XMLContext newXMLContext( Context parent, Node node ); 86 87 92 public abstract XPathProcessor getXPathProcessor(); 93 94 99 public static XMLFactory getFactory() { 100 return instance; 101 } 102 103 static { 104 DocumentBuilderFactory docFactory = null; 105 106 String factoryName = PropertyManager.getProperty("javax.xml.parsers.DocumentBuilderFactory", null); 107 if( factoryName != null ) { 108 try { 109 Class clazz = Class.forName(factoryName); 110 docFactory = (DocumentBuilderFactory) clazz.newInstance(); 111 } catch( Exception e ) { 112 } 113 } 114 115 if( docFactory == null ) { 116 try { 117 docFactory = DocumentBuilderFactory.newInstance(); 118 } catch( RuntimeException e ) { 119 } 120 if (docFactory == null) { 121 try { 122 Class clazz = Class.forName("org.openlaszlo.iv.flash.xml.apache.DocumentBuilderFactoryImpl"); 123 docFactory = (DocumentBuilderFactory) clazz.newInstance(); 124 } catch( Exception e ) { 125 Log.logRB(e); 126 } 127 } 128 } 129 130 if (docFactory != null) { 131 132 String name = docFactory.getClass().getName(); 133 if( name.startsWith("org.apache.xerces") ) { 134 try { 136 Class clazz = Class.forName("org.openlaszlo.iv.flash.xml.apache.DocumentBuilderFactoryImpl"); 137 DocumentBuilderFactory docFactory2 = (DocumentBuilderFactory) clazz.newInstance(); 138 docFactory = docFactory2; 139 name = docFactory.getClass().getName(); 140 } catch( Exception e ) { 141 } 142 } 143 144 docFactory.setExpandEntityReferences(false); 145 docFactory.setIgnoringComments(true); 146 docFactory.setNamespaceAware(true); 147 docFactory.setValidating(false); 148 149 String xmlFactoryName = PropertyManager.getProperty("org.openlaszlo.iv.flash.XMLFactory", null); 151 if (xmlFactoryName != null) { 152 try { 153 instance = constructFactory(xmlFactoryName, docFactory); 154 } catch( Exception e ) { 155 Log.logRB(e); 156 } 157 } 158 else if( name.startsWith("org.openlaszlo.iv.flash.xml.apache.") ) { 160 try { 161 instance = constructFactory("org.openlaszlo.iv.flash.xml.apache.XMLFactoryImpl", docFactory); 162 } catch( Exception e ) { 163 Log.logRB(e); 164 } 165 } else if( name.startsWith("com.caucho.") ) { 166 try { 168 instance = constructFactory("org.openlaszlo.iv.flash.xml.caucho.XMLFactoryImpl", docFactory); 169 } catch( Exception e ) { 170 Log.logRB(e); 171 } 172 } else { 173 instance = new org.openlaszlo.iv.flash.xml.generic.XMLFactoryImpl(docFactory); 174 } 175 } 176 } 177 178 private static XMLFactory constructFactory(String factoryName, DocumentBuilderFactory docFactory) throws Exception { 179 Class factory = Class.forName(factoryName); 180 Constructor constr = factory.getConstructor(new Class [] {DocumentBuilderFactory.class}); 181 return (XMLFactory) constr.newInstance(new Object [] {docFactory}); 182 } 183 } 184 185 186 | Popular Tags |