1 package com.jcorporate.expresso.kernel.management; 2 3 import com.jcorporate.expresso.kernel.exception.ExpressoRuntimeException; 4 import com.jcorporate.expresso.kernel.util.ClassLocator; 5 import org.apache.log4j.Logger; 6 import org.apache.xml.serialize.OutputFormat; 7 import org.apache.xml.serialize.XMLSerializer; 8 import org.w3c.dom.Document ; 9 10 import java.io.IOException ; 11 import java.io.OutputStream ; 12 13 14 22 23 public class XercesDOMWriter implements DOMWriter { 24 static Logger log = Logger.getLogger(XercesDOMWriter.class); 25 26 public XercesDOMWriter() { 27 super(); 28 } 29 30 35 protected boolean isXercesInstalled() { 36 37 try { 38 ClassLocator.loadClass(getRequiredClass()); 39 } catch (ClassNotFoundException ex) { 40 return false; 41 } 42 43 return true; 44 } 45 46 52 public String getRequiredClass() { 53 return "org.apache.xerces.parsers.SAXParser"; 54 } 55 56 57 public void saveDocument(OutputStream os, Document document) throws ExpressoRuntimeException { 58 try { 59 OutputFormat format = new OutputFormat(document); 61 format.setLineWidth(65); 62 format.setIndenting(true); 63 format.setIndent(4); 64 format.setEncoding("ISO-8859-1"); 65 format.setMediaType("application/xml"); 66 format.setOmitComments(true); 67 format.setOmitXMLDeclaration(false); 68 format.setVersion("1.0"); 69 format.setDoctype("-//Jcorporate Ltd//DTD Expresso Services Configuration 5.1//EN", 70 "http://www.jcorporate.com/dtds/expresso-services_5_1.dtd"); 71 72 XMLSerializer serializer 73 = new XMLSerializer(os, format); 74 serializer.serialize(document); 75 } catch (IOException ex) { 76 throw new ExpressoRuntimeException("I/O Error writing config file", ex); 77 } 78 79 } 80 } | Popular Tags |