1 56 57 package org.jdom.adapters; 58 59 import java.io.*; 60 import java.lang.reflect.*; 61 62 import org.jdom.*; 63 import org.w3c.dom.Document ; 64 import org.xml.sax.*; 65 66 72 public class CrimsonDOMAdapter extends AbstractDOMAdapter { 73 74 private static final String CVS_ID = 75 "@(#) $RCSfile: CrimsonDOMAdapter.java,v $ $Revision: 1.16 $ $Date: 2004/02/06 09:28:31 $ $Name: $"; 76 77 88 public Document getDocument(InputStream in, boolean validate) 89 throws IOException, JDOMException { 90 91 try { 92 Class [] parameterTypes = new Class [2]; 93 parameterTypes[0] = Class.forName("java.io.InputStream"); 94 parameterTypes[1] = boolean.class; 95 96 Object [] args = new Object [2]; 97 args[0] = in; 98 args[1] = new Boolean (false); 99 100 Class parserClass = Class.forName("org.apache.crimson.tree.XmlDocument"); 102 Method createXmlDocument = 103 parserClass.getMethod("createXmlDocument", parameterTypes); 104 Document doc = 105 (Document )createXmlDocument.invoke(null, args); 106 107 return doc; 108 109 } catch (InvocationTargetException e) { 110 Throwable targetException = e.getTargetException(); 111 if (targetException instanceof org.xml.sax.SAXParseException ) { 112 SAXParseException parseException = (SAXParseException)targetException; 113 throw new JDOMException("Error on line " + parseException.getLineNumber() + 114 " of XML document: " + parseException.getMessage(), parseException); 115 } else if (targetException instanceof IOException) { 116 IOException ioException = (IOException) targetException; 117 throw ioException; 118 } else { 119 throw new JDOMException(targetException.getMessage(), targetException); 120 } 121 } catch (Exception e) { 122 throw new JDOMException(e.getClass().getName() + ": " + 123 e.getMessage(), e); 124 } 125 } 126 127 134 public Document createDocument() throws JDOMException { 135 try { 136 return 137 (Document )Class.forName( 138 "org.apache.crimson.tree.XmlDocument") 139 .newInstance(); 140 141 } catch (Exception e) { 142 throw new JDOMException(e.getClass().getName() + ": " + 143 e.getMessage() + " when creating document", e); 144 } 145 } 146 } 147
| Popular Tags
|