com.thaiopensource.resolver.catalog.CatalogEntityResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wicketstuff-jing Show documentation
Show all versions of wicketstuff-jing Show documentation
Jing is a validator for RELAX NG and other schema languages. This
project was taken from http://code.google.com/p/jing-trang and
mavenized for inclusion in the Wicket Stuff HTML Validator.
The code was taken from the 20091111 release.
package com.thaiopensource.resolver.catalog;
import org.apache.xml.resolver.helpers.BootstrapResolver;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.net.URL;
/**
* An EntityResolver for use when parsing catalogs.
*/
class CatalogEntityResolver implements EntityResolver {
private final EntityResolver entityResolver;
CatalogEntityResolver(EntityResolver entityResolver) {
this.entityResolver = entityResolver;
}
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (BootstrapResolver.xmlCatalogPubId.equals(publicId)
|| BootstrapResolver.xmlCatalogSysId.equals(systemId)) {
URL url = BootstrapResolver.class.getResource("/org/apache/xml/resolver/etc/catalog.dtd");
if (url != null) {
InputSource in = new InputSource(url.toString());
// Avoid any weirdness the parser may perform on URLs
in.setByteStream(url.openStream());
in.setPublicId(publicId);
return in;
}
}
if (entityResolver != null)
return entityResolver.resolveEntity(publicId, systemId);
return null;
}
}