001    package railo.runtime.text.xml;
002    
003    import org.xml.sax.InputSource;
004    import org.xml.sax.SAXException;
005    import org.xml.sax.helpers.DefaultHandler;
006    
007    import railo.commons.io.IOUtil;
008    import railo.commons.net.HTTPUtil;
009    
010    
011    
012    public class XMLEntityResolverDefaultHandler extends DefaultHandler {
013    
014            private InputSource entityRes;
015    
016            public XMLEntityResolverDefaultHandler(InputSource entityRes) {
017                    this.entityRes=entityRes;
018            }
019            
020            @Override
021            public InputSource resolveEntity(String publicID, String systemID) throws SAXException {
022                    //if(entityRes!=null)print.out("resolveEntity("+(entityRes!=null)+"):"+publicID+":"+systemID);
023                    
024                    if(entityRes!=null) return entityRes;
025                    try {
026                            // TODO user resources
027                            return new InputSource(IOUtil.toBufferedInputStream(HTTPUtil.toURL(systemID).openStream()));
028                    } 
029                    catch (Throwable t) {
030                            return null;
031                    }
032            }
033            
034    }