1 17 package org.apache.excalibur.xml.dom; 18 19 import javax.xml.parsers.DocumentBuilder ; 20 import javax.xml.parsers.DocumentBuilderFactory ; 21 import javax.xml.transform.sax.SAXTransformerFactory ; 22 import javax.xml.transform.sax.TransformerHandler ; 23 24 import org.apache.avalon.framework.activity.Initializable; 25 import org.apache.avalon.framework.component.Component; 26 import org.apache.avalon.framework.logger.AbstractLogEnabled; 27 import org.apache.avalon.framework.thread.ThreadSafe; 28 import org.w3c.dom.Document ; 29 30 35 public class DefaultDOMHandlerFactory 36 extends AbstractLogEnabled 37 implements DOMHandlerFactory, Initializable, Component, ThreadSafe 38 { 39 private final SAXTransformerFactory m_transformerFactory = (SAXTransformerFactory )SAXTransformerFactory.newInstance(); 40 private final DocumentBuilderFactory m_documentBuilderFactory = DocumentBuilderFactory.newInstance(); 41 private DocumentBuilder m_documentBuilder; 42 43 public void initialize() 44 throws Exception 45 { 46 m_documentBuilderFactory.setNamespaceAware( true ); 47 m_documentBuilder = m_documentBuilderFactory.newDocumentBuilder(); 48 } 49 50 public DOMHandler createDOMHandler() 51 throws Exception 52 { 53 final Document document = m_documentBuilder.newDocument(); 54 return createDOMHandler( document ); 55 } 56 57 public DOMHandler createDOMHandler( final Document document ) 58 throws Exception 59 { 60 final TransformerHandler transformerHandler = 61 m_transformerFactory.newTransformerHandler(); 62 return new DefaultDOMHandler( transformerHandler, document ); 63 } 64 } 65 | Popular Tags |