Search in sources :

Example 1 with EntityResolver2

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);
}
Also used : EntityResolver2(org.xml.sax.ext.EntityResolver2) Test(org.junit.Test)

Example 2 with EntityResolver2

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;
}
Also used : Digester(org.apache.tomcat.util.digester.Digester) EntityResolver2(org.xml.sax.ext.EntityResolver2)

Example 3 with EntityResolver2

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;
}
Also used : InputSource(org.xml.sax.InputSource) CacheXmlParser(org.apache.geode.internal.cache.xmlcache.CacheXmlParser) EntityResolver2(org.xml.sax.ext.EntityResolver2) URL(java.net.URL) SAXException(org.xml.sax.SAXException)

Aggregations

EntityResolver2 (org.xml.sax.ext.EntityResolver2)3 URL (java.net.URL)1 CacheXmlParser (org.apache.geode.internal.cache.xmlcache.CacheXmlParser)1 Digester (org.apache.tomcat.util.digester.Digester)1 Test (org.junit.Test)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1