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.*; 64 import org.w3c.dom.Document ; 65 66 73 public abstract class AbstractDOMAdapter implements DOMAdapter { 74 75 private static final String CVS_ID = 76 "@(#) $RCSfile: AbstractDOMAdapter.java,v $ $Revision: 1.20 $ $Date: 2004/02/06 09:28:31 $ $Name: $"; 77 78 89 public Document getDocument(File filename, boolean validate) 90 throws IOException, JDOMException { 91 92 return getDocument(new FileInputStream(filename), validate); 93 } 94 95 106 public abstract Document getDocument(InputStream in, boolean validate) 107 throws IOException, JDOMException; 108 109 116 public abstract Document createDocument() throws JDOMException; 117 118 128 public Document createDocument(DocType doctype) throws JDOMException { 129 if (doctype == null) { 130 return createDocument(); 131 } 132 133 DOMImplementation domImpl = createDocument().getImplementation(); 134 DocumentType domDocType = domImpl.createDocumentType( 135 doctype.getElementName(), 136 doctype.getPublicID(), 137 doctype.getSystemID()); 138 139 setInternalSubset(domDocType, doctype.getInternalSubset()); 141 142 return domImpl.createDocument("http://temporary", 143 doctype.getElementName(), 144 domDocType); 145 } 146 147 156 protected void setInternalSubset(DocumentType dt, String s) { 157 if (dt == null || s == null) return; 158 159 try { 163 Class dtclass = dt.getClass(); 164 Method setInternalSubset = dtclass.getMethod( 165 "setInternalSubset", new Class [] {java.lang.String .class}); 166 setInternalSubset.invoke(dt, new Object [] {s}); 167 } 168 catch (Exception e) { 169 } 171 } 172 } 173 | Popular Tags |