1 19 package org.jahia.utils.xml; 20 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.FileNotFoundException ; 25 import java.util.Hashtable ; 26 27 import org.xml.sax.EntityResolver ; 28 import org.xml.sax.InputSource ; 29 30 31 37 public class DtdEntityResolver implements EntityResolver { 38 39 42 private Hashtable m_DTDs = new Hashtable (); 43 44 45 51 public InputSource resolveEntity (String publicID, String systemID) { 52 53 55 if ( publicID == null ){ 56 return null; 57 } 58 59 String dtd = null; 60 61 if ( m_DTDs.get(publicID) != null ){ 62 dtd = (String ) m_DTDs.get(publicID); 63 } 64 65 if( dtd != null ) { 66 File f = new File ( dtd ); 68 if( f.exists() ) 69 try { 70 return new InputSource (new FileInputStream (f)); 71 } catch( FileNotFoundException ex ) { 72 } 73 } 74 75 return null; 76 } 77 78 79 84 public void registerDTD(String publicID, String dtd) { 85 86 m_DTDs.put(publicID, dtd); 87 88 } 89 90 91 } | Popular Tags |