resolver

 public id: " + publicId);
      }
      if (systemId != null) {
        System.out.println("  system id: " + systemId);
      }
      result = resolver.resolveEntity(name, publicId, systemId);
    }
    else if (resType == Catalog.NOTATION)
    {
      System.out.println("Resolve NOTATION (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);
      }
      result = resolver.resolveNotation(name, publicId, systemId);
    }
    else if (resType == Catalog.PUBLIC)
    {
      System.out.println("Resolve PUBLIC (publicid, systemid):");
      if (publicId != null) {
        System.out.println("  public id: " + publicId);
      }
      if (systemId != null) {
        System.out.println("  system id: " + systemId);
      }
      result = resolver.resolvePublic(publicId, systemId);
    }
    else if (resType == Catalog.SYSTEM)
    {
      System.out.println("Resolve SYSTEM (systemid):");
      if (systemId != null) {
        System.out.println("  system id: " + systemId);
      }
      result = resolver.resolveSystem(systemId);
    }
    else if (resType == Catalog.URI)
    {
      System.out.println("Resolve URI (uri):");
      if (uri != null) {
        System.out.println("        uri: " + uri);
      }
      result = resolver.resolveURI(uri);
    }
    else
    {
      System.out.println("resType is wrong!? This can't happen!");
      usage();
    }
    System.out.println("Result: " + result);
  }
  
  public static void usage()
  {
    System.out.println("Usage: resolver [options] keyword");
    System.out.println("");
    System.out.println("Where:");
    System.out.println("");
    System.out.println("-c catalogfile  Loads a particular catalog file.");
    System.out.println("-n name         Sets the name.");
    System.out.println("-p publicId     Sets the public identifier.");
    System.out.println("-s systemId     Sets the system identifier.");
    System.out.println("-a              Makes the system URI absolute before resolution");
    System.out.println("-u uri          Sets the URI.");
    System.out.println("-d integer      Set the debug level.");
    System.out.println("keyword         Identifies the type of resolution to perform:");
    System.out.println("                doctype, document, entity, notation, public, system,");
    System.out.println("                or uri.");
    
    System.exit(1);
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.apps.resolver
 * 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.util.Date;
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.tools.ResolvingParser;
import org.xml.sax.SAXException;

/**
 * @deprecated
 */
public class xparse
{
  private static Debug debug = getStaticManagerdebug;
  
  public static void main(String[] args)
    throws FileNotFoundException, IOException
  {
    String xmlfile = null;
    int debuglevel = 0;
    int maxErrs = 10;
    boolean nsAware = true;
    boolean validating = true;
    boolean showWarnings = debuglevel > 2;
    boolean showErrors = true;
    Vector catalogFiles = new Vector();
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-c"))
      {
        i++;
        catalogFiles.add(args[i]);
      }
      else if (args[i].equals("-w"))
      {
        validating = false;
      }
      else if (args[i].equals("-v"))
      {
        validating = true;
      }
      else if (args[i].equals("-n"))
      {
        nsAware = false;
      }
      else if (args[i].equals("-N"))
      {
        nsAware = true;
      }
      else if (args[i].equals("-d"))
      {
        i++;
        String debugstr = args[i];
        try
        {
          debuglevel = Integer.parseInt(debugstr);
          if (debuglevel >= 0)
          {
            debug.setDebug(debuglevel);
            showWarnings = debuglevel > 2;
          }
        }
        catch (Exception e) {}
      }
      else if (args[i].equals("-E"))
      {
        i++;
        String errstr = args[i];
        try
        {
          int errs = Integer.parseInt(errstr);
          if (errs >= 0) {
            maxErrs = errs;
          }
        }
        catch (Exception e) {}
      }
      else
      {
        xmlfile = args[i];
      }
    }
    if (xmlfile == null)
    {
      System.out.println("Usage: org.apache.xml.resolver.apps.xparse [opts] xmlfile");
      System.exit(1);
    }
    ResolvingParser.validating = validating;
    ResolvingParser.namespaceAware = nsAware;
    ResolvingParser reader = new ResolvingParser();
    Catalog catalog = reader.getCatalog();
    for (int count = 0; count < catalogFiles.size(); count++)
    {
      String file = (String)catalogFiles.elementAt(count);
      catalog.parseCatalog(file);
    }
    XParseError xpe = new XParseError(showErrors, showWarnings);
    xpe.setMaxMessages(maxErrs);
    reader.setErrorHandler(xpe);
    
    String parseType = validating ? "validating" : "well-formed";
    String nsType = nsAware ? "namespace-aware" : "namespace-ignorant";
    if (maxErrs > 0) {
      System.out.println("Attempting " + parseType + ", " + nsType + " parse");
    }
    Date startTime = new Date();
    try
    {
      reader.parse(xmlfile);
    }
    catch (SAXException sx)
    {
      System.out.println("SAX Exception: " + sx);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    Date endTime = new Date();
    
    long millisec = endTime.getTime() - startTime.getTime();
    long secs = 0L;
    long mins = 0L;
    long hours = 0L;
    if (millisec > 1000L)
    {
      secs = millisec / 1000L;
      millisec %= 1000L;
    }
    if (secs > 60L)
    {
      mins = secs / 60L;
      secs %= 60L;
    }
    if (mins > 60L)
    {
      hours = mins / 60L;
      mins %= 60L;
    }
    if (maxErrs > 0)
    {
      System.out.print("Parse ");
      if (xpe.getFatalCount() > 0)
      {
        System.out.print("failed ");
      }
      else
      {
        System.out.print("succeeded ");
        System.out.print("(");
        if (hours > 0L) {
          System.out.print(hours + ":");
        }
        if ((hours > 0L) || (mins > 0L)) {
          System.out.print(mins + ":");
        }
        System.out.print(secs + "." + millisec);
        System.out.print(") ");
      }
      System.out.print("with ");
      
      int errCount = xpe.getErrorCount();
      int warnCount = xpe.getWarningCount();
      if (errCount > 0)
      {
        System.out.print(errCount + " error");
        System.out.print(errCount > 1 ? "s" : "");
        System.out.print(" and ");
      }
      else
      {
        System.out.print("no errors and ");
      }
      if (warnCount > 0)
      {
        System.out.print(warnCount + " warning");
        System.out.print(warnCount > 1 ? "s" : "");
        System.out.print(".");
      }
      else
      {
        System.out.print("no warnings.");
      }
      System.out.println("");
    }
    if (xpe.getErrorCount() > 0) {
      System.exit(1);
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.xml.resolver.apps.xparse
 * 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.util.Date;
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.tools.ResolvingXMLFilter;
import org.apache.xml.resolver.tools.ResolvingXMLReader;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;

public class xread
{
  private static Debug debug = getStaticManagerdebug;
  
  public static void main(String[] args)
    throws FileNotFoundException, IOException
  {
    String xmlfile = null;
    int debuglevel = 0;
    int maxErrs = 10;
    boolean nsAware = true;
    boolean validating = true;
    boolean useSchema = false;
    boolean showWarnings = debuglevel > 2;
    boolean showErrors = true;
    Vector catalogFiles = new Vector();
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-c"))
      {
        i++;
        catalogFiles.add(args[i]);
      }
      else if (args[i].equals("-w"))
      {
        validating = false;
      }
      else if (args[i].equals("-v"))
      {
        validating = true;
      }
      else if (args[i].equals("-s"))
      {
        useSchema = true;
      }
      else if (args[i].equals("-n"))
      {
        nsAware = false;
      }
      else if (args[i].equals("-N"))
      {
        nsAware = true;
      }
      else if (args[i].equals("-d"))
      {
        i++;
        String debugstr = args[i];
        try
        {
          debuglevel = Integer.parseInt(debugstr);
          if (debuglevel >= 0)
          {
            debug.setDebug(debuglevel);
            showWarnings = debuglevel > 2;
          }
        }
        catch (Exception e) {}
      }
      else if (args[i].equals("-E"))
      {
        i++;
        String errstr = args[i];
        try
        {
          int errs = Integer.parseInt(errstr);
          if (errs >= 0) {
            maxErrs = errs;
          }
        }
        catch (Exception e) {}
      }
      else
      {
        xmlfile = args[i];
      }
    }
    if (xmlfile == null)
    {
      System.out.println("Usage: org.apache.xml.resolver.apps.xread [opts] xmlfile");
      System.exit(1);
    }
    ResolvingXMLReader reader = new ResolvingXMLReader();
    try
    {
      reader.setFeature("http://xml.org/sax/features/namespaces", nsAware);
      reader.setFeature("http://xml.org/sax/features/validation", validating);
      if (useSchema) {
        reader.setFeature("http://apache.org/xml/features/validation/schema", true);
      }
    }
    catch (SAXException e) {}
    Catalog catalog = reader.getCatalog();
    for (int count = 0; count < catalogFiles.size(); count++)
    {
      String file = (String)catalogFiles.elementAt(count);
      catalog.parseCatalog(file);
    }
    XParseError xpe = new XParseError(showErrors, showWarnings);
    xpe.setMaxMessages(maxErrs);
    reader.setErrorHandler(xpe);
    
    String parseType = validating ? "validating" : "well-formed";
    String nsType = nsAware ? "namespace-aware" : "namespace-ignorant";
    if (maxErrs > 0) {
      System.out.println("Attempting " + parseType + ", " + nsType + " parse");
    }
    Date startTime = new Date();
    try
    {
      reader.parse(xmlfile);
    }
    catch (SAXException sx)
    {
      System.out.println("SAX Exception: " + sx);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    Date endTime = new Date();
    
    long millisec = endTime.getTime() - startTime.getTime();
    long secs = 0L;
    long mins = 0L;
    long hours = 0L;
    if (millisec > 1000L)
    {
      secs = millisec / 1000L;
      millisec %= 1000L;
    }
    if (secs > 60L)
    {
      mins = secs / 60L;
      secs %= 60L;
    }
    if (mins > 60L)
    {
      hours = mins / 60L;
      mins %= 60L;
    }
    if (maxErrs > 0)
    {
      System.out.print("Parse ");
      if (xpe.getFatalCount() > 0)
      {
        System.out.print("failed ");
      }
      else
      {
        System.out.print("succeeded ");
        System.out.print("(");
        if (hours > 0L) {
          System.out.print(hours + ":");
        }
        if ((hours > 0L) || (mins > 0L)) {
          System.out.print(mins + ":");
        }
        System.out.print(secs + "." + millisec);
        System.out.print(") ");
      }
      System.out.print("with ");
      
      int errCount = xpe.getErrorCount();
      int warnCount = xpe.getWarningCount();
      if (errCount > 0)
      {
        System.out.print(errCount + " error");
        System.out.print(errCount > 1 ? "s" : "");
        System.out.print(" and ");
      }
      else
      {
        System.out.print("no errors and ");
      }
      if (warnCount > 0)
      {
        System.out.print(warnCount + " warning");
        System.out.print(warnCount > 1 ? "s" : "");
        System.out.print(".");
      }
      else
      {
        System.out.print("no warnings.");
      }
      System.out.println("");
    }
    if (xpe.getErrorCount() > 0) {
      System.exit(1);
    }
  }
}

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

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;

public class BootstrapResolver
  implements EntityResolver, URIResolver
{
  public static final String xmlCatalogXSD = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.xsd";
  public static final String xmlCatalogRNG = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.rng";
  public static final String xmlCatalogPubId = "-//OASIS//DTD XML Catalogs V1.0//EN";
  public static final String xmlCatalogSysId = "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd";
  public static final String xCatalogPubId = "-//DTD XCatalog//EN";
  private Hashtable publicMap = new Hashtable();
  private Hashtable systemMap = new Hashtable();
  private Hashtable uriMap = new Hashtable();
  
  public BootstrapResolver()
  {
    URL url = getClass().getResource("/org/apache/xml/resolver/etc/catalog.dtd");
    if (url != null)
    {
      publicMap.put("-//OASIS//DTD XML Catalogs V1.0//EN", url.toString());
      systemMap.put("http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd", url.toString());
    }
    url = getClass().getResource("/org/apache/xml/resolver/etc/catalog.rng");
    if (url != null) {
      uriMap.put("http://www.oasis-open.org/committees/entity/release/1.0/catalog.rng", url.toString());
    }
    url = getClass().getResource("/org/apache/xml/resolver/etc/catalog.xsd");
    if (url != null) {
      uriMap.put("http://www.oasis-open.org/committees/entity/release/1.0/catalog.xsd", url.toString());
    }
    url = getClass().getResource("/org/apache/xml/resolver/etc/xcatalog.dtd");
    if (url != null) {
      publicMap.put("-//DTD XCatalog//EN", url.toString());
    }
  }
  
  public InputSource resolveEntity(String publicId, String systemId)
  {
    String resolved = null;
    if ((systemId != null) && (systemMap.containsKey(systemId))) {
      resolved = (String)systemMap.get(systemId);
    } else if ((publicId != null) && (publicMap.containsKey(publicId))) {
      resolved = (String)publicMap.get(publicId);
    }
    if (resolved != null) {
      try
      {
        InputSource iSource = new InputSource(resolved);
        iSource.setPublicId(publicId);
        
        URL url = new URL(resolved);
        InputStream iStream = url.openStream();
        iSource.setByteStream(iStream);
        
        return iSource;
      }
      catch (Exception e)
      {
        return null;
      }
    }
    return null;
  }
  
  public Source resolve(String href, String base)
    throws TransformerException
  {
    String uri = href;
    String fragment = null;
    int hashPos = href.indexOf("#");
    if (hashPos >= 0)
    {
      uri = href.substring(0, hashPos);
      fragment = href.substring(hashPos + 1);
    }
    String result = null;
    if ((href != null) && (uriMap.containsKey(href))) {
      result = (String)uriMap.get(href);
    }
    if (result == null) {
      try
      {
        URL url = null;
        if (base == null)
        {
          url = new URL(uri);
          result = url.toString();
        }
        else
        {
          URL baseURL = new URL(base);
          url = href.length() == 0 ? baseURL : new URL(baseURL, uri);
          result = url.toString();
        }
      }
      catch (MalformedURLException mue)
      {
        String absBase = makeAbsolute(base);
        if (!absBase.equals(base)) {
          return resolve(href, absBase);
        }
        throw new TransformerException("Malformed URL " + href + "(base " + base + ")", mue);
      }
    }
    SAXSource source = new SAXSource();
    source.setInputSource(new InputSource(result));
    return source;
  }
  
  private String makeAbsolute(String uri)
  {
    if (uri == null) {
      uri = "";
    }
    try
    {
      URL url = new URL(uri);
      return url.toString();
    }
    catch (MalformedURLException mue)
    {
      try
      {
        URL fileURL = FileURL.makeURL(uri);
        return fileURL.toString();
      }
      catch (MalformedURLException mue2) {}
    }
    return uri;
  }
}

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

import java.io.PrintStream;

public class Debug
{
  protected int debug = 0;
  
  public void setDebug(int newDebug)
  {
    debug = newDebug;
  }
  
  public int getDebug()
  {
    return debug;
  }
  
  public void message(int level, String message)
  {
    if (debug >= level) {
      System.out.println(message);
    }
  }
  
  public void message(int level, String message, String spec)
  {
    if (debug >= level) {
      System.out.println(message + ": " + spec);
    }
  }
  
  public void message(int level, String message, String spec1, String spec2)
  {
    if (debug >= level)
    {
      System.out.println(message + ": " + spec1);
      System.out.println("\t" + spec2);
    }
  }
}

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

import java.net.MalformedURLException;
import java.net.URL;

public abstract class FileURL
{
  public static URL makeURL(String pathname)
    throws MalformedURLException
  {
    if (pathname.startsWith("/")) {
      return new URL("file://" + pathname);
    }
    String userdir = System.getProperty("user.dir");
    userdir = userdir.replace('\\', '/');
    if (userdir.endsWith("/")) {
      return new URL("file:///" + userdir + pathname);
    }
    return new URL("file:///" + userdir + "/" + pathname);
  }
}

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

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Namespaces
{
  public static String getPrefix(Element element)
  {
    String name = element.getTagName();
    String prefix = "";
    if (name.indexOf(':') > 0) {
      prefix = name.substring(0, name.indexOf(':'));
    }
    return prefix;
  }
  
  public static String getLocalName(Element element)
  {
    String name = element.getTagName();
    if (name.indexOf(':') > 0) {
      name = name.substring(name.indexOf(':') + 1);
    }
    return name;
  }
  
  public static String getNamespaceURI(Node node, String prefix)
  {
    if ((node == null) || (node.getNodeType() != 1)) {
      return null;
    }
    if (prefix.equals(""))
    {
      if (((Element)node).hasAttribute("xmlns")) {
        return ((Element)node).getAttribute("xmlns");
      }
    }
    else
    {
      String nsattr = "xmlns:" + prefix;
      if (((Element)node).hasAttribute(nsattr)) {
        return ((Element)node).getAttribute(nsattr);
      }
    }
    return getNamespaceURI(node.getParentNode(), prefix);
  }
  
  public static String getNamespaceURI(Element element)
  {
    String prefix = getPrefix(element);
    return getNamespaceURI(element, prefix);
  }
}

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

public abstract class PublicId
{
  public static String normalize(String publicId)
  {
    String normal = publicId.replace('\t', ' ');
    normal = normal.replace('\r', ' ');
    normal = normal.replace('\n', ' ');
    normal = normal.trim();
    int pos;
    while ((pos = normal.indexOf("  ")) >= 0)
    {
      int i;
      normal = normal.substring(0, i) + normal.substring(i + 1);
    }
    return normal;
  }
  
  public static String encodeURN(String publicId)
  {
    String urn = normalize(publicId);
    
    urn = stringReplace(urn, "%", "%25");
    urn = stringReplace(urn, ";", "%3B");
    urn = stringReplace(urn, "'", "%27");
    urn = stringReplace(urn, "?", "%3F");
    urn = stringReplace(urn, "#", "%23");
    urn = stringReplace(urn, "+", "%2B");
    urn = stringReplace(urn, " ", "+");
    urn = stringReplace(urn, "::", ";");
    urn = stringReplace(urn, ":", "%3A");
    urn = stringReplace(urn, "//", ":");
    urn = stringReplace(urn, "/", "%2F");
    
    return "urn:publicid:" + urn;
  }
  
  public static String decodeURN(String urn)
  {
    String publicId = "";
    if (urn.startsWith("urn:publicid:")) {
      publicId = urn.substring(13);
    } else {
      return urn;
    }
    publicId = stringReplace(publicId, "%2F", "/");
    publicId = stringReplace(publicId, ":", "//");
    publicId = stringReplace(publicId, "%3A", ":");
    publicId = stringReplace(publicId, ";", "::");
    publicId = stringReplace(publicId, "+", " ");
    publicId = stringReplace(publicId, "%2B", "+");
    publicId = stringReplace(publicId, "%23", "#");
    publicId = stringReplace(publicId, "%3F", "?");
    publicId = stringReplace(publicId, "%27", "'");
    publicId = stringReplace(publicId, "%3B", ";");
    publicId = stringReplace(publicId, "%25", "%");
    
    return publicId;
  }
  
  private static String stringReplace(String str, String oldStr, String newStr)
  {
    String result = "";
    int pos = str.indexOf(oldStr);
    while (pos >= 0)
    {
      result = result + str.substring(0, pos);
      result = result + newStr;
      str = str.substring(pos + 1);
      
      pos = str.indexOf(oldStr);
    }
    return result + str;
  }
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogException;

public abstract interface CatalogReader
{
  public abstract void readCatalog(Catalog paramCatalog, String paramString)
    throws MalformedURLException, IOException, CatalogException;
  
  public abstract void readCatalog(Catalog paramCatalog, InputStream paramInputStream)
    throws IOException, CatalogException;
}

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

import org.apache.xml.resolver.Catalog;
import org.w3c.dom.Node;

public abstract interface DOMCatalogParser
{
  public abstract void parseCatalogEntry(Catalog paramCatalog, Node paramNode);
}

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

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Hashtable;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogException;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.helpers.Debug;
import org.apache.xml.resolver.helpers.Namespaces;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

public class DOMCatalogReader
  implements CatalogReader
{
  protected Hashtable namespaceMap = new Hashtable();
  
  public void setCatalogParser(String namespaceURI, String rootElement, String parserClass)
  {
    if (namespaceURI == null) {
      namespaceMap.put(rootElement, parserClass);
    } else {
      namespaceMap.put("{" + namespaceURI + "}" + rootElement, parserClass);
    }
  }
  
  public String getCatalogParser(String namespaceURI, String rootElement)
  {
    if (namespaceURI == null) {
      return (String)namespaceMap.get(rootElement);
    }
    return (String)namespaceMap.get("{" + namespaceURI + "}" + rootElement);
  }
  
  public void readCatalog(Catalog catalog, InputStream is)
    throws IOException, CatalogException
  {
    DocumentBuilderFactory factory = null;
    DocumentBuilder builder = null;
    
    factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(false);
    factory.setValidating(false);
    try
    {
      builder = factory.newDocumentBuilder();
    }
    catch (ParserConfigurationException pce)
    {
      throw new CatalogException(6);
    }
    Document doc = null;
    try
    {
      doc = builder.parse(is);
    }
    catch (SAXException se)
    {
      throw new CatalogException(5);
    }
    Element root = doc.getDocumentElement();
    
    String namespaceURI = Namespaces.getNamespaceURI(root);
    String localName = Namespaces.getLocalName(root);
    
    String domParserClass = getCatalogParser(namespaceURI, localName);
    if (domParserClass == null)
    {
      if (namespaceURI == null) {
        getCatalogManagerdebug.message(1, "No Catalog parser for " + localName);
      } else {
        getCatalogManagerdebug.message(1, "No Catalog parser for {" + namespaceURI + "}" + localName);
      }
      return;
    }
    DOMCatalogParser domParser = null;
    try
    {
      domParser = (DOMCatalogParser)Class.forName(domParserClass).newInstance();
    }
    catch (ClassNotFoundException cnfe)
    {
      getCatalogManagerdebug.message(1, "Cannot load XML Catalog Parser class", domParserClass);
      throw new CatalogException(6);
    }
    catch (InstantiationException ie)
    {
      getCatalogManagerdebug.message(1, "Cannot instantiate XML Catalog Parser class", domParserClass);
      throw new CatalogException(6);
    }
    catch (IllegalAccessException iae)
    {
      getCatalogManagerdebug.message(1, "Cannot access XML Catalog Parser class", domParserClass);
      throw new CatalogException(6);
    }
    catch (ClassCastException cce)
    {
      getCatalogManagerdebug.message(1, "Cannot cast XML Catalog Parser class", domParserClass);
      throw new CatalogException(6);
    }
    Node node = root.getFirstChild();
    while (node != null)
    {
      domParser.parseCatalogEntry(catalog, node);
      node = node.getNextSibling();
    }
  }
  
  public void readCatalog(Catalog catalog, String fileUrl)
    throws MalformedURLException, IOException, CatalogException
  {
    URL url = new URL(fileUrl);
    URLConnection urlCon = url.openConnection();
    readCatalog(catalog, urlCon.getInputStream());
  }
}

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

import java.util.Stack;
import java.util.Vector;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogEntry;
import org.apache.xml.resolver.CatalogException;
import org.apache.xml.resolver.Resolver;
import org.apache.xml.resolver.helpers.Debug;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

public class ExtendedXMLCatalogReader
  extends OASISXMLCatalogReader
{
  public static final String extendedNamespaceName = "http://nwalsh.com/xcatalog/1.0";
  
  public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
    throws SAXException
  {
    boolean inExtension = inExtensionNamespace();
    
    super.startElement(namespaceURI, localName, qName, atts);
    
    int entryType = -1;
    Vector entryArgs = new Vector();
    if ((namespaceURI != null) && ("http://nwalsh.com/xcatalog/1.0".equals(namespaceURI)) && (!inExtension))
    {
      if (atts.getValue("xml:base") != null)
      {
        String baseURI = atts.getValue("xml:base");
        entryType = Catalog.BASE;
        entryArgs.add(baseURI);
        baseURIStack.push(baseURI);
        
        debug.message(4, "xml:base", baseURI);
        try
        {
          CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
          catalog.addEntry(ce);
        }
        catch (CatalogException cex)
        {
          if (cex.getExceptionType() == 3) {
            debug.message(1, "Invalid catalog entry type", localName);
          } else if (cex.getExceptionType() == 2) {
            debug.message(1, "Invalid catalog entry (base)", localName);
          }
        }
        entryType = -1;
        entryArgs = new Vector();
      }
      else
      {
        baseURIStack.push(baseURIStack.peek());
      }
      if (localName.equals("uriSuffix"))
      {
        if (checkAttributes(atts, "suffix", "uri"))
        {
          entryType = Resolver.URISUFFIX;
          entryArgs.add(atts.getValue("suffix"));
          entryArgs.add(atts.getValue("uri"));
          
          debug.message(4, "uriSuffix", atts.getValue("suffix"), atts.getValue("uri"));
        }
      }
      else if (localName.equals("systemSuffix"))
      {
        if (checkAttributes(atts, "suffix", "uri"))
        {
          entryType = Resolver.SYSTEMSUFFIX;
          entryArgs.add(atts.getValue("suffix"));
          entryArgs.add(atts.getValue("uri"));
          
          debug.message(4, "systemSuffix", atts.getValue("suffix"), atts.getValue("uri"));
        }
      }
      else {
        debug.message(1, "Invalid catalog entry type", localName);
      }
      if (entryType >= 0) {
        try
        {
          CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
          catalog.addEntry(ce);
        }
        catch (CatalogException cex)
        {
          if (cex.getExceptionType() == 3) {
            debug.message(1, "Invalid catalog entry type", localName);
          } else if (cex.getExceptionType() == 2) {
            debug.message(1, "Invalid catalog entry", localName);
          }
        }
      }
    }
  }
  
  public void endElement(String namespaceURI, String localName, String qName)
    throws SAXException
  {
    super.endElement(namespaceURI, localName, qName);
    
    boolean inExtension = inExtensionNamespace();
    
    int entryType = -1;
    Vector entryArgs = new Vector();
    if ((namespaceURI != null) && ("http://nwalsh.com/xcatalog/1.0".equals(namespaceURI)) && (!inExtension))
    {
      String popURI = (String)baseURIStack.pop();
      String baseURI = (String)baseURIStack.peek();
      if (!baseURI.equals(popURI))
      {
        entryType = Catalog.BASE;
        entryArgs.add(baseURI);
        
        debug.message(4, "(reset) xml:base", baseURI);
        try
        {
          CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
          catalog.addEntry(ce);
        }
        catch (CatalogException cex)
        {
          if (cex.getExceptionType() == 3) {
            debug.message(1, "Invalid catalog entry type", localName);
          } else if (cex.getExceptionType() == 2) {
            debug.message(1, "Invalid catalog entry (rbase)", localName);
          }
        }
      }
    }
  }
}

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

import java.util.Enumeration;
import java.util.Stack;
import java.util.Vector;
import javax.xml.parsers.SAXParserFactory;
import org.apache.xml.resolver.Catalog;
import org.apache.xml.resolver.CatalogEntry;
import org.apache.xml.resolver.CatalogException;
import org.apache.xml.resolver.CatalogManager;
import org.apache.xml.resolver.helpers.Debug;
import org.apache.xml.resolver.helpers.PublicId;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;

public class OASISXMLCatalogReader
  extends SAXCatalogReader
  implements SAXCatalogParser
{
  protected Catalog catalog = null;
  public static final String namespaceName = "urn:oasis:names:tc:entity:xmlns:xml:catalog";
  public static final String tr9401NamespaceName = "urn:oasis:names:tc:entity:xmlns:tr9401:catalog";
  protected Stack baseURIStack = new Stack();
  protected Stack overrideStack = new Stack();
  protected Stack namespaceStack = new Stack();
  
  public void setCatalog(Catalog catalog)
  {
    this.catalog = catalog;
    debug = getCatalogManagerdebug;
  }
  
  public Catalog getCatalog()
  {
    return catalog;
  }
  
  public OASISXMLCatalogReader() {}
  
  public OASISXMLCatalogReader(SAXParserFactory parserFactory, Catalog catalog)
  {
    super(parserFactory);
    setCatalog(catalog);
  }
  
  protected boolean inExtensionNamespace()
  {
    boolean inExtension = false;
    
    Enumeration elements = namespaceStack.elements();
    while ((!inExtension) && (elements.hasMoreElements()))
    {
      String ns = (String)elements.nextElement();
      if (ns == null) {
        inExtension = true;
      } else {
        inExtension = (!ns.equals("urn:oasis:names:tc:entity:xmlns:tr9401:catalog")) && (!ns.equals("urn:oasis:names:tc:entity:xmlns:xml:catalog"));
      }
    }
    return inExtension;
  }
  
  public void setDocumentLocator(Locator locator) {}
  
  public void startDocument()
    throws SAXException
  {
    baseURIStack.push(catalog.getCurrentBase());
    overrideStack.push(catalog.getDefaultOverride());
  }
  
  public void endDocument()
    throws SAXException
  {}
  
  public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
    throws SAXException
  {
    int entryType = -1;
    Vector entryArgs = new Vector();
    
    namespaceStack.push(namespaceURI);
    
    boolean inExtension = inExtensionNamespace();
    if ((namespaceURI != null) && ("urn:oasis:names:tc:entity:xmlns:xml:catalog".equals(namespaceURI)) && (!inExtension))
    {
      if (atts.getValue("xml:base") != null)
      {
        String baseURI = atts.getValue("xml:base");
        entryType = Catalog.BASE;
        entryArgs.add(baseURI);
        baseURIStack.push(baseURI);
        
        debug.message(4, "xml:base", baseURI);
        try
        {
          CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
          catalog.addEntry(ce);
        }
        catch (CatalogException cex)
        {
          if (cex.getExceptionType() == 3) {
            debug.message(1, "Invalid catalog entry type", localName);
          } else if (cex.getExceptionType() == 2) {
            debug.message(1, "Invalid catalog entry (base)", localName);
          }
        }
        entryType = -1;
        entryArgs = new Vector();
      }
      else
      {
        baseURIStack.push(baseURIStack.peek());
      }
      if (((localName.equals("catalog")) || (localName.equals("group"))) && (atts.getValue("prefer") != null))
      {
        String override = atts.getValue("prefer");
        if (override.equals("public"))
        {
          override = "yes";
        }
        else if (override.equals("system"))
        {
          override = "no";
        }
        else
        {
          debug.message(1, "Invalid prefer: must be 'system' or 'public'", localName);
          
          override = catalog.getDefaultOverride();
        }
        entryType = Catalog.OVERRIDE;
        entryArgs.add(override);
        overrideStack.push(override);
        
        debug.message(4, "override", override);
        try
        {
          CatalogEntry ce = new CatalogEntry(entryType, entryArgs);
          catalog.addEntry(ce);
        }
        catch (CatalogException cex)
        {
          if (cex.getExceptionType() == 3) {
            debug.message(1, "Invalid catalog entry type", localName);
          } else if (cex.getExceptionType() == 2) {
            debug.message(1, "Invalid catalog entry (override)", localName);
          }
        }
        entryType = -1;
        entryArgs = new Vector();
      }
      else
      {
        overrideStack.push(overrideStack.peek());
      }
      if (localName.equals("delegatePublic"))
      {
        if (checkAttributes(atts, "publicIdStartString", "catalog"))
        {
          entryType = Catalog.DELEGATE_PUBLIC;
          entryArgs.add(atts.getValue("publicIdStartString"));
          entryArgs.add(atts.getValue("catalog"));
          
          debug.message(4, "delegatePublic", PublicId.normalize(atts.getValue("publicIdStartString")), atts.getValue("catalog"));
        }
      }
      else if (localName.equals("delegateSystem"))
      {
        if (checkAttributes(atts, "systemIdStartString", "catalog"))
        {
          entryType = Catalog.DELEGATE_SYSTEM;
          entryArgs.add(atts.getValue("systemIdStartString"));
          entryArgs.add(atts.getValue("catalog"));
          
          debug.message(4, "delegateSystem", atts.getValue("systemIdStartString"), atts.getValue("catalog"));
        }
      }
      else if (localName.equals("delegateURI"))
      {
        if (checkAttributes(atts, "uriStartString", "catalog"))
        {
          entryType = Catalog.DELEGATE_URI;
          entryArgs.add(atts.getValue("uriStartString"));
          entryArgs.add(atts.getValue("catalog"));
          
          debug.message(4, "delegateURI", atts.getValue("uriStartString"), atts.getValue("catalog"));
        }
      }
      else if (localName.equals("rewriteSystem"))
      {
        if (checkAttributes(atts, "systemIdStartString", "rewritePrefix"))
        {
          entryType = Catalog.REWRITE_SYSTEM;
          entryArgs.add(atts.getValue("systemIdStartString"));
          entryArgs.add(atts.getValue("rewritePrefix"));
          
          debug.message(4, "rewriteSystem", atts.getValue("systemIdStartString"), atts.getValue("rewritePrefix"));
        }
      }
      else if (localName.equals("systemSuffix"))
      {
        if (checkAttributes(atts, "systemIdSuffix", "uri"))
        {
          entryType = Catalog.SYSTEM_SUFFIX;
          entryArgs.add(atts.getValue("systemIdSuffix"));
          entryArgs.add(atts.getValue("uri"));
          
          debug.message(4, "systemSuffix", atts.getValue("systemIdSuffix"), atts.getValue("uri"));
        }
      }
      else if (localName.equals("rewriteURI"))
      {
        if (checkAttributes(atts, "uriStartString", "rewritePrefix"))
        {
          entryType = Catalog.REWRITE_URI;
          entryArgs.add(atts.getValue("uriStartString"));
          entryArgs.add(atts.getValue("rewritePrefix"));
          
          debug.message(4, "rewriteURI", atts.getValue("uriStartString"), atts.getValue("rewritePrefix"));
        }
      }
      else if (localName.equals("uriSuffix"))
      {
        if (checkAttributes(atts, "uriSuffix", "uri"))
        {
          entryType = Catalog.URI_SUFFIX;
          entryArgs.add(atts.getValue("uriSuffix"));
          entryArgs.add(atts.getValue("uri"));
          
          debug.message(4, "uriSuffix", atts.getValue("uriSuffix"), atts.getValue("uri"));
        }
      }
      else if (localN
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-2017. Infinite Loop Ltd