You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by il...@apache.org on 2002/09/17 16:56:03 UTC

cvs commit: xml-commons/java/external/src/org/xml/sax/helpers ParserFactory.java ParserAdapter.java XMLReaderFactory.java NewInstance.java

ilene       2002/09/17 07:56:03

  Modified:    java/external/src/org/xml/sax/helpers Tag: RIVERCOURT1
                        ParserFactory.java ParserAdapter.java
                        XMLReaderFactory.java NewInstance.java
  Log:
  Update JAXP FactoryFinder code to correspond with HEAD and with code
  in Xerces' xmlParserAPIs.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.2.2.2   +20 -20    xml-commons/java/external/src/org/xml/sax/helpers/ParserFactory.java
  
  Index: ParserFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/org/xml/sax/helpers/ParserFactory.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- ParserFactory.java	10 May 2002 20:42:39 -0000	1.2.2.1
  +++ ParserFactory.java	17 Sep 2002 14:56:02 -0000	1.2.2.2
  @@ -79,18 +79,19 @@
        * @see org.xml.sax.Parser
        */
       public static Parser makeParser ()
  -	throws ClassNotFoundException,
  -	IllegalAccessException, 
  -	InstantiationException,
  -	NullPointerException,
  -	ClassCastException
  +    throws ClassNotFoundException,
  +    IllegalAccessException, 
  +    InstantiationException,
  +    NullPointerException,
  +    ClassCastException
       {
  -	String className = System.getProperty("org.xml.sax.parser");
  -	if (className == null) {
  -	    throw new NullPointerException("No value for sax.parser property");
  -	} else {
  -	    return makeParser(className);
  -	}
  +    SecuritySupport ss = SecuritySupport.getInstance();
  +    String className = ss.getSystemProperty("org.xml.sax.parser");
  +    if (className == null) {
  +        throw new NullPointerException("No value for sax.parser property");
  +    } else {
  +        return makeParser(className);
  +    }
       }
       
       
  @@ -116,14 +117,13 @@
        * @see org.xml.sax.Parser
        */
       public static Parser makeParser (String className)
  -	throws ClassNotFoundException,
  -	IllegalAccessException, 
  -	InstantiationException,
  -	ClassCastException
  +    throws ClassNotFoundException,
  +    IllegalAccessException, 
  +    InstantiationException,
  +    ClassCastException
       {
  -	return (Parser) NewInstance.newInstance (
  -		NewInstance.getClassLoader (), className);
  +    return (Parser) NewInstance.newInstance (
  +        NewInstance.getClassLoader (), className);
       }
       
  -}
  -
  +}
  \ No newline at end of file
  
  
  
  1.3.2.2   +459 -458  xml-commons/java/external/src/org/xml/sax/helpers/ParserAdapter.java
  
  Index: ParserAdapter.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/org/xml/sax/helpers/ParserAdapter.java,v
  retrieving revision 1.3.2.1
  retrieving revision 1.3.2.2
  diff -u -r1.3.2.1 -r1.3.2.2
  --- ParserAdapter.java	10 May 2002 20:42:39 -0000	1.3.2.1
  +++ ParserAdapter.java	17 Sep 2002 14:56:02 -0000	1.3.2.2
  @@ -9,7 +9,7 @@
   import java.io.IOException;
   import java.util.Enumeration;
   
  -import org.xml.sax.Parser;	// deprecated
  +import org.xml.sax.Parser;  // deprecated
   import org.xml.sax.InputSource;
   import org.xml.sax.Locator;
   import org.xml.sax.AttributeList; // deprecated
  @@ -74,35 +74,36 @@
       public ParserAdapter ()
         throws SAXException
       {
  -	super();
  +    super();
   
  -	String driver = System.getProperty("org.xml.sax.parser");
  +    SecuritySupport ss = SecuritySupport.getInstance();
  +    String driver = ss.getSystemProperty("org.xml.sax.parser");
   
  -	try {
  -	    setup(ParserFactory.makeParser());
  -	} catch (ClassNotFoundException e1) {
  -	    throw new
  -		SAXException("Cannot find SAX1 driver class " +
  -			     driver, e1);
  -	} catch (IllegalAccessException e2) {
  -	    throw new
  -		SAXException("SAX1 driver class " +
  -			     driver +
  -			     " found but cannot be loaded", e2);
  -	} catch (InstantiationException e3) {
  -	    throw new
  -		SAXException("SAX1 driver class " +
  -			     driver +
  -			     " loaded but cannot be instantiated", e3);
  -	} catch (ClassCastException e4) {
  -	    throw new
  -		SAXException("SAX1 driver class " +
  -			     driver +
  -			     " does not implement org.xml.sax.Parser");
  -	} catch (NullPointerException e5) {
  -	    throw new 
  -		SAXException("System property org.xml.sax.parser not specified");
  -	}
  +    try {
  +        setup(ParserFactory.makeParser());
  +    } catch (ClassNotFoundException e1) {
  +        throw new
  +        SAXException("Cannot find SAX1 driver class " +
  +                 driver, e1);
  +    } catch (IllegalAccessException e2) {
  +        throw new
  +        SAXException("SAX1 driver class " +
  +                 driver +
  +                 " found but cannot be loaded", e2);
  +    } catch (InstantiationException e3) {
  +        throw new
  +        SAXException("SAX1 driver class " +
  +                 driver +
  +                 " loaded but cannot be instantiated", e3);
  +    } catch (ClassCastException e4) {
  +        throw new
  +        SAXException("SAX1 driver class " +
  +                 driver +
  +                 " does not implement org.xml.sax.Parser");
  +    } catch (NullPointerException e5) {
  +        throw new 
  +        SAXException("System property org.xml.sax.parser not specified");
  +    }
       }
   
   
  @@ -119,8 +120,8 @@
        */
       public ParserAdapter (Parser parser)
       {
  -	super();
  -	setup(parser);
  +    super();
  +    setup(parser);
       }
   
   
  @@ -133,14 +134,14 @@
        */
       private void setup (Parser parser)
       {
  -	if (parser == null) {
  -	    throw new
  -		NullPointerException("Parser argument must not be null");
  -	}
  -	this.parser = parser;
  -	atts = new AttributesImpl();
  -	nsSupport = new NamespaceSupport();
  -	attAdapter = new AttributeListAdapter();
  +    if (parser == null) {
  +        throw new
  +        NullPointerException("Parser argument must not be null");
  +    }
  +    this.parser = parser;
  +    atts = new AttributesImpl();
  +    nsSupport = new NamespaceSupport();
  +    attAdapter = new AttributeListAdapter();
       }
   
   
  @@ -158,9 +159,9 @@
       private final static String NAMESPACE_PREFIXES = FEATURES + "namespace-prefixes";
       private final static String VALIDATION = FEATURES + "validation";
       private final static String EXTERNAL_GENERAL =
  -	FEATURES + "external-general-entities";
  +    FEATURES + "external-general-entities";
       private final static String EXTERNAL_PARAMETER =
  -	FEATURES + "external-parameter-entities";
  +    FEATURES + "external-parameter-entities";
   
   
       /**
  @@ -178,27 +179,27 @@
        * @see org.xml.sax.XMLReader#setFeature
        */
       public void setFeature (String name, boolean state)
  -	throws SAXNotRecognizedException, SAXNotSupportedException
  +    throws SAXNotRecognizedException, SAXNotSupportedException
       {
  -	if (name.equals(NAMESPACES)) {
  -	    checkNotParsing("feature", name);
  -	    namespaces = state;
  -	    if (!namespaces && !prefixes) {
  -		prefixes = true;
  -	    }
  -	} else if (name.equals(NAMESPACE_PREFIXES)) {
  -	    checkNotParsing("feature", name);
  -	    prefixes = state;
  -	    if (!prefixes && !namespaces) {
  -		namespaces = true;
  -	    }
  -	} else if (name.equals(VALIDATION) ||
  -		   name.equals(EXTERNAL_GENERAL) ||
  -		   name.equals(EXTERNAL_PARAMETER)) {
  -	    throw new SAXNotSupportedException("Feature: " + name);
  -	} else {
  -	    throw new SAXNotRecognizedException("Feature: " + name);
  -	}
  +    if (name.equals(NAMESPACES)) {
  +        checkNotParsing("feature", name);
  +        namespaces = state;
  +        if (!namespaces && !prefixes) {
  +        prefixes = true;
  +        }
  +    } else if (name.equals(NAMESPACE_PREFIXES)) {
  +        checkNotParsing("feature", name);
  +        prefixes = state;
  +        if (!prefixes && !namespaces) {
  +        namespaces = true;
  +        }
  +    } else if (name.equals(VALIDATION) ||
  +           name.equals(EXTERNAL_GENERAL) ||
  +           name.equals(EXTERNAL_PARAMETER)) {
  +        throw new SAXNotSupportedException("Feature: " + name);
  +    } else {
  +        throw new SAXNotRecognizedException("Feature: " + name);
  +    }
       }
   
   
  @@ -217,19 +218,19 @@
        * @see org.xml.sax.XMLReader#setFeature
        */
       public boolean getFeature (String name)
  -	throws SAXNotRecognizedException, SAXNotSupportedException
  +    throws SAXNotRecognizedException, SAXNotSupportedException
       {
  -	if (name.equals(NAMESPACES)) {
  -	    return namespaces;
  -	} else if (name.equals(NAMESPACE_PREFIXES)) {
  -	    return prefixes;
  -	} else if (name.equals(VALIDATION) ||
  -		   name.equals(EXTERNAL_GENERAL) ||
  -		   name.equals(EXTERNAL_PARAMETER)) {
  -	    throw new SAXNotSupportedException("Feature: " + name);
  -	} else {
  -	    throw new SAXNotRecognizedException("Feature: " + name);
  -	}
  +    if (name.equals(NAMESPACES)) {
  +        return namespaces;
  +    } else if (name.equals(NAMESPACE_PREFIXES)) {
  +        return prefixes;
  +    } else if (name.equals(VALIDATION) ||
  +           name.equals(EXTERNAL_GENERAL) ||
  +           name.equals(EXTERNAL_PARAMETER)) {
  +        throw new SAXNotSupportedException("Feature: " + name);
  +    } else {
  +        throw new SAXNotRecognizedException("Feature: " + name);
  +    }
       }
   
   
  @@ -247,9 +248,9 @@
        * @see org.xml.sax.XMLReader#setProperty
        */
       public void setProperty (String name, Object value)
  -	throws SAXNotRecognizedException, SAXNotSupportedException
  +    throws SAXNotRecognizedException, SAXNotSupportedException
       {
  -	throw new SAXNotRecognizedException("Property: " + name);
  +    throw new SAXNotRecognizedException("Property: " + name);
       }
   
   
  @@ -267,9 +268,9 @@
        * @see org.xml.sax.XMLReader#getProperty
        */
       public Object getProperty (String name)
  -	throws SAXNotRecognizedException, SAXNotSupportedException
  +    throws SAXNotRecognizedException, SAXNotSupportedException
       {
  -	throw new SAXNotRecognizedException("Property: " + name);
  +    throw new SAXNotRecognizedException("Property: " + name);
       }
   
   
  @@ -283,10 +284,10 @@
        */
       public void setEntityResolver (EntityResolver resolver)
       {
  -	if (resolver == null) {
  -	    throw new NullPointerException("Null entity resolver");
  -	}
  -	entityResolver = resolver;
  +    if (resolver == null) {
  +        throw new NullPointerException("Null entity resolver");
  +    }
  +    entityResolver = resolver;
       }
   
   
  @@ -298,7 +299,7 @@
        */
       public EntityResolver getEntityResolver ()
       {
  -	return entityResolver;
  +    return entityResolver;
       }
   
   
  @@ -312,10 +313,10 @@
        */
       public void setDTDHandler (DTDHandler handler)
       {
  -	if (handler == null) {
  -	    throw new NullPointerException("Null DTD handler");
  -	}
  -	dtdHandler = handler;
  +    if (handler == null) {
  +        throw new NullPointerException("Null DTD handler");
  +    }
  +    dtdHandler = handler;
       }
   
   
  @@ -327,7 +328,7 @@
        */
       public DTDHandler getDTDHandler ()
       {
  -	return dtdHandler;
  +    return dtdHandler;
       }
   
   
  @@ -341,10 +342,10 @@
        */
       public void setContentHandler (ContentHandler handler)
       {
  -	if (handler == null) {
  -	    throw new NullPointerException("Null content handler");
  -	}
  -	contentHandler = handler;
  +    if (handler == null) {
  +        throw new NullPointerException("Null content handler");
  +    }
  +    contentHandler = handler;
       }
   
   
  @@ -356,7 +357,7 @@
        */
       public ContentHandler getContentHandler ()
       {
  -	return contentHandler;
  +    return contentHandler;
       }
   
   
  @@ -370,10 +371,10 @@
        */
       public void setErrorHandler (ErrorHandler handler)
       {
  -	if (handler == null) {
  -	    throw new NullPointerException("Null error handler");
  -	}
  -	errorHandler = handler;
  +    if (handler == null) {
  +        throw new NullPointerException("Null error handler");
  +    }
  +    errorHandler = handler;
       }
   
   
  @@ -385,7 +386,7 @@
        */
       public ErrorHandler getErrorHandler ()
       {
  -	return errorHandler;
  +    return errorHandler;
       }
   
   
  @@ -401,9 +402,9 @@
        * @see org.xml.sax.Parser#parse(java.lang.String)
        */
       public void parse (String systemId)
  -	throws IOException, SAXException
  +    throws IOException, SAXException
       {
  -	parse(new InputSource(systemId));
  +    parse(new InputSource(systemId));
       }
   
   
  @@ -419,19 +420,19 @@
        * @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
        */
       public void parse (InputSource input)
  -	throws IOException, SAXException
  +    throws IOException, SAXException
       {
  -	if (parsing) {
  -	    throw new SAXException("Parser is already in use");
  -	}
  -	setupParser();
  -	parsing = true;
  -	try {
  -	    parser.parse(input);
  -	} finally {
  -	    parsing = false;
  -	}
  -	parsing = false;
  +    if (parsing) {
  +        throw new SAXException("Parser is already in use");
  +    }
  +    setupParser();
  +    parsing = true;
  +    try {
  +        parser.parse(input);
  +    } finally {
  +        parsing = false;
  +    }
  +    parsing = false;
       }
   
   
  @@ -449,10 +450,10 @@
        */
       public void setDocumentLocator (Locator locator)
       {
  -	this.locator = locator;
  -	if (contentHandler != null) {
  -	    contentHandler.setDocumentLocator(locator);
  -	}
  +    this.locator = locator;
  +    if (contentHandler != null) {
  +        contentHandler.setDocumentLocator(locator);
  +    }
       }
   
   
  @@ -464,11 +465,11 @@
        * @see org.xml.sax.DocumentHandler#startDocument
        */
       public void startDocument ()
  -	throws SAXException
  +    throws SAXException
       {
  -	if (contentHandler != null) {
  -	    contentHandler.startDocument();
  -	}
  +    if (contentHandler != null) {
  +        contentHandler.startDocument();
  +    }
       }
   
   
  @@ -480,11 +481,11 @@
        * @see org.xml.sax.DocumentHandler#endDocument
        */
       public void endDocument ()
  -	throws SAXException
  +    throws SAXException
       {
  -	if (contentHandler != null) {
  -	    contentHandler.endDocument();
  -	}
  +    if (contentHandler != null) {
  +        contentHandler.endDocument();
  +    }
       }
   
   
  @@ -497,88 +498,88 @@
        * @param qAtts The XML 1.0 attribute list (with qnames).
        */
       public void startElement (String qName, AttributeList qAtts)
  -	throws SAXException
  +    throws SAXException
       {
  -				// If we're not doing Namespace
  -				// processing, dispatch this quickly.
  -	if (!namespaces) {
  -	    if (contentHandler != null) {
  -		attAdapter.setAttributeList(qAtts);
  -		contentHandler.startElement("", "", qName.intern(),
  -					    attAdapter);
  -	    }
  -	    return;
  -	}
  -
  -
  -				// OK, we're doing Namespace processing.
  -	nsSupport.pushContext();
  -	boolean seenDecl = false;
  -	atts.clear();
  -	
  -				// Take a first pass and copy all
  -				// attributes into the SAX2 attribute
  -				// list, noting any Namespace 
  -				// declarations.
  -	int length = qAtts.getLength();
  -	for (int i = 0; i < length; i++) {
  -	    String attQName = qAtts.getName(i);
  -	    String type = qAtts.getType(i);
  -	    String value = qAtts.getValue(i);
  -
  -				// Found a declaration...
  -	    if (attQName.startsWith("xmlns")) {
  -		String prefix;
  -		int n = attQName.indexOf(':');
  -		if (n == -1) {
  -		    prefix = "";
  -		} else {
  -		    prefix = attQName.substring(n+1);
  -		}
  -		if (!nsSupport.declarePrefix(prefix, value)) {
  -		    reportError("Illegal Namespace prefix: " + prefix);
  -		}
  -		if (contentHandler != null) {
  -		    contentHandler.startPrefixMapping(prefix, value);
  -		}
  -				// We may still have to add this to
  -				// the list.
  -		if (prefixes) {
  -		    atts.addAttribute("", "", attQName.intern(),
  -				      type, value);
  -		}
  -		seenDecl = true;
  -
  -				// This isn't a declaration.
  -	    } else {
  -		String attName[] = processName(attQName, true);
  -		atts.addAttribute(attName[0], attName[1], attName[2],
  -				  type, value);
  -	    }
  -	}
  -	
  -				// If there was a Namespace declaration,
  -				// we have to make a second pass just
  -				// to be safe -- this will happen very
  -				// rarely, possibly only once for each
  -				// document.
  -	if (seenDecl) {
  -	    length = atts.getLength();
  -	    for (int i = 0; i < length; i++) {
  -		String attQName = atts.getQName(i);
  -		if (!attQName.startsWith("xmlns")) {
  -		    String attName[] = processName(attQName, true);
  -		    atts.setURI(i, attName[0]);
  -		    atts.setLocalName(i, attName[1]);
  -		}
  -	    }
  -	}
  -
  -				// OK, finally report the event.
  -	if (contentHandler != null) {
  -	    String name[] = processName(qName, false);
  -	    contentHandler.startElement(name[0], name[1], name[2], atts);
  -	}
  +                // If we're not doing Namespace
  +                // processing, dispatch this quickly.
  +    if (!namespaces) {
  +        if (contentHandler != null) {
  +        attAdapter.setAttributeList(qAtts);
  +        contentHandler.startElement("", "", qName.intern(),
  +                        attAdapter);
  +        }
  +        return;
  +    }
  +
  +
  +                // OK, we're doing Namespace processing.
  +    nsSupport.pushContext();
  +    boolean seenDecl = false;
  +    atts.clear();
  +    
  +                // Take a first pass and copy all
  +                // attributes into the SAX2 attribute
  +                // list, noting any Namespace 
  +                // declarations.
  +    int length = qAtts.getLength();
  +    for (int i = 0; i < length; i++) {
  +        String attQName = qAtts.getName(i);
  +        String type = qAtts.getType(i);
  +        String value = qAtts.getValue(i);
  +
  +                // Found a declaration...
  +        if (attQName.startsWith("xmlns")) {
  +        String prefix;
  +        int n = attQName.indexOf(':');
  +        if (n == -1) {
  +            prefix = "";
  +        } else {
  +            prefix = attQName.substring(n+1);
  +        }
  +        if (!nsSupport.declarePrefix(prefix, value)) {
  +            reportError("Illegal Namespace prefix: " + prefix);
  +        }
  +        if (contentHandler != null) {
  +            contentHandler.startPrefixMapping(prefix, value);
  +        }
  +                // We may still have to add this to
  +                // the list.
  +        if (prefixes) {
  +            atts.addAttribute("", "", attQName.intern(),
  +                      type, value);
  +        }
  +        seenDecl = true;
  +
  +                // This isn't a declaration.
  +        } else {
  +        String attName[] = processName(attQName, true);
  +        atts.addAttribute(attName[0], attName[1], attName[2],
  +                  type, value);
  +        }
  +    }
  +    
  +                // If there was a Namespace declaration,
  +                // we have to make a second pass just
  +                // to be safe -- this will happen very
  +                // rarely, possibly only once for each
  +                // document.
  +    if (seenDecl) {
  +        length = atts.getLength();
  +        for (int i = 0; i < length; i++) {
  +        String attQName = atts.getQName(i);
  +        if (!attQName.startsWith("xmlns")) {
  +            String attName[] = processName(attQName, true);
  +            atts.setURI(i, attName[0]);
  +            atts.setLocalName(i, attName[1]);
  +        }
  +        }
  +    }
  +
  +                // OK, finally report the event.
  +    if (contentHandler != null) {
  +        String name[] = processName(qName, false);
  +        contentHandler.startElement(name[0], name[1], name[2], atts);
  +    }
       }
   
   
  @@ -591,28 +592,28 @@
        * @see org.xml.sax.DocumentHandler#endElement
        */
       public void endElement (String qName)
  -	throws SAXException
  +    throws SAXException
       {
  -				// If we're not doing Namespace
  -				// processing, dispatch this quickly.
  -	if (!namespaces) {
  -	    if (contentHandler != null) {
  -		contentHandler.endElement("", "", qName.intern());
  -	    }
  -	    return;
  -	}
  -
  -				// Split the name.
  -	String names[] = processName(qName, false);
  -	if (contentHandler != null) {
  -	    contentHandler.endElement(names[0], names[1], names[2]);
  -	    Enumeration prefixes = nsSupport.getDeclaredPrefixes();
  -	    while (prefixes.hasMoreElements()) {
  -		String prefix = (String)prefixes.nextElement();
  -		contentHandler.endPrefixMapping(prefix);
  -	    }
  -	}
  -	nsSupport.popContext();
  +                // If we're not doing Namespace
  +                // processing, dispatch this quickly.
  +    if (!namespaces) {
  +        if (contentHandler != null) {
  +        contentHandler.endElement("", "", qName.intern());
  +        }
  +        return;
  +    }
  +
  +                // Split the name.
  +    String names[] = processName(qName, false);
  +    if (contentHandler != null) {
  +        contentHandler.endElement(names[0], names[1], names[2]);
  +        Enumeration prefixes = nsSupport.getDeclaredPrefixes();
  +        while (prefixes.hasMoreElements()) {
  +        String prefix = (String)prefixes.nextElement();
  +        contentHandler.endPrefixMapping(prefix);
  +        }
  +    }
  +    nsSupport.popContext();
       }
   
   
  @@ -627,11 +628,11 @@
        * @see org.xml.sax.DocumentHandler#characters
        */
       public void characters (char ch[], int start, int length)
  -	throws SAXException
  +    throws SAXException
       {
  -	if (contentHandler != null) {
  -	    contentHandler.characters(ch, start, length);
  -	}
  +    if (contentHandler != null) {
  +        contentHandler.characters(ch, start, length);
  +    }
       }
   
   
  @@ -646,11 +647,11 @@
        * @see org.xml.sax.DocumentHandler#ignorableWhitespace
        */
       public void ignorableWhitespace (char ch[], int start, int length)
  -	throws SAXException
  +    throws SAXException
       {
  -	if (contentHandler != null) {
  -	    contentHandler.ignorableWhitespace(ch, start, length);
  -	}
  +    if (contentHandler != null) {
  +        contentHandler.ignorableWhitespace(ch, start, length);
  +    }
       }
   
   
  @@ -664,11 +665,11 @@
        * @see org.xml.sax.DocumentHandler#processingInstruction
        */
       public void processingInstruction (String target, String data)
  -	throws SAXException
  +    throws SAXException
       {
  -	if (contentHandler != null) {
  -	    contentHandler.processingInstruction(target, data);
  -	}
  +    if (contentHandler != null) {
  +        contentHandler.processingInstruction(target, data);
  +    }
       }
   
   
  @@ -683,19 +684,19 @@
        */
       private void setupParser ()
       {
  -	nsSupport.reset();
  +    nsSupport.reset();
   
  -	if (entityResolver != null) {
  -	    parser.setEntityResolver(entityResolver);
  -	}
  -	if (dtdHandler != null) {
  -	    parser.setDTDHandler(dtdHandler);
  -	}
  -	if (errorHandler != null) {
  -	    parser.setErrorHandler(errorHandler);
  -	}
  -	parser.setDocumentHandler(this);
  -	locator = null;
  +    if (entityResolver != null) {
  +        parser.setEntityResolver(entityResolver);
  +    }
  +    if (dtdHandler != null) {
  +        parser.setDTDHandler(dtdHandler);
  +    }
  +    if (errorHandler != null) {
  +        parser.setErrorHandler(errorHandler);
  +    }
  +    parser.setDocumentHandler(this);
  +    locator = null;
       }
   
   
  @@ -713,16 +714,16 @@
        *            an exception if there is an error callback.
        */
       private String [] processName (String qName, boolean isAttribute)
  -	throws SAXException
  +    throws SAXException
       {
  -	String parts[] = nsSupport.processName(qName, nameParts,
  -					       isAttribute);
  -	if (parts == null) {
  -	    parts = new String[3];
  -	    parts[2] = qName.intern();
  -	    reportError("Undeclared prefix: " + qName);
  -	}
  -	return parts;
  +    String parts[] = nsSupport.processName(qName, nameParts,
  +                           isAttribute);
  +    if (parts == null) {
  +        parts = new String[3];
  +        parts[2] = qName.intern();
  +        reportError("Undeclared prefix: " + qName);
  +    }
  +    return parts;
       }
   
   
  @@ -734,19 +735,19 @@
        *            an exception.
        */
       void reportError (String message)
  -	throws SAXException
  +    throws SAXException
       {
  -	if (errorHandler == null) {
  -	    return;
  -	}
  -
  -	SAXParseException e;
  -	if (locator != null) {
  -	    e = new SAXParseException(message, locator);
  -	} else {
  -	    e = new SAXParseException(message, null, null, -1, -1);
  -	}
  -	errorHandler.error(e);
  +    if (errorHandler == null) {
  +        return;
  +    }
  +
  +    SAXParseException e;
  +    if (locator != null) {
  +        e = new SAXParseException(message, locator);
  +    } else {
  +        e = new SAXParseException(message, null, null, -1, -1);
  +    }
  +    errorHandler.error(e);
       }
   
   
  @@ -762,14 +763,14 @@
        *            document is currently being parsed.
        */
       private void checkNotParsing (String type, String name)
  -	throws SAXNotSupportedException
  +    throws SAXNotSupportedException
       {
  -	if (parsing) {
  -	    throw new SAXNotSupportedException("Cannot change " +
  -					       type + ' ' +
  -					       name + " while parsing");
  -					       
  -	}
  +    if (parsing) {
  +        throw new SAXNotSupportedException("Cannot change " +
  +                           type + ' ' +
  +                           name + " while parsing");
  +                           
  +    }
       }
   
   
  @@ -788,13 +789,13 @@
   
       private AttributesImpl atts = null;
   
  -				// Features
  +                // Features
       private boolean namespaces = true;
       private boolean prefixes = false;
   
  -				// Properties
  +                // Properties
   
  -				// Handlers
  +                // Handlers
       Locator locator;
   
       EntityResolver entityResolver = null;
  @@ -823,185 +824,185 @@
       final class AttributeListAdapter implements Attributes
       {
   
  -	/**
  -	 * Construct a new adapter.
  -	 */
  -	AttributeListAdapter ()
  -	{
  -	}
  -
  -
  -	/**
  -	 * Set the embedded AttributeList.
  -	 *
  -	 * <p>This method must be invoked before any of the others
  -	 * can be used.</p>
  -	 *
  -	 * @param The SAX1 attribute list (with qnames).
  -	 */
  -	void setAttributeList (AttributeList qAtts)
  -	{
  -	    this.qAtts = qAtts;
  -	}
  -
  -
  -	/**
  -	 * Return the length of the attribute list.
  -	 *
  -	 * @return The number of attributes in the list.
  -	 * @see org.xml.sax.Attributes#getLength
  -	 */
  -	public int getLength ()
  -	{
  -	    return qAtts.getLength();
  -	}
  -
  -
  -	/**
  -	 * Return the Namespace URI of the specified attribute.
  -	 *
  -	 * @param The attribute's index.
  -	 * @return Always the empty string.
  -	 * @see org.xml.sax.Attributes#getURI
  -	 */
  -	public String getURI (int i)
  -	{
  -	    return "";
  -	}
  -
  -
  -	/**
  -	 * Return the local name of the specified attribute.
  -	 *
  -	 * @param The attribute's index.
  -	 * @return Always the empty string.
  -	 * @see org.xml.sax.Attributes#getLocalName
  -	 */
  -	public String getLocalName (int i)
  -	{
  -	    return "";
  -	}
  -
  -
  -	/**
  -	 * Return the qualified (prefixed) name of the specified attribute.
  -	 *
  -	 * @param The attribute's index.
  -	 * @return The attribute's qualified name, internalized.
  -	 */
  -	public String getQName (int i)
  -	{
  -	    return qAtts.getName(i).intern();
  -	}
  -
  -
  -	/**
  -	 * Return the type of the specified attribute.
  -	 *
  -	 * @param The attribute's index.
  -	 * @return The attribute's type as an internalized string.
  -	 */
  -	public String getType (int i)
  -	{
  -	    return qAtts.getType(i).intern();
  -	}
  -
  -
  -	/**
  -	 * Return the value of the specified attribute.
  -	 *
  -	 * @param The attribute's index.
  -	 * @return The attribute's value.
  -	 */
  -	public String getValue (int i)
  -	{
  -	    return qAtts.getValue(i);
  -	}
  -
  -
  -	/**
  -	 * Look up an attribute index by Namespace name.
  -	 *
  -	 * @param uri The Namespace URI or the empty string.
  -	 * @param localName The local name.
  -	 * @return The attributes index, or -1 if none was found.
  -	 * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)
  -	 */
  -	public int getIndex (String uri, String localName)
  -	{
  -	    return -1;
  -	}
  -
  -
  -	/**
  -	 * Look up an attribute index by qualified (prefixed) name.
  -	 *
  -	 * @param qName The qualified name.
  -	 * @return The attributes index, or -1 if none was found.
  -	 * @see org.xml.sax.Attributes#getIndex(java.lang.String)
  -	 */
  -	public int getIndex (String qName)
  -	{
  -	    int max = atts.getLength();
  -	    for (int i = 0; i < max; i++) {
  -		if (qAtts.getName(i).equals(qName)) {
  -		    return i;
  -		}
  -	    }
  -	    return -1;
  -	}
  -
  -
  -	/**
  -	 * Look up the type of an attribute by Namespace name.
  -	 *
  -	 * @param uri The Namespace URI
  -	 * @param localName The local name.
  -	 * @return The attribute's type as an internalized string.
  -	 */
  -	public String getType (String uri, String localName)
  -	{
  -	    return null;
  -	}
  -
  -
  -	/**
  -	 * Look up the type of an attribute by qualified (prefixed) name.
  -	 *
  -	 * @param qName The qualified name.
  -	 * @return The attribute's type as an internalized string.
  -	 */
  -	public String getType (String qName)
  -	{
  -	    return qAtts.getType(qName).intern();
  -	}
  -
  -
  -	/**
  -	 * Look up the value of an attribute by Namespace name.
  -	 *
  -	 * @param uri The Namespace URI
  -	 * @param localName The local name.
  -	 * @return The attribute's value.
  -	 */
  -	public String getValue (String uri, String localName)
  -	{
  -	    return null;
  -	}
  -
  -
  -	/**
  -	 * Look up the value of an attribute by qualified (prefixed) name.
  -	 *
  -	 * @param qName The qualified name.
  -	 * @return The attribute's value.
  -	 */
  -	public String getValue (String qName)
  -	{
  -	    return qAtts.getValue(qName);
  -	}
  +    /**
  +     * Construct a new adapter.
  +     */
  +    AttributeListAdapter ()
  +    {
  +    }
  +
  +
  +    /**
  +     * Set the embedded AttributeList.
  +     *
  +     * <p>This method must be invoked before any of the others
  +     * can be used.</p>
  +     *
  +     * @param The SAX1 attribute list (with qnames).
  +     */
  +    void setAttributeList (AttributeList qAtts)
  +    {
  +        this.qAtts = qAtts;
  +    }
  +
  +
  +    /**
  +     * Return the length of the attribute list.
  +     *
  +     * @return The number of attributes in the list.
  +     * @see org.xml.sax.Attributes#getLength
  +     */
  +    public int getLength ()
  +    {
  +        return qAtts.getLength();
  +    }
  +
  +
  +    /**
  +     * Return the Namespace URI of the specified attribute.
  +     *
  +     * @param The attribute's index.
  +     * @return Always the empty string.
  +     * @see org.xml.sax.Attributes#getURI
  +     */
  +    public String getURI (int i)
  +    {
  +        return "";
  +    }
  +
  +
  +    /**
  +     * Return the local name of the specified attribute.
  +     *
  +     * @param The attribute's index.
  +     * @return Always the empty string.
  +     * @see org.xml.sax.Attributes#getLocalName
  +     */
  +    public String getLocalName (int i)
  +    {
  +        return "";
  +    }
  +
  +
  +    /**
  +     * Return the qualified (prefixed) name of the specified attribute.
  +     *
  +     * @param The attribute's index.
  +     * @return The attribute's qualified name, internalized.
  +     */
  +    public String getQName (int i)
  +    {
  +        return qAtts.getName(i).intern();
  +    }
  +
  +
  +    /**
  +     * Return the type of the specified attribute.
  +     *
  +     * @param The attribute's index.
  +     * @return The attribute's type as an internalized string.
  +     */
  +    public String getType (int i)
  +    {
  +        return qAtts.getType(i).intern();
  +    }
  +
  +
  +    /**
  +     * Return the value of the specified attribute.
  +     *
  +     * @param The attribute's index.
  +     * @return The attribute's value.
  +     */
  +    public String getValue (int i)
  +    {
  +        return qAtts.getValue(i);
  +    }
  +
  +
  +    /**
  +     * Look up an attribute index by Namespace name.
  +     *
  +     * @param uri The Namespace URI or the empty string.
  +     * @param localName The local name.
  +     * @return The attributes index, or -1 if none was found.
  +     * @see org.xml.sax.Attributes#getIndex(java.lang.String,java.lang.String)
  +     */
  +    public int getIndex (String uri, String localName)
  +    {
  +        return -1;
  +    }
  +
  +
  +    /**
  +     * Look up an attribute index by qualified (prefixed) name.
  +     *
  +     * @param qName The qualified name.
  +     * @return The attributes index, or -1 if none was found.
  +     * @see org.xml.sax.Attributes#getIndex(java.lang.String)
  +     */
  +    public int getIndex (String qName)
  +    {
  +        int max = atts.getLength();
  +        for (int i = 0; i < max; i++) {
  +        if (qAtts.getName(i).equals(qName)) {
  +            return i;
  +        }
  +        }
  +        return -1;
  +    }
  +
  +
  +    /**
  +     * Look up the type of an attribute by Namespace name.
  +     *
  +     * @param uri The Namespace URI
  +     * @param localName The local name.
  +     * @return The attribute's type as an internalized string.
  +     */
  +    public String getType (String uri, String localName)
  +    {
  +        return null;
  +    }
  +
  +
  +    /**
  +     * Look up the type of an attribute by qualified (prefixed) name.
  +     *
  +     * @param qName The qualified name.
  +     * @return The attribute's type as an internalized string.
  +     */
  +    public String getType (String qName)
  +    {
  +        return qAtts.getType(qName).intern();
  +    }
  +
  +
  +    /**
  +     * Look up the value of an attribute by Namespace name.
  +     *
  +     * @param uri The Namespace URI
  +     * @param localName The local name.
  +     * @return The attribute's value.
  +     */
  +    public String getValue (String uri, String localName)
  +    {
  +        return null;
  +    }
  +
  +
  +    /**
  +     * Look up the value of an attribute by qualified (prefixed) name.
  +     *
  +     * @param qName The qualified name.
  +     * @return The attribute's value.
  +     */
  +    public String getValue (String qName)
  +    {
  +        return qAtts.getValue(qName);
  +    }
   
  -	private AttributeList qAtts;
  +    private AttributeList qAtts;
       }
   }
   
  
  
  
  1.2.2.2   +111 -64   xml-commons/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java
  
  Index: XMLReaderFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/org/xml/sax/helpers/XMLReaderFactory.java,v
  retrieving revision 1.2.2.1
  retrieving revision 1.2.2.2
  diff -u -r1.2.2.1 -r1.2.2.2
  --- XMLReaderFactory.java	10 May 2002 20:42:39 -0000	1.2.2.1
  +++ XMLReaderFactory.java	17 Sep 2002 14:56:02 -0000	1.2.2.2
  @@ -102,57 +102,104 @@
        * @see #createXMLReader(java.lang.String)
        */
       public static XMLReader createXMLReader ()
  -	throws SAXException
  +    throws SAXException
       {
  -	String		className = null;
  -	ClassLoader	loader = NewInstance.getClassLoader ();
  -	
  -	// 1. try the JVM-instance-wide system property
  -	try { className = System.getProperty (property); }
  -	catch (Exception e) { /* normally fails for applets */ }
  -
  -	// 2. if that fails, try META-INF/services/
  -	if (className == null) {
  -	    try {
  -		String		service = "META-INF/services/" + property;
  -		InputStream	in;
  -		BufferedReader	reader;
  -
  -		if (loader == null)
  -		    in = ClassLoader.getSystemResourceAsStream (service);
  -		else
  -		    in = loader.getResourceAsStream (service);
  -
  -		if (in != null) {
  -		    reader = new BufferedReader (
  -			    new InputStreamReader (in, "UTF8"));
  -		    className = reader.readLine ();
  -		    in.close ();
  -		}
  -	    } catch (Exception e) {
  -	    }
  -	}
  +        String      className = null;
  +        SecuritySupport ss = SecuritySupport.getInstance();
  +        ClassLoader loader = NewInstance.getClassLoader ();
  +    
  +        // 1. try the JVM-instance-wide system property 
  +        try {
  +            className = ss.getSystemProperty(property);
  +        } catch (Exception e) { /* normally fails for applets */ }
  +
  +    // 2. if that fails, try META-INF/services/
  +    if (className == null) {
  +        String      service = "META-INF/services/" + property;
  +
  +        InputStream is = null;
  +
  +        // First try the Context ClassLoader
  +        ClassLoader cl = ss.getContextClassLoader();
  +        if (cl != null) {
  +            is = ss.getResourceAsStream(cl, service);
  +
  +            // If no provider found then try the current ClassLoader
  +            if (is == null) {
  +                cl = XMLReaderFactory.class.getClassLoader();
  +                is = ss.getResourceAsStream(cl, service);
  +            }
  +        } else {
  +            // No Context ClassLoader or JDK 1.1 so try the current
  +            // ClassLoader
  +            cl = XMLReaderFactory.class.getClassLoader();
  +            is = ss.getResourceAsStream(cl, service);
  +        }
  +
  +        if (is != null) {
  +
  +            // Read the service provider name in UTF-8 as specified in
  +            // the jar spec.  Unfortunately this fails in Microsoft
  +            // VJ++, which does not implement the UTF-8
  +            // encoding. Theoretically, we should simply let it fail in
  +            // that case, since the JVM is obviously broken if it
  +            // doesn't support such a basic standard.  But since there
  +            // are still some users attempting to use VJ++ for
  +            // development, we have dropped in a fallback which makes a
  +            // second attempt using the platform's default encoding. In
  +            // VJ++ this is apparently ASCII, which is a subset of
  +            // UTF-8... and since the strings we'll be reading here are
  +            // also primarily limited to the 7-bit ASCII range (at
  +            // least, in English versions), this should work well
  +            // enough to keep us on the air until we're ready to
  +            // officially decommit from VJ++. [Edited comment from
  +            // jkesselm]
  +            BufferedReader rd;
  +            try {
  +                rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
  +            } catch (java.io.UnsupportedEncodingException e) {
  +                rd = new BufferedReader(new InputStreamReader(is));
  +            }
  +        
  +            try {
  +                // XXX Does not handle all possible input as specified by the
  +                // Jar Service Provider specification
  +                className = rd.readLine();
  +                rd.close();
  +            } catch (Exception x) {
  +                // No provider found
  +            } 
  +        }
  +    }
  +    // REVISIT:  there is a comment in the original FactoryFinder codde to the effect:
  +    //
  +    // ClassLoader because we want to avoid the case where the
  +    // resource file was found using one ClassLoader and the
  +    // provider class was instantiated using a different one.
  +    //
  +    // But it's not clear how the class loader "cl" (now out of scope!)
  +    // that loaded the inputStream would matter here...
   
  -	// 3. Distro-specific fallback
  -	if (className == null) {
  +    // 3. Distro-specific fallback
  +    if (className == null) {
           // modified by neilg in accordance with the "strong encouragement"
           // provided to distributions which include parsers.
   
  -	    className = "org.apache.xerces.parsers.SAXParser";
  +        className = "org.apache.xerces.parsers.SAXParser";
   
  -	}
  -	
  -	// do we know the XMLReader implementation class yet?
  -	if (className != null)
  -	    return loadClass (loader, className);
  -
  -	// 4. panic -- adapt any SAX1 parser
  -	try {
  -	    return new ParserAdapter (ParserFactory.makeParser ());
  -	} catch (Exception e) {
  -	    throw new SAXException ("Can't create default XMLReader; "
  -		    + "is system property org.xml.sax.driver set?");
  -	}
  +    }
  +    
  +    // do we know the XMLReader implementation class yet?
  +    if (className != null)
  +        return loadClass (loader, className);
  +
  +    // 4. panic -- adapt any SAX1 parser
  +    try {
  +        return new ParserAdapter (ParserFactory.makeParser ());
  +    } catch (Exception e) {
  +        throw new SAXException ("Can't create default XMLReader; "
  +            + "is system property org.xml.sax.driver set?");
  +    }
       }
   
   
  @@ -172,29 +219,29 @@
        * @see #createXMLReader()
        */
       public static XMLReader createXMLReader (String className)
  -	throws SAXException
  +    throws SAXException
       {
  -	return loadClass (NewInstance.getClassLoader (), className);
  +    return loadClass (NewInstance.getClassLoader (), className);
       }
   
       private static XMLReader loadClass (ClassLoader loader, String className)
       throws SAXException
       {
  -	try {
  -	    return (XMLReader) NewInstance.newInstance (loader, className);
  -	} catch (ClassNotFoundException e1) {
  -	    throw new SAXException("SAX2 driver class " + className +
  -				   " not found", e1);
  -	} catch (IllegalAccessException e2) {
  -	    throw new SAXException("SAX2 driver class " + className +
  -				   " found but cannot be loaded", e2);
  -	} catch (InstantiationException e3) {
  -	    throw new SAXException("SAX2 driver class " + className +
  -	   " loaded but cannot be instantiated (no empty public constructor?)",
  -				   e3);
  -	} catch (ClassCastException e4) {
  -	    throw new SAXException("SAX2 driver class " + className +
  -				   " does not implement XMLReader", e4);
  -	}
  +    try {
  +        return (XMLReader) NewInstance.newInstance (loader, className);
  +    } catch (ClassNotFoundException e1) {
  +        throw new SAXException("SAX2 driver class " + className +
  +                   " not found", e1);
  +    } catch (IllegalAccessException e2) {
  +        throw new SAXException("SAX2 driver class " + className +
  +                   " found but cannot be loaded", e2);
  +    } catch (InstantiationException e3) {
  +        throw new SAXException("SAX2 driver class " + className +
  +       " loaded but cannot be instantiated (no empty public constructor?)",
  +                   e3);
  +    } catch (ClassCastException e4) {
  +        throw new SAXException("SAX2 driver class " + className +
  +                   " does not implement XMLReader", e4);
  +    }
       }
   }
  
  
  
  1.1.2.3   +49 -26    xml-commons/java/external/src/org/xml/sax/helpers/NewInstance.java
  
  Index: NewInstance.java
  ===================================================================
  RCS file: /home/cvs/xml-commons/java/external/src/org/xml/sax/helpers/NewInstance.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- NewInstance.java	17 May 2002 16:13:15 -0000	1.1.2.2
  +++ NewInstance.java	17 Sep 2002 14:56:02 -0000	1.1.2.3
  @@ -23,33 +23,61 @@
    * <p>This class contains a static method for creating an instance of a
    * class from an explicit class name.  It tries to use the thread's context
    * ClassLoader if possible and falls back to using
  - * Class.forName(String).</p>
  + * Class.forName(String).  It also takes into account JDK 1.2+'s
  + * AccessController mechanism for performing its actions.  </p>
    *
  - * <p>This code is designed to compile and run on JDK version 1.1 and later
  - * including versions of Java 2.</p>
  + * <p>This code is designed to run on JDK version 1.1 and later and compile
  + * on versions of Java 2 and later.</p>
    *
  - * @author Edwin Goei, David Brownell
  - * @version 2.0r2pre3
  + * @author Edwin Goei, David Brownell, Neil Graham
  + * @version $Id$
    */
   class NewInstance {
   
  +    // constants
  +
  +    // governs whether, if we fail in finding a class even
  +    // when given a classloader, we'll make a last-ditch attempt
  +    // to use the current classloader.  
  +    private static final boolean DO_FALLBACK = true;
  +
       /**
        * Creates a new instance of the specified class name
        *
        * Package private so this code is not exposed at the API level.
        */
  -    static Object newInstance (ClassLoader classLoader, String className)
  +    static Object newInstance (ClassLoader cl, String className)
           throws ClassNotFoundException, IllegalAccessException,
               InstantiationException
       {
  -        if (classLoader != null) {
  +
  +        Class providerClass;
  +        if (cl == null) {
  +            // XXX Use the bootstrap ClassLoader.  There is no way to
  +            // load a class using the bootstrap ClassLoader that works
  +            // in both JDK 1.1 and Java 2.  However, this should still
  +            // work b/c the following should be true:
  +            //
  +            // (cl == null) iff current ClassLoader == null
  +            //
  +            // Thus Class.forName(String) will use the current
  +            // ClassLoader which will be the bootstrap ClassLoader.
  +            providerClass = Class.forName(className);
  +        } else {
               try {
  -                  return classLoader.loadClass(className).newInstance ();
  +                providerClass = cl.loadClass(className);
               } catch (ClassNotFoundException x) {
  -                  // try again
  +                if (DO_FALLBACK) {
  +                    // Fall back to current classloader
  +                    cl = NewInstance.class.getClassLoader();
  +                    providerClass = cl.loadClass(className);
  +                } else {
  +                    throw x;
  +                }
               }
           }
  -        return Class.forName(className).newInstance();
  +        Object instance = providerClass.newInstance();
  +        return instance;
       }
   
       /**
  @@ -58,23 +86,18 @@
        */           
       static ClassLoader getClassLoader ()
       {
  -        Method m = null;
   
  -        try {
  -            m = Thread.class.getMethod("getContextClassLoader", null);
  -        } catch (NoSuchMethodException e) {
  -            // Assume that we are running JDK 1.1, use the current ClassLoader
  -            return NewInstance.class.getClassLoader();
  -        }
  +        SecuritySupport ss = SecuritySupport.getInstance();
   
  -        try {
  -            return (ClassLoader) m.invoke(Thread.currentThread(), null);
  -        } catch (IllegalAccessException e) {
  -            // assert(false)
  -            throw new UnknownError(e.getMessage());
  -        } catch (InvocationTargetException e) {
  -            // assert(e.getTargetException() instanceof SecurityException)
  -            throw new UnknownError(e.getMessage());
  +        // Figure out which ClassLoader to use for loading the provider
  +        // class.  If there is a Context ClassLoader then use it.
  +        ClassLoader cl = ss.getContextClassLoader();
  +        if (cl == null) {
  +            // Assert: we are on JDK 1.1 or we have no Context ClassLoader
  +            // so use the current ClassLoader
  +            cl = NewInstance.class.getClassLoader();
           }
  +        return cl;
  +
       }
   }