use of org.xml.sax.ext.EntityResolver2 in project geode by apache.
the class AbstractEntityResolverTest method testDiscovery.
/**
* Find the {@link PivotalEntityResolver} in the {@link ClassPathLoader}. Verifies that the
* META-INF/services file is correctly found and the the implementation class is loadable.
*
* @since GemFire 8.1
*/
@Test
public void testDiscovery() {
boolean found = false;
final ServiceLoader<EntityResolver2> entityResolvers = ServiceLoader.load(EntityResolver2.class, ClassPathLoader.getLatestAsClassLoader());
for (final EntityResolver2 entityResolver : entityResolvers) {
if (getEntityResolver().getClass().isAssignableFrom(entityResolver.getClass())) {
found = true;
break;
}
}
assertTrue("Resolver not found.", found);
}
use of org.xml.sax.ext.EntityResolver2 in project tomcat by apache.
the class DigesterFactory method newDigester.
/**
* Create a <code>Digester</code> parser.
* @param xmlValidation turn on/off xml validation
* @param xmlNamespaceAware turn on/off namespace validation
* @param rule an instance of <code>RuleSet</code> used for parsing the xml.
* @param blockExternal turn on/off the blocking of external resources
* @return a new digester
*/
public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule, boolean blockExternal) {
Digester digester = new Digester();
digester.setNamespaceAware(xmlNamespaceAware);
digester.setValidating(xmlValidation);
digester.setUseContextClassLoader(true);
EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS, SERVLET_API_SYSTEM_IDS, blockExternal);
digester.setEntityResolver(resolver);
if (rule != null) {
digester.addRuleSet(rule);
}
return digester;
}
use of org.xml.sax.ext.EntityResolver2 in project geode by apache.
the class CacheElement method resolveSchema.
/**
* Resolve schema from <code>schemaLocationsNape</code> or <code>namespaceUri</code> for given
* <code>namespaceUri</code>.
*
* @param schemaLocationMap {@link Map} of namespaceUri to URLs.
* @param namespaceUri Namespace URI for schema.
* @return {@link InputSource} for schema if found.
* @throws IOException if unable to open {@link InputSource}.
* @since GemFire 8.1
*/
private static InputSource resolveSchema(final Map<String, List<String>> schemaLocationMap, String namespaceUri) throws IOException {
final EntityResolver2 entityResolver = new CacheXmlParser();
InputSource inputSource = null;
// Try loading schema from locations until we find one.
final List<String> locations = schemaLocationMap.get(namespaceUri);
for (final String location : locations) {
try {
inputSource = entityResolver.resolveEntity(null, location);
if (null != inputSource) {
break;
}
} catch (final SAXException e) {
// ignore
}
}
if (null == inputSource) {
// Try getting it from the namespace, will throw if does not exist.
inputSource = new InputSource(new URL(namespaceUri).openStream());
}
return inputSource;
}
Aggregations