All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thaiopensource.resolver.catalog.CatalogEntityResolver Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.11
Show newest version
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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy