public InternalResolver() { log("Apache resolver library not found, internal resolver will be used", Project.MSG_VERBOSE); }
public ExternalResolver(Class<?> resolverImplClass, Object resolverImpl) { this.resolverImpl = resolverImpl; // // Get Method instances for each of the methods we need to // call on the resolverImpl using reflection. We can't // call them directly, because they require on the // xml-commons resolver library which may not be available // in the classpath. // try { setXMLCatalog = resolverImplClass.getMethod("setXMLCatalog", XMLCatalog.class); parseCatalog = resolverImplClass.getMethod("parseCatalog", String.class); resolveEntity = resolverImplClass.getMethod("resolveEntity", String.class, String.class); resolve = resolverImplClass.getMethod("resolve", String.class, String.class); } catch (NoSuchMethodException ex) { throw new BuildException(ex); } log("Apache resolver library found, xml-commons resolver will be used", Project.MSG_VERBOSE); }
@Override public InputSource resolveEntity(String publicId, String systemId) { InputSource result = null; ResourceLocation matchingEntry = findMatchingEntry(publicId); if (matchingEntry != null) { log("Matching catalog entry found for publicId: '" + matchingEntry.getPublicId() + "' location: '" + matchingEntry.getLocation() + "'", Project.MSG_DEBUG); result = filesystemLookup(matchingEntry); if (result == null) { result = classpathLookup(matchingEntry); } if (result == null) { result = urlLookup(matchingEntry); } } return result; }
log("uri : '" + uri + "' matches a readable file", Project.MSG_DEBUG); try { log("uri : '" + uri + "' does not match a readable file", Project.MSG_DEBUG); String fileName = FILE_UTILS.fromURI(url.toString()); if (fileName != null) { log("fileName " + fileName, Project.MSG_DEBUG); File resFile = new File(fileName); if (resFile.exists() && resFile.canRead()) { String sysid = JAXPUtils.getSystemId(resFile); source.setSystemId(sysid); log("catalog entry matched a readable file: '" + sysid + "'", Project.MSG_DEBUG); } catch (IOException ex) {
if (matchingEntry != null) { log("Matching catalog entry found for publicId: '" + matchingEntry.getPublicId() + "' location: '" + matchingEntry.getLocation() + "'",
String sysid = url.toExternalForm(); source.setSystemId(sysid); log("catalog entry matched as a URL: '" + sysid + "'", Project.MSG_DEBUG);
/** * Implements the EntityResolver.resolveEntity() interface method. * @param publicId the public id to resolve. * @param systemId the system id to resolve. * @throws SAXException if there is a parsing problem. * @throws IOException if there is an IO problem. * @return the resolved entity. * @see org.xml.sax.EntityResolver#resolveEntity */ @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (isReference()) { return getRef().resolveEntity(publicId, systemId); } dieOnCircularReference(); log("resolveEntity: '" + publicId + "': '" + systemId + "'", Project.MSG_DEBUG); InputSource inputSource = getCatalogResolver().resolveEntity(publicId, systemId); if (inputSource == null) { log("No matching catalog entry found, parser will use: '" + systemId + "'", Project.MSG_DEBUG); } return inputSource; }
/** * Utility method to lookup a ResourceLocation in the classpath. * * @return An InputSource for reading the resource, or <code>null</code> * if the resource does not exist in the classpath or is not readable. */ private InputSource classpathLookup(ResourceLocation matchingEntry) { InputSource source = null; Path cp = classpath; if (cp != null) { cp = classpath.concatSystemClasspath("ignore"); } else { cp = (new Path(getProject())).concatSystemClasspath("last"); } AntClassLoader loader = getProject().createClassLoader(cp); // // for classpath lookup we ignore the base directory // InputStream is = loader.getResourceAsStream(matchingEntry.getLocation()); if (is != null) { source = new InputSource(is); URL entryURL = loader.getResource(matchingEntry.getLocation()); String sysid = entryURL.toExternalForm(); source.setSystemId(sysid); log("catalog entry matched a resource in the classpath: '" + sysid + "'", Project.MSG_DEBUG); } return source; }
log("Matching catalog entry found for uri: '" + matchingEntry.getPublicId() + "' location: '" + matchingEntry.getLocation() + "'",
log("Matching catalog entry found for uri: '" + matchingEntry.getPublicId() + "' location: '" + matchingEntry.getLocation() + "'",