org.apache.xml.resolver_1.2.0.v201005080400

 + encodedByte(ch);
      } else {
        newRef = newRef + (char)bytes[count];
      }
    }
    return newRef;
  }
  
  protected String encodedByte(int b)
  {
    String hex = Integer.toHexString(b).toUpperCase();
    if (hex.length() < 2) {
      return "%0" + hex;
    }
    return "%" + hex;
  }
  
  protected void addDelegate(CatalogEntry entry)
  {
    int pos = 0;
    String partial = entry.getEntryArg(0);
    
    Enumeration local = localDelegate.elements();
    while (local.hasMoreElements())
    {
      CatalogEntry dpe = (CatalogEntry)local.nextElement();
      String dp = dpe.getEntryArg(0);
      if (dp.equals(partial)) {
        return;
      }
      if (dp.length() > partial.length()) {
        pos++;
      }
      if (dp.length() < partial.length()) {
        break;
      }
    }
    if (localDelegate.size() == 0) {
      localDelegate.addElement(entry);
    } else {
      localDelegate.insertElementAt(entry, pos);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.Catalog
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver;

import java.util.Hashtable;
import java.util.Vector;

public class CatalogEntry
{
  protected static int nextEntry = 0;
  protected static Hashtable entryTypes = new Hashtable();
  protected static Vector entryArgs = new Vector();
  
  public static int addEntryType(String name, int numArgs)
  {
    entryTypes.put(name, new Integer(nextEntry));
    entryArgs.add(nextEntry, new Integer(numArgs));
    nextEntry += 1;
    
    return nextEntry - 1;
  }
  
  public static int getEntryType(String name)
    throws CatalogException
  {
    if (!entryTypes.containsKey(name)) {
      throw new CatalogException(3);
    }
    Integer iType = (Integer)entryTypes.get(name);
    if (iType == null) {
      throw new CatalogException(3);
    }
    return iType.intValue();
  }
  
  public static int getEntryArgCount(String name)
    throws CatalogException
  {
    return getEntryArgCount(getEntryType(name));
  }
  
  public static int getEntryArgCount(int type)
    throws CatalogException
  {
    try
    {
      Integer iArgs = (Integer)entryArgs.get(type);
      return iArgs.intValue();
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      throw new CatalogException(3);
    }
  }
  
  protected int entryType = 0;
  protected Vector args = null;
  
  public CatalogEntry() {}
  
  public CatalogEntry(String name, Vector args)
    throws CatalogException
  {
    Integer iType = (Integer)entryTypes.get(name);
    if (iType == null) {
      throw new CatalogException(3);
    }
    int type = iType.intValue();
    try
    {
      Integer iArgs = (Integer)entryArgs.get(type);
      if (iArgs.intValue() != args.size()) {
        throw new CatalogException(2);
      }
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      throw new CatalogException(3);
    }
    entryType = type;
    this.args = args;
  }
  
  public CatalogEntry(int type, Vector args)
    throws CatalogException
  {
    try
    {
      Integer iArgs = (Integer)entryArgs.get(type);
      if (iArgs.intValue() != args.size()) {
        throw new CatalogException(2);
      }
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      throw new CatalogException(3);
    }
    entryType = type;
    this.args = args;
  }
  
  public int getEntryType()
  {
    return entryType;
  }
  
  public String getEntryArg(int argNum)
  {
    try
    {
      return (String)args.get(argNum);
    }
    catch (ArrayIndexOutOfBoundsException e) {}
    return null;
  }
  
  public void setEntryArg(int argNum, String newspec)
    throws ArrayIndexOutOfBoundsException
  {
    args.set(argNum, newspec);
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.CatalogEntry
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver;

public class CatalogException
  extends Exception
{
  public static final int WRAPPER = 1;
  public static final int INVALID_ENTRY = 2;
  public static final int INVALID_ENTRY_TYPE = 3;
  public static final int NO_XML_PARSER = 4;
  public static final int UNKNOWN_FORMAT = 5;
  public static final int UNPARSEABLE = 6;
  public static final int PARSE_FAILED = 7;
  public static final int UNENDED_COMMENT = 8;
  private Exception exception = null;
  private int exceptionType = 0;
  
  public CatalogException(int type, String message)
  {
    super(message);
    exceptionType = type;
    exception = null;
  }
  
  public CatalogException(int type)
  {
    super("Catalog Exception " + type);
    exceptionType = type;
    exception = null;
  }
  
  public CatalogException(Exception e)
  {
    exceptionType = 1;
    exception = e;
  }
  
  public CatalogException(String message, Exception e)
  {
    super(message);
    exceptionType = 1;
    exception = e;
  }
  
  public String getMessage()
  {
    String message = super.getMessage();
    if ((message == null) && (exception != null)) {
      return exception.getMessage();
    }
    return message;
  }
  
  public Exception getException()
  {
    return exception;
  }
  
  public int getExceptionType()
  {
    return exceptionType;
  }
  
  public String toString()
  {
    if (exception != null) {
      return exception.toString();
    }
    return super.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.CatalogException
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.Vector;
import org.apache.xml.resolver.helpers.BootstrapResolver;
import org.apache.xml.resolver.helpers.Debug;

public class CatalogManager
{
  private static String pFiles = "xml.catalog.files";
  private static String pVerbosity = "xml.catalog.verbosity";
  private static String pPrefer = "xml.catalog.prefer";
  private static String pStatic = "xml.catalog.staticCatalog";
  private static String pAllowPI = "xml.catalog.allowPI";
  private static String pClassname = "xml.catalog.className";
  private static String pIgnoreMissing = "xml.catalog.ignoreMissing";
  private static CatalogManager staticManager = new CatalogManager();
  private BootstrapResolver bResolver = new BootstrapResolver();
  private boolean ignoreMissingProperties = (System.getProperty(pIgnoreMissing) != null) || (System.getProperty(pFiles) != null);
  private ResourceBundle resources;
  private String propertyFile = "CatalogManager.properties";
  private URL propertyFileURI = null;
  private String defaultCatalogFiles = "./xcatalog";
  private String catalogFiles = null;
  private boolean fromPropertiesFile = false;
  private int defaultVerbosity = 1;
  private Integer verbosity = null;
  private boolean defaultPreferPublic = true;
  private Boolean preferPublic = null;
  private boolean defaultUseStaticCatalog = true;
  private Boolean useStaticCatalog = null;
  private static Catalog staticCatalog = null;
  private boolean defaultOasisXMLCatalogPI = true;
  private Boolean oasisXMLCatalogPI = null;
  private boolean defaultRelativeCatalogs = true;
  private Boolean relativeCatalogs = null;
  private String catalogClassName = null;
  public Debug debug = null;
  
  public CatalogManager()
  {
    debug = new Debug();
  }
  
  public CatalogManager(String propertyFile)
  {
    this.propertyFile = propertyFile;
    
    debug = new Debug();
  }
  
  public void setBootstrapResolver(BootstrapResolver resolver)
  {
    bResolver = resolver;
  }
  
  public BootstrapResolver getBootstrapResolver()
  {
    return bResolver;
  }
  
  private synchronized void readProperties()
  {
    try
    {
      propertyFileURI = CatalogManager.class.getResource("/" + propertyFile);
      InputStream in = CatalogManager.class.getResourceAsStream("/" + propertyFile);
      if (in == null)
      {
        if (!ignoreMissingProperties)
        {
          System.err.println("Cannot find " + propertyFile);
          
          ignoreMissingProperties = true;
        }
        return;
      }
      resources = new PropertyResourceBundle(in);
    }
    catch (MissingResourceException mre)
    {
      if (!ignoreMissingProperties) {
        System.err.println("Cannot read " + propertyFile);
      }
    }
    catch (IOException e)
    {
      if (!ignoreMissingProperties) {
        System.err.println("Failure trying to read " + propertyFile);
      }
    }
    if (verbosity == null) {
      try
      {
        String verbStr = resources.getString("verbosity");
        int verb = Integer.parseInt(verbStr.trim());
        debug.setDebug(verb);
        verbosity = new Integer(verb);
      }
      catch (Exception e) {}
    }
  }
  
  public static CatalogManager getStaticManager()
  {
    return staticManager;
  }
  
  public boolean getIgnoreMissingProperties()
  {
    return ignoreMissingProperties;
  }
  
  public void setIgnoreMissingProperties(boolean ignore)
  {
    ignoreMissingProperties = ignore;
  }
  
  /**
   * @deprecated
   */
  public void ignoreMissingProperties(boolean ignore)
  {
    setIgnoreMissingProperties(ignore);
  }
  
  private int queryVerbosity()
  {
    String defaultVerbStr = Integer.toString(defaultVerbosity);
    
    String verbStr = System.getProperty(pVerbosity);
    if (verbStr == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources != null) {
        try
        {
          verbStr = resources.getString("verbosity");
        }
        catch (MissingResourceException e)
        {
          verbStr = defaultVerbStr;
        }
      } else {
        verbStr = defaultVerbStr;
      }
    }
    int verb = defaultVerbosity;
    try
    {
      verb = Integer.parseInt(verbStr.trim());
    }
    catch (Exception e)
    {
      System.err.println("Cannot parse verbosity: \"" + verbStr + "\"");
    }
    if (verbosity == null)
    {
      debug.setDebug(verb);
      verbosity = new Integer(verb);
    }
    return verb;
  }
  
  public int getVerbosity()
  {
    if (verbosity == null) {
      verbosity = new Integer(queryVerbosity());
    }
    return verbosity.intValue();
  }
  
  public void setVerbosity(int verbosity)
  {
    this.verbosity = new Integer(verbosity);
    debug.setDebug(verbosity);
  }
  
  /**
   * @deprecated
   */
  public int verbosity()
  {
    return getVerbosity();
  }
  
  private boolean queryRelativeCatalogs()
  {
    if (resources == null) {
      readProperties();
    }
    if (resources == null) {
      return defaultRelativeCatalogs;
    }
    try
    {
      String allow = resources.getString("relative-catalogs");
      return (allow.equalsIgnoreCase("true")) || (allow.equalsIgnoreCase("yes")) || (allow.equalsIgnoreCase("1"));
    }
    catch (MissingResourceException e) {}
    return defaultRelativeCatalogs;
  }
  
  public boolean getRelativeCatalogs()
  {
    if (relativeCatalogs == null) {
      relativeCatalogs = new Boolean(queryRelativeCatalogs());
    }
    return relativeCatalogs.booleanValue();
  }
  
  public void setRelativeCatalogs(boolean relative)
  {
    relativeCatalogs = new Boolean(relative);
  }
  
  /**
   * @deprecated
   */
  public boolean relativeCatalogs()
  {
    return getRelativeCatalogs();
  }
  
  private String queryCatalogFiles()
  {
    String catalogList = System.getProperty(pFiles);
    fromPropertiesFile = false;
    if (catalogList == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources != null) {
        try
        {
          catalogList = resources.getString("catalogs");
          fromPropertiesFile = true;
        }
        catch (MissingResourceException e)
        {
          System.err.println(propertyFile + ": catalogs not found.");
          catalogList = null;
        }
      }
    }
    if (catalogList == null) {
      catalogList = defaultCatalogFiles;
    }
    return catalogList;
  }
  
  public Vector getCatalogFiles()
  {
    if (catalogFiles == null) {
      catalogFiles = queryCatalogFiles();
    }
    StringTokenizer files = new StringTokenizer(catalogFiles, ";");
    Vector catalogs = new Vector();
    while (files.hasMoreTokens())
    {
      String catalogFile = files.nextToken();
      URL absURI = null;
      if ((fromPropertiesFile) && (!relativeCatalogs())) {
        try
        {
          absURI = new URL(propertyFileURI, catalogFile);
          catalogFile = absURI.toString();
        }
        catch (MalformedURLException mue)
        {
          absURI = null;
        }
      }
      catalogs.add(catalogFile);
    }
    return catalogs;
  }
  
  public void setCatalogFiles(String fileList)
  {
    catalogFiles = fileList;
    fromPropertiesFile = false;
  }
  
  /**
   * @deprecated
   */
  public Vector catalogFiles()
  {
    return getCatalogFiles();
  }
  
  private boolean queryPreferPublic()
  {
    String prefer = System.getProperty(pPrefer);
    if (prefer == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources == null) {
        return defaultPreferPublic;
      }
      try
      {
        prefer = resources.getString("prefer");
      }
      catch (MissingResourceException e)
      {
        return defaultPreferPublic;
      }
    }
    if (prefer == null) {
      return defaultPreferPublic;
    }
    return prefer.equalsIgnoreCase("public");
  }
  
  public boolean getPreferPublic()
  {
    if (preferPublic == null) {
      preferPublic = new Boolean(queryPreferPublic());
    }
    return preferPublic.booleanValue();
  }
  
  public void setPreferPublic(boolean preferPublic)
  {
    this.preferPublic = new Boolean(preferPublic);
  }
  
  /**
   * @deprecated
   */
  public boolean preferPublic()
  {
    return getPreferPublic();
  }
  
  private boolean queryUseStaticCatalog()
  {
    String staticCatalog = System.getProperty(pStatic);
    if (staticCatalog == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources == null) {
        return defaultUseStaticCatalog;
      }
      try
      {
        staticCatalog = resources.getString("static-catalog");
      }
      catch (MissingResourceException e)
      {
        return defaultUseStaticCatalog;
      }
    }
    if (staticCatalog == null) {
      return defaultUseStaticCatalog;
    }
    return (staticCatalog.equalsIgnoreCase("true")) || (staticCatalog.equalsIgnoreCase("yes")) || (staticCatalog.equalsIgnoreCase("1"));
  }
  
  public boolean getUseStaticCatalog()
  {
    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(queryUseStaticCatalog());
    }
    return useStaticCatalog.booleanValue();
  }
  
  public void setUseStaticCatalog(boolean useStatic)
  {
    useStaticCatalog = new Boolean(useStatic);
  }
  
  /**
   * @deprecated
   */
  public boolean staticCatalog()
  {
    return getUseStaticCatalog();
  }
  
  public Catalog getPrivateCatalog()
  {
    Catalog catalog = staticCatalog;
    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(getUseStaticCatalog());
    }
    if ((catalog == null) || (!useStaticCatalog.booleanValue()))
    {
      try
      {
        String catalogClassName = getCatalogClassName();
        if (catalogClassName == null) {
          catalog = new Catalog();
        } else {
          try
          {
            catalog = (Catalog)Class.forName(catalogClassName).newInstance();
          }
          catch (ClassNotFoundException cnfe)
          {
            debug.message(1, "Catalog class named '" + catalogClassName + "' could not be found. Using default.");
            
            catalog = new Catalog();
          }
          catch (ClassCastException cnfe)
          {
            debug.message(1, "Class named '" + catalogClassName + "' is not a Catalog. Using default.");
            
            catalog = new Catalog();
          }
        }
        catalog.setCatalogManager(this);
        catalog.setupReaders();
        catalog.loadSystemCatalogs();
      }
      catch (Exception ex)
      {
        ex.printStackTrace();
      }
      if (useStaticCatalog.booleanValue()) {
        staticCatalog = catalog;
      }
    }
    return catalog;
  }
  
  public Catalog getCatalog()
  {
    Catalog catalog = staticCatalog;
    if (useStaticCatalog == null) {
      useStaticCatalog = new Boolean(getUseStaticCatalog());
    }
    if ((catalog == null) || (!useStaticCatalog.booleanValue()))
    {
      catalog = getPrivateCatalog();
      if (useStaticCatalog.booleanValue()) {
        staticCatalog = catalog;
      }
    }
    return catalog;
  }
  
  public boolean queryAllowOasisXMLCatalogPI()
  {
    String allow = System.getProperty(pAllowPI);
    if (allow == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources == null) {
        return defaultOasisXMLCatalogPI;
      }
      try
      {
        allow = resources.getString("allow-oasis-xml-catalog-pi");
      }
      catch (MissingResourceException e)
      {
        return defaultOasisXMLCatalogPI;
      }
    }
    if (allow == null) {
      return defaultOasisXMLCatalogPI;
    }
    return (allow.equalsIgnoreCase("true")) || (allow.equalsIgnoreCase("yes")) || (allow.equalsIgnoreCase("1"));
  }
  
  public boolean getAllowOasisXMLCatalogPI()
  {
    if (oasisXMLCatalogPI == null) {
      oasisXMLCatalogPI = new Boolean(queryAllowOasisXMLCatalogPI());
    }
    return oasisXMLCatalogPI.booleanValue();
  }
  
  public void setAllowOasisXMLCatalogPI(boolean allowPI)
  {
    oasisXMLCatalogPI = new Boolean(allowPI);
  }
  
  /**
   * @deprecated
   */
  public boolean allowOasisXMLCatalogPI()
  {
    return getAllowOasisXMLCatalogPI();
  }
  
  public String queryCatalogClassName()
  {
    String className = System.getProperty(pClassname);
    if (className == null)
    {
      if (resources == null) {
        readProperties();
      }
      if (resources == null) {
        return null;
      }
      try
      {
        return resources.getString("catalog-class-name");
      }
      catch (MissingResourceException e)
      {
        return null;
      }
    }
    return className;
  }
  
  public String getCatalogClassName()
  {
    if (catalogClassName == null) {
      catalogClassName = queryCatalogClassName();
    }
    return catalogClassName;
  }
  
  public void setCatalogClassName(String className)
  {
    catalogClassName = className;
  }
  
  /**
   * @deprecated
   */
  public String catalogClassName()
  {
    return getCatalogClassName();
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.CatalogManager
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.Vector;
import javax.xml.parsers.SAXParserFactory;
import org.apache.xml.resolver.helpers.Debug;
import org.apache.xml.resolver.readers.SAXCatalogReader;
import org.apache.xml.resolver.readers.TR9401CatalogReader;

public class Resolver
  extends Catalog
{
  public static final int URISUFFIX = CatalogEntry.addEntryType("URISUFFIX", 2);
  public static final int SYSTEMSUFFIX = CatalogEntry.addEntryType("SYSTEMSUFFIX", 2);
  public static final int RESOLVER = CatalogEntry.addEntryType("RESOLVER", 1);
  public static final int SYSTEMREVERSE = CatalogEntry.addEntryType("SYSTEMREVERSE", 1);
  
  public void setupReaders()
  {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(false);
    
    SAXCatalogReader saxReader = new SAXCatalogReader(spf);
    
    saxReader.setCatalogParser(null, "XCatalog", "org.apache.xml.resolver.readers.XCatalogReader");
    
    saxReader.setCatalogParser("urn:oasis:names:tc:entity:xmlns:xml:catalog", "catalog", "org.apache.xml.resolver.readers.ExtendedXMLCatalogReader");
    
    addReader("application/xml", saxReader);
    
    TR9401CatalogReader textReader = new TR9401CatalogReader();
    addReader("text/plain", textReader);
  }
  
  public void addEntry(CatalogEntry entry)
  {
    int type = entry.getEntryType();
    if (type == URISUFFIX)
    {
      String suffix = normalizeURI(entry.getEntryArg(0));
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
      
      entry.setEntryArg(1, fsi);
      
      catalogManager.debug.message(4, "URISUFFIX", suffix, fsi);
    }
    else if (type == SYSTEMSUFFIX)
    {
      String suffix = normalizeURI(entry.getEntryArg(0));
      String fsi = makeAbsolute(normalizeURI(entry.getEntryArg(1)));
      
      entry.setEntryArg(1, fsi);
      
      catalogManager.debug.message(4, "SYSTEMSUFFIX", suffix, fsi);
    }
    super.addEntry(entry);
  }
  
  public String resolveURI(String uri)
    throws MalformedURLException, IOException
  {
    String resolved = super.resolveURI(uri);
    if (resolved != null) {
      return resolved;
    }
    Enumeration en = catalogEntries.elements();
    while (en.hasMoreElements())
    {
      CatalogEntry e = (CatalogEntry)en.nextElement();
      if (e.getEntryType() == RESOLVER)
      {
        resolved = resolveExternalSystem(uri, e.getEntryArg(0));
        if (resolved != null) {
          return resolved;
        }
      }
      else if (e.getEntryType() == URISUFFIX)
      {
        String suffix = e.getEntryArg(0);
        String result = e.getEntryArg(1);
        if ((suffix.length() <= uri.length()) && (uri.substring(uri.length() - suffix.length()).equals(suffix))) {
          return result;
        }
      }
    }
    return resolveSubordinateCatalogs(Catalog.URI, null, null, uri);
  }
  
  public String resolveSystem(String systemId)
    throws MalformedURLException, IOException
  {
    String resolved = super.resolveSystem(systemId);
    if (resolved != null) {
      return resolved;
    }
    Enumeration en = catalogEntries.elements();
    while (en.hasMoreElements())
    {
      CatalogEntry e = (CatalogEntry)en.nextElement();
      if (e.getEntryType() == RESOLVER)
      {
        resolved = resolveExternalSystem(systemId, e.getEntryArg(0));
        if (resolved != null) {
          return resolved;
        }
      }
      else if (e.getEntryType() == SYSTEMSUFFIX)
      {
        String suffix = e.getEntryArg(0);
        String result = e.getEntryArg(1);
        if ((suffix.length() <= systemId.length()) && (systemId.substring(systemId.length() - suffix.length()).equals(suffix))) {
          return result;
        }
      }
    }
    return resolveSubordinateCatalogs(Catalog.SYSTEM, null, null, systemId);
  }
  
  public String resolvePublic(String publicId, String systemId)
    throws MalformedURLException, IOException
  {
    String resolved = super.resolvePublic(publicId, systemId);
    if (resolved != null) {
      return resolved;
    }
    Enumeration en = catalogEntries.elements();
    while (en.hasMoreElements())
    {
      CatalogEntry e = (CatalogEntry)en.nextElement();
      if (e.getEntryType() == RESOLVER)
      {
        if (systemId != null)
        {
          resolved = resolveExternalSystem(systemId, e.getEntryArg(0));
          if (resolved != null) {
            return resolved;
          }
        }
        resolved = resolveExternalPublic(publicId, e.getEntryArg(0));
        if (resolved != null) {
          return resolved;
        }
      }
    }
    return resolveSubordinateCatalogs(Catalog.PUBLIC, null, publicId, systemId);
  }
  
  protected String resolveExternalSystem(String systemId, String resolver)
    throws MalformedURLException, IOException
  {
    Resolver r = queryResolver(resolver, "i2l", systemId, null);
    if (r != null) {
      return r.resolveSystem(systemId);
    }
    return null;
  }
  
  protected String resolveExternalPublic(String publicId, String resolver)
    throws MalformedURLException, IOException
  {
    Resolver r = queryResolver(resolver, "fpi2l", publicId, null);
    if (r != null) {
      return r.resolvePublic(publicId, null);
    }
    return null;
  }
  
  protected Resolver queryResolver(String resolver, String command, String arg1, String arg2)
  {
    InputStream iStream = null;
    String RFC2483 = resolver + "?command=" + command + "&format=tr9401&uri=" + arg1 + "&uri2=" + arg2;
    
    String line = null;
    try
    {
      URL url = new URL(RFC2483);
      
      URLConnection urlCon = url.openConnection();
      
      urlCon.setUseCaches(false);
      
      Resolver r = (Resolver)newCatalog();
      
      String cType = urlCon.getContentType();
      if (cType.indexOf(";") > 0) {
        cType = cType.substring(0, cType.indexOf(";"));
      }
      r.parseCatalog(cType, urlCon.getInputStream());
      
      return r;
    }
    catch (CatalogException cex)
    {
      if (cex.getExceptionType() == 6) {
        catalogManager.debug.message(1, "Unparseable catalog: " + RFC2483);
      } else if (cex.getExceptionType() == 5) {
        catalogManager.debug.message(1, "Unknown catalog format: " + RFC2483);
      }
      return null;
    }
    catch (MalformedURLException mue)
    {
      catalogManager.debug.message(1, "Malformed resolver URL: " + RFC2483);
      return null;
    }
    catch (IOException ie)
    {
      catalogManager.debug.message(1, "I/O Exception opening resolver: " + RFC2483);
    }
    return null;
  }
  
  private Vector appendVector(Vector vec, Vector appvec)
  {
    if (appvec != null) {
      for (int count = 0; count < appvec.size(); count++) {
        vec.addElement(appvec.elementAt(count));
      }
    }
    return vec;
  }
  
  public Vector resolveAllSystemReverse(String systemId)
    throws MalformedURLException, IOException
  {
    Vector resolved = new Vector();
    if (systemId != null)
    {
      Vector localResolved = resolveLocalSystemReverse(systemId);
      resolved = appendVector(resolved, localResolved);
    }
    Vector subResolved = resolveAllSubordinateCatalogs(SYSTEMREVERSE, null, null, systemId);
    
    return appendVector(resolved, subResolved);
  }
  
  public String resolveSystemReverse(String systemId)
    throws MalformedURLException, IOException
  {
    Vector resolved = resolveAllSystemReverse(systemId);
    if ((resolved != null) && (resolved.size() > 0)) {
      return (String)resolved.elementAt(0);
    }
    return null;
  }
  
  public Vector resolveAllSystem(String systemId)
    throws MalformedURLException, IOException
  {
    Vector resolutions = new Vector();
    if (systemId != null)
    {
      Vector localResolutions = resolveAllLocalSystem(systemId);
      resolutions = appendVector(resolutions, localResolutions);
    }
    Vector subResolutions = resolveAllSubordinateCatalogs(Catalog.SYSTEM, null, null, systemId);
    
    resolutions = appendVector(resolutions, subResolutions);
    if (resolutions.size() > 0) {
      return resolutions;
    }
    return null;
  }
  
  private Vector resolveAllLocalSystem(String systemId)
  {
    Vector map = new Vector();
    String osname = System.getProperty("os.name");
    boolean windows = osname.indexOf("Windows") >= 0;
    Enumeration en = catalogEntries.elements();
    while (en.hasMoreElements())
    {
      CatalogEntry e = (CatalogEntry)en.nextElement();
      if ((e.getEntryType() == Catalog.SYSTEM) && ((e.getEntryArg(0).equals(systemId)) || ((windows) && (e.getEntryArg(0).equalsIgnoreCase(systemId))))) {
        map.addElement(e.getEntryArg(1));
      }
    }
    if (map.size() == 0) {
      return null;
    }
    return map;
  }
  
  private Vector resolveLocalSystemReverse(String systemId)
  {
    Vector map = new Vector();
    String osname = System.getProperty("os.name");
    boolean windows = osname.indexOf("Windows") >= 0;
    Enumeration en = catalogEntries.elements();
    while (en.hasMoreElements())
    {
      CatalogEntry e = (CatalogEntry)en.nextElement();
      if ((e.getEntryType() == Catalog.SYSTEM) && ((e.getEntryArg(1).equals(systemId)) || ((windows) && (e.getEntryArg(1).equalsIgnoreCase(systemId))))) {
        map.addElement(e.getEntryArg(0));
      }
    }
    if (map.size() == 0) {
      return null;
    }
    return map;
  }
  
  private synchronized Vector resolveAllSubordinateCatalogs(int entityType, String entityName, String publicId, String systemId)
    throws MalformedURLException, IOException
  {
    Vector resolutions = new Vector();
    for (int catPos = 0; catPos < catalogs.size(); catPos++)
    {
      Resolver c = null;
      try
      {
        c = (Resolver)catalogs.elementAt(catPos);
      }
      catch (ClassCastException e)
      {
        String catfile = (String)catalogs.elementAt(catPos);
        c = (Resolver)newCatalog();
        try
        {
          c.parseCatalog(catfile);
        }
        catch (MalformedURLException mue)
        {
          catalogManager.debug.message(1, "Malformed Catalog URL", catfile);
        }
        catch (FileNotFoundException fnfe)
        {
          catalogManager.debug.message(1, "Failed to load catalog, file not found", catfile);
        }
        catch (IOException ioe)
        {
          catalogManager.debug.message(1, "Failed to load catalog, I/O error", catfile);
        }
        catalogs.setElementAt(c, catPos);
      }
      String resolved = null;
      if (entityType == Catalog.DOCTYPE)
      {
        resolved = c.resolveDoctype(entityName, publicId, systemId);
        if (resolved != null)
        {
          resolutions.addElement(resolved);
          return resolutions;
        }
      }
      else if (entityType == Catalog.DOCUMENT)
      {
        resolved = c.resolveDocument();
        if (resolved != null)
        {
          resolutions.addElement(resolved);
          return resolutions;
        }
      }
      else if (entityType == Catalog.ENTITY)
      {
        resolved = c.resolveEntity(entityName, publicId, systemId);
        if (resolved != null)
        {
          resolutions.addElement(resolved);
          return resolutions;
        }
      }
      else if (entityType == Catalog.NOTATION)
      {
        resolved = c.resolveNotation(entityName, publicId, systemId);
        if (resolved != null)
        {
          resolutions.addElement(resolved);
          return resolutions;
        }
      }
      else if (entityType == Catalog.PUBLIC)
      {
        resolved = c.resolvePublic(publicId, systemId);
        if (resolved != null)
        {
          resolutions.addElement(resolved);
          return resolutions;
        }
      }
      else
      {
        if (entityType == Catalog.SYSTEM)
        {
          Vector localResolutions = c.resolveAllSystem(systemId);
          resolutions = appendVector(resolutions, localResolutions);
          break;
        }
        if (entityType == SYSTEMREVERSE)
        {
          Vector localResolutions = c.resolveAllSystemReverse(systemId);
          resolutions = appendVector(resolutions, localResolutions);
        }
      }
    }
    if (resolutions != null) {
      return resolutions;
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.Resolver
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver;

import java.io.PrintStream;

public class Version
{
  public static String getVersion()
  {
    return getProduct() + " " + getVersionNum();
  }
  
  public static String getProduct()
  {
    return "XmlResolver";
  }
  
  public static String getVersionNum()
  {
    return "1.2";
  }
  
  public static void main(String[] argv)
  {
    System.out.println(getVersion());
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.Version
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver.apps;

import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xml.resolver.helpers.FileURL;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class XParseError
  implements ErrorHandler
{
  private boolean showErrors = true;
  private boolean showWarnings = false;
  private int maxMessages = 10;
  private int fatalCount = 0;
  private int errorCount = 0;
  private int warningCount = 0;
  private String baseURI = "";
  
  public XParseError(boolean errors, boolean warnings)
  {
    showErrors = errors;
    showWarnings = warnings;
    try
    {
      URL url = FileURL.makeURL("basename");
      baseURI = url.toString();
    }
    catch (MalformedURLException mue) {}
  }
  
  public int getErrorCount()
  {
    return errorCount;
  }
  
  public int getFatalCount()
  {
    return fatalCount;
  }
  
  public int getWarningCount()
  {
    return warningCount;
  }
  
  public int getMaxMessages()
  {
    return maxMessages;
  }
  
  public void setMaxMessages(int max)
  {
    maxMessages = max;
  }
  
  public void error(SAXParseException exception)
  {
    errorCount += 1;
    if ((showErrors) && (errorCount + warningCount < maxMessages)) {
      message("Error", exception);
    }
  }
  
  public void fatalError(SAXParseException exception)
  {
    errorCount += 1;
    fatalCount += 1;
    if ((showErrors) && (errorCount + warningCount < maxMessages)) {
      message("Fatal error", exception);
    }
  }
  
  public void warning(SAXParseException exception)
  {
    warningCount += 1;
    if ((showWarnings) && (errorCount + warningCount < maxMessages)) {
      message("Warning", exception);
    }
  }
  
  private void message(String type, SAXParseException exception)
  {
    String filename = exception.getSystemId();
    if (filename.startsWith(baseURI)) {
      filename = filename.substring(baseURI.length());
    }
    System.out.print(type + ":" + filename + ":" + exception.getLineNumber());
    if (exception.getColumnNumber() > 0) {
      System.out.print(":" + exception.getColumnNumber());
    }
    System.out.println(":" + exception.getMessage());
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.apps.XParseError
 * Java Class Version: 1.1 (45.3)
 * JD-Core Version:    0.7.1
 */
package org.apache.xml.resolver.apps;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.helpers.Debug;
import org.apache.xml.resolver.helpers.FileURL;
import org.apache.xml.resolver.tools.CatalogResolver;

public class resolver
{
  private static Debug debug = getStaticManagerdebug;
  
  public static void main(String[] args)
    throws FileNotFoundException, IOException
  {
    int debuglevel = 0;
    Vector catalogFiles = new Vector();
    int resType = 0;
    String resTypeStr = null;
    String name = null;
    String publicId = null;
    String systemId = null;
    String uri = null;
    boolean absoluteSystem = false;
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-c"))
      {
        i++;
        catalogFiles.add(args[i]);
      }
      else if (args[i].equals("-p"))
      {
        i++;
        publicId = args[i];
      }
      else if (args[i].equals("-s"))
      {
        i++;
        systemId = args[i];
      }
      else if (args[i].equals("-n"))
      {
        i++;
        name = args[i];
      }
      else if (args[i].equals("-u"))
      {
        i++;
        uri = args[i];
      }
      else if (args[i].equals("-a"))
      {
        absoluteSystem = true;
      }
      else if (args[i].equals("-d"))
      {
        i++;
        String debugstr = args[i];
        try
        {
          debuglevel = Integer.parseInt(debugstr);
          if (debuglevel > 0) {
            debug.setDebug(debuglevel);
          }
        }
        catch (Exception e) {}
      }
      else
      {
        resTypeStr = args[i];
      }
    }
    if (resTypeStr == null) {
      usage();
    }
    if (resTypeStr.equalsIgnoreCase("doctype"))
    {
      resType = Catalog.DOCTYPE;
      if ((publicId == null) && (systemId == null))
      {
        System.out.println("DOCTYPE requires public or system identifier.");
        usage();
      }
    }
    else if (resTypeStr.equalsIgnoreCase("document"))
    {
      resType = Catalog.DOCUMENT;
    }
    else if (resTypeStr.equalsIgnoreCase("entity"))
    {
      resType = Catalog.ENTITY;
      if ((publicId == null) && (systemId == null) && (name == null))
      {
        System.out.println("ENTITY requires name or public or system identifier.");
        usage();
      }
    }
    else if (resTypeStr.equalsIgnoreCase("notation"))
    {
      resType = Catalog.NOTATION;
      if ((publicId == null) && (systemId == null) && (name == null))
      {
        System.out.println("NOTATION requires name or public or system identifier.");
        usage();
      }
    }
    else if (resTypeStr.equalsIgnoreCase("public"))
    {
      resType = Catalog.PUBLIC;
      if (publicId == null)
      {
        System.out.println("PUBLIC requires public identifier.");
        usage();
      }
    }
    else if (resTypeStr.equalsIgnoreCase("system"))
    {
      resType = Catalog.SYSTEM;
      if (systemId == null)
      {
        System.out.println("SYSTEM requires system identifier.");
        usage();
      }
    }
    else if (resTypeStr.equalsIgnoreCase("uri"))
    {
      resType = Catalog.URI;
      if (uri == null)
      {
        System.out.println("URI requires a uri.");
        usage();
      }
    }
    else
    {
      System.out.println(resTypeStr + " is not a recognized keyword.");
      usage();
    }
    if (absoluteSystem)
    {
      URL base = null;
      URL sysid = null;
      try
      {
        base = FileURL.makeURL("basename");
      }
      catch (MalformedURLException e)
      {
        String userdir = System.getProperty("user.dir");
        userdir = userdir.replace('\\', '/');
        debug.message(1, "Malformed URL on cwd", userdir);
        base = null;
      }
      try
      {
        sysid = new URL(base, systemId);
        systemId = sysid.toString();
      }
      catch (MalformedURLException e)
      {
        try
        {
          sysid = new URL("file:///" + systemId);
        }
        catch (MalformedURLException e2)
        {
          debug.message(1, "Malformed URL on system id", systemId);
        }
      }
    }
    CatalogResolver catalogResolver = new CatalogResolver();
    Catalog resolver = catalogResolver.getCatalog();
    for (int count = 0; count < catalogFiles.size(); count++)
    {
      String file = (String)catalogFiles.elementAt(count);
      resolver.parseCatalog(file);
    }
    String result = null;
    if (resType == Catalog.DOCTYPE)
    {
      System.out.println("Resolve DOCTYPE (name, publicid, systemid):");
      if (name != null) {
        System.out.println("       name: " + name);
      }
      if (publicId != null) {
        System.out.println("  public id: " + publicId);
      }
      if (systemId != null) {
        System.out.println("  system id: " + systemId);
      }
      if (uri != null) {
        System.out.println("        uri: " + uri);
      }
      result = resolver.resolveDoctype(name, publicId, systemId);
    }
    else if (resType == Catalog.DOCUMENT)
    {
      System.out.println("Resolve DOCUMENT ():");
      result = resolver.resolveDocument();
    }
    else if (resType == Catalog.ENTITY)
    {
      System.out.println("Resolve ENTITY (name, publicid, systemid):");
      if (name != null) {
        System.out.println("       name: " + name);
      }
      if (publicId != nu
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd