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

com.thaiopensource.resolver.load.ResolverLoader 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.load;

import com.thaiopensource.resolver.Resolver;
import com.thaiopensource.resolver.SequenceResolver;
import com.thaiopensource.resolver.xml.sax.SAX;
import com.thaiopensource.resolver.xml.transform.Transform;
import org.xml.sax.EntityResolver;

import javax.xml.transform.URIResolver;

/**
 * XXX maybe get rid of this
 */
public class ResolverLoader {
  public static Resolver loadResolver(String className, ClassLoader loader) throws ResolverLoadException {
    Object obj;
    try {
      if (loader == null) {
        loader = Thread.currentThread().getContextClassLoader();
        if (loader == null) {
          loader = ClassLoader.getSystemClassLoader();
          if (loader == null)
            throw new ResolverLoadException("no class loader");
        }
      }
      obj = loader.loadClass(className).newInstance();
    }
    catch (Exception e) {
      throw new ResolverLoadException(e);
    }
    if (obj instanceof Resolver)
      return (Resolver)obj;
    Resolver entityResolver = null;
    Resolver uriResolver = null;
    if (obj instanceof URIResolver)
      uriResolver = Transform.createResolver((URIResolver)obj);
    if (obj instanceof EntityResolver)
      entityResolver = SAX.createResolver((EntityResolver)obj, uriResolver == null);
    if (uriResolver == null) {
      if (entityResolver == null)
        throw new ResolverLoadException(className +
                                        " not an instance of javax.xml.transform.URIResolver or org.xml.sax.EntityResolver");
      return entityResolver;
    }
    if (entityResolver == null)
      return uriResolver;
    // do the entityResolver first so that it has first go at ExternalIdentifier
    return new SequenceResolver(entityResolver, uriResolver);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy