1 8 package org.apache.avalon.phoenix.tools.configuration; 9 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import org.xml.sax.EntityResolver ; 13 import org.xml.sax.InputSource ; 14 import org.xml.sax.SAXException ; 15 16 23 public class DTDResolver 24 implements EntityResolver 25 { 26 29 private final DTDInfo[] m_dtdInfos; 30 31 34 private final ClassLoader m_classLoader; 35 36 40 public DTDResolver( final DTDInfo[] dtdInfos, final ClassLoader classLoader ) 41 { 42 m_dtdInfos = dtdInfos; 43 m_classLoader = classLoader; 44 } 45 46 50 public InputSource resolveEntity( final String publicId, final String systemId ) 51 throws IOException , SAXException 52 { 53 for( int i = 0; i < m_dtdInfos.length; i++ ) 54 { 55 final DTDInfo info = m_dtdInfos[ i ]; 56 57 if( (publicId != null && publicId.equals( info.getPublicId() )) || 58 (systemId != null && systemId.equals( info.getSystemId() )) ) 59 { 60 final ClassLoader classLoader = getClassLoader(); 61 final InputStream inputStream = 62 classLoader.getResourceAsStream( info.getResource() ); 63 return new InputSource ( inputStream ); 64 } 65 } 66 67 return null; 68 } 69 70 76 private ClassLoader getClassLoader() 77 { 78 ClassLoader classLoader = m_classLoader; 79 if( null == classLoader ) 80 { 81 classLoader = Thread.currentThread().getContextClassLoader(); 82 } 83 if( null == classLoader ) 84 { 85 classLoader = getClass().getClassLoader(); 86 } 87 return classLoader; 88 } 89 } 90 | Popular Tags |