/** Parses the given InputSource into a Document. */ private Document parseInputSource(InputSource s) throws SAXException, IOException { db.setEntityResolver(new JstlEntityResolver(pageContext)); // normalize URIs so they can be processed consistently by resolver if (systemId == null) { s.setSystemId("jstl:"); } else if (ImportSupport.isAbsoluteUrl(systemId)) { s.setSystemId(systemId); } else { s.setSystemId("jstl:" + systemId); } return db.parse(s); }
public InputSource resolveEntity(String publicId, String systemId) throws FileNotFoundException { // pass if we don't have a systemId if (systemId == null) { return null; } // strip leading "jstl:" off URL if applicable if (systemId.startsWith("jstl:")) { systemId = systemId.substring(5); } // we're only concerned with relative URLs if (ImportSupport.isAbsoluteUrl(systemId)) { return null; } // for relative URLs, load and wrap the resource. // don't bother checking for 'null' since we specifically want // the parser to fail if the resource doesn't exist InputStream s; if (systemId.startsWith("/")) { s = ctx.getServletContext().getResourceAsStream(systemId); if (s == null) { throw new FileNotFoundException( Resources.getMessage("UNABLE_TO_RESOLVE_ENTITY", systemId)); } } else { String pagePath = ((HttpServletRequest) ctx.getRequest()).getServletPath(); String basePath = pagePath.substring(0, pagePath.lastIndexOf("/")); s = ctx.getServletContext().getResourceAsStream(basePath + "/" + systemId); if (s == null) { throw new FileNotFoundException( Resources.getMessage("UNABLE_TO_RESOLVE_ENTITY", systemId)); } } return new InputSource(s); }