1 50 51 package org.apache.avalon.meta; 52 53 import java.io.IOException ; 54 import java.io.InputStream ; 55 import org.xml.sax.EntityResolver ; 56 import org.xml.sax.InputSource ; 57 import org.xml.sax.SAXException ; 58 59 67 class DTDResolver 68 implements EntityResolver 69 { 70 73 private final DTDInfo[] m_dtdInfos; 74 75 78 private final ClassLoader m_classLoader; 79 80 84 public DTDResolver( final DTDInfo[] dtdInfos, final ClassLoader classLoader ) 85 { 86 m_dtdInfos = dtdInfos; 87 m_classLoader = classLoader; 88 } 89 90 94 public InputSource resolveEntity( final String publicId, final String systemId ) 95 throws IOException , SAXException 96 { 97 for( int i = 0; i < m_dtdInfos.length; i++ ) 98 { 99 final DTDInfo info = m_dtdInfos[ i ]; 100 101 if( ( publicId != null && publicId.equals( info.getPublicId() ) ) 102 || ( systemId != null && systemId.equals( info.getSystemId() ) ) ) 103 { 104 final ClassLoader classLoader = getClassLoader(); 105 final InputStream inputStream = 106 classLoader.getResourceAsStream( info.getResource() ); 107 return new InputSource ( inputStream ); 108 } 109 } 110 111 return null; 112 } 113 114 120 private ClassLoader getClassLoader() 121 { 122 ClassLoader classLoader = m_classLoader; 123 if( null == classLoader ) 124 { 125 classLoader = Thread.currentThread().getContextClassLoader(); 126 } 127 if( null == classLoader ) 128 { 129 classLoader = getClass().getClassLoader(); 130 } 131 return classLoader; 132 } 133 } 134 | Popular Tags |