1 64 65 package com.jcorporate.expresso.kernel.management; 66 67 import com.jcorporate.expresso.kernel.exception.ExpressoRuntimeException; 68 import com.jcorporate.expresso.kernel.util.ClassLocator; 69 import org.w3c.dom.Document ; 70 71 import javax.xml.transform.Result ; 72 import javax.xml.transform.Source ; 73 import javax.xml.transform.Transformer ; 74 import javax.xml.transform.TransformerException ; 75 import javax.xml.transform.TransformerFactory ; 76 import javax.xml.transform.TransformerFactoryConfigurationError ; 77 import javax.xml.transform.dom.DOMSource ; 78 import javax.xml.transform.stream.StreamResult ; 79 import java.io.OutputStream ; 80 81 89 90 public class TraxDOMWriter implements DOMWriter { 91 92 public TraxDOMWriter() { 93 } 94 95 public void saveDocument(OutputStream os, Document document) throws ExpressoRuntimeException { 96 if (!isTraxInstalled()) { 97 throw new ExpressoRuntimeException( 98 "Must have javax.xml.transform.TransformerFactory in classpath. EX: Xalan"); 99 } 100 101 try { 102 TransformerFactory xformFactory = TransformerFactory.newInstance(); 103 Transformer idTransform = xformFactory.newTransformer(); 104 Source input = new DOMSource (document); 105 Result output = new StreamResult (os); 106 idTransform.transform(input, output); 107 } catch (TransformerException ex) { 108 throw new ExpressoRuntimeException("Unable to save config file", ex); 109 } catch (TransformerFactoryConfigurationError ex) { 110 throw new ExpressoRuntimeException("Unable to save config file", ex); 111 } 112 } 113 114 120 public String getRequiredClass() { 121 return "javax.xml.transform.TransformerFactory"; 122 } 123 124 125 131 protected boolean isTraxInstalled() { 132 try { 133 ClassLocator.loadClass(getRequiredClass()); 134 } catch (ClassNotFoundException ex) { 135 return false; 136 } 137 138 return true; 139 140 } 141 } | Popular Tags |