You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2001/11/29 18:26:57 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util DOMEntityResolverWrapper.java DOMErrorHandlerWrapper.java

elena       01/11/29 09:26:56

  Added:       java/src/org/apache/xerces/dom DOMErrorImpl.java
                        DOMInputSourceImpl.java DOMLocatorImpl.java
               java/src/org/apache/xerces/util
                        DOMEntityResolverWrapper.java
                        DOMErrorHandlerWrapper.java
  Log:
  Implementation of some features for DOM L3 Core/LS.
  Submitted by: Gopal Sharma, SUN Microsystems Inc
  Reviewed by: Elena Litani
  
  Revision  Changes    Path
  1.1                  xml-xerces/java/src/org/apache/xerces/dom/DOMErrorImpl.java
  
  Index: DOMErrorImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.dom;
  
  import org.apache.xerces.xni.parser.XMLParseException;
  
  import org.apache.xerces.dom3.DOMError;
  import org.apache.xerces.dom3.DOMLocator;
  
  
  /**
   * <code>DOMErrorImpl</code> is an implementation that describes an error.
   * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010913'>Document Object Model (DOM) Level 3 Core Specification</a>.
   *
   * @author Gopal Sharma, SUN Microsystems Inc.
   */
  
  //
  // REVISIT: 
  // implementation does not allow to reuse the DOMError obj
  // to allow reuse we need to implement setter methods 
  // we also create new DOMLocator for each error.  -- el
  // 
  
  public class DOMErrorImpl implements DOMError {
  
      //
      // Data
      //
  
      short fSeverity = -1;
      String fMessage = null;    
      DOMLocator fLocation = null;
      Exception fException = null;
  
  
      //
      // Constructor
      //
  
      public DOMErrorImpl (short severity, XMLParseException exception) {
          fSeverity = severity;
          fException = exception;
          fMessage = exception.getMessage();
          fLocation = createDOMLocator (exception);
      }
  
      /**
       * The severity of the error, either <code>SEVERITY_WARNING</code>, 
       * <code>SEVERITY_ERROR</code>, or <code>SEVERITY_FATAL_ERROR</code>.
       */
  
      public short getSeverity() {
          return fSeverity;
      }
  
      /**
       * An implementation specific string describing the error that occured.
       */
  
      public String getMessage() {
          return fMessage;
      }
  
      /**
       * The byte or character offset into the input source, if we're parsing a 
       * file or a byte stream then this will be the byte offset into that 
       * stream, but if a character media is parsed then the offset will be 
       * the character offset.exception is a reserved word, we need to rename 
       * it.
       */
  
      public Object getException() {
          return fException;
      } 
  
      /**
       * The location of the error.
       */
  
      public DOMLocator getLocation() {
          return fLocation;
      }
  
      // method to get the DOMLocator Object
      private DOMLocator createDOMLocator(XMLParseException exception) {
          return new DOMLocatorImpl(exception.getLineNumber(),
                                    exception.getColumnNumber(),
                                    exception.getSystemId()
                                   );
      } // createDOMLocator()
  
  }// class DOMErrorImpl
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/dom/DOMInputSourceImpl.java
  
  Index: DOMInputSourceImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.dom;
  
  import org.apache.xerces.dom3.ls.DOMInputSource;
  
  import java.io.Reader;
  import java.io.InputStream;
  
  /**
   * This Class <code>DOMInputSourceImpl</code> represents a single input source for an XML entity. 
   * <p> This Class allows an application to encapsulate information about 
   * an input source in a single object, which may include a public 
   * identifier, a system identifier, a byte stream (possibly with a specified 
   * encoding), and/or a character stream. 
   * <p> The exact definitions of a byte stream and a character stream are 
   * binding dependent. 
   * <p> There are two places that the application will deliver this input 
   * source to the parser: as the argument to the <code>parse</code> method, 
   * or as the return value of the <code>DOMEntityResolver.resolveEntity</code>
   *  method. 
   * <p> The <code>DOMBuilder</code> will use the <code>DOMInputSource</code> 
   * object to determine how to read XML input. If there is a character stream 
   * available, the parser will read that stream directly; if not, the parser 
   * will use a byte stream, if available; if neither a character stream nor a 
   * byte stream is available, the parser will attempt to open a URI 
   * connection to the resource identified by the system identifier. 
   * <p> An <code>DOMInputSource</code> object belongs to the application: the 
   * parser shall never modify it in any way (it may modify a copy if 
   * necessary).  Eventhough all attributes in this interface are writable the 
   * DOM implementation is expected to never mutate a DOMInputSource. 
   * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-ASLS-20011025'>Document Object Model (DOM) Level 3 Abstract Schemas and Load
  and Save Specification</a>.
   *
   *
   * @author Gopal Sharma, SUN Microsystems Inc.
   */
  
  // REVISIT: 
  // 1. it should be possible to do the following
  // DOMInputSourceImpl extends XMLInputSource implements DOMInputSource
  // 2. we probably need only the default constructor.  -- el
  
  public class DOMInputSourceImpl implements DOMInputSource {
  
  	//
  	// Data
  	//
  
  	protected String fPublicId = null;
  	protected String fSystemId = null;
  	protected String fBaseSystemId = null;
  	
  	protected InputStream fByteStream = null;
  	protected Reader fCharStream	= null;
  	protected String fData = null;
  	
  	protected String fEncoding = null;
  
     /** 
       * Default Constructor, constructs an input source 
       *
       *
       */
       public DOMInputSourceImpl() {} 	
  
     /** 
       * Constructs an input source from just the public and system
       * identifiers, leaving resolution of the entity and opening of
       * the input stream up to the caller.
       *
       * @param publicId     The public identifier, if known.
       * @param systemId     The system identifier. This value should
       *                     always be set, if possible, and can be
       *                     relative or absolute. If the system identifier
       *                     is relative, then the base system identifier
       *                     should be set.
       * @param baseSystemId The base system identifier. This value should
       *                     always be set to the fully expanded URI of the
       *                     base system identifier, if possible.
       */
   
      public DOMInputSourceImpl(String publicId, String systemId,  
                            String baseSystemId) {
  		
  		fPublicId = publicId;
  		fSystemId = systemId;
  		fBaseSystemId = baseSystemId;
  
      } // DOMInputSourceImpl(String,String,String)
  
      /**
       * Constructs an input source from a byte stream.
       *
       * @param publicId     The public identifier, if known.
       * @param systemId     The system identifier. This value should
       *                     always be set, if possible, and can be
       *                     relative or absolute. If the system identifier
       *                     is relative, then the base system identifier
       *                     should be set.
       * @param baseSystemId The base system identifier. This value should
       *                     always be set to the fully expanded URI of the
       *                     base system identifier, if possible.
       * @param byteStream   The byte stream.
       * @param encoding     The encoding of the byte stream, if known.
       */
  
      public DOMInputSourceImpl(String publicId, String systemId,  
                            String baseSystemId, InputStream byteStream,
                            String encoding) {
  		
  		fPublicId = publicId;
  		fSystemId = systemId;
  		fBaseSystemId = baseSystemId;
  		fByteStream = byteStream;
  		fEncoding = encoding;
  
      } // DOMInputSourceImpl(String,String,String,InputStream,String)
  
     /**
       * Constructs an input source from a character stream.
       *
       * @param publicId     The public identifier, if known.
       * @param systemId     The system identifier. This value should
       *                     always be set, if possible, and can be
       *                     relative or absolute. If the system identifier
       *                     is relative, then the base system identifier
       *                     should be set.
       * @param baseSystemId The base system identifier. This value should
       *                     always be set to the fully expanded URI of the
       *                     base system identifier, if possible.
       * @param charStream   The character stream.
       * @param encoding     The original encoding of the byte stream
       *                     used by the reader, if known.
       */
  
       public DOMInputSourceImpl(String publicId, String systemId,  
                            String baseSystemId, Reader charStream,
                            String encoding) {
  		
  		fPublicId = publicId;
  		fSystemId = systemId;
  		fBaseSystemId = baseSystemId;
  		fCharStream = charStream;
  		fEncoding = encoding;
  
       } // DOMInputSourceImpl(String,String,String,Reader,String)
  
     /**
       * Constructs an input source from a String.
       *
       * @param publicId     The public identifier, if known.
       * @param systemId     The system identifier. This value should
       *                     always be set, if possible, and can be
       *                     relative or absolute. If the system identifier
       *                     is relative, then the base system identifier
       *                     should be set.
       * @param baseSystemId The base system identifier. This value should
       *                     always be set to the fully expanded URI of the
       *                     base system identifier, if possible.
       * @param data		   The String Data.
       * @param encoding     The original encoding of the byte stream
       *                     used by the reader, if known.
       */
  
       public DOMInputSourceImpl(String publicId, String systemId,  
                            String baseSystemId, String data,
                            String encoding) {
                  fPublicId = publicId;
  		fSystemId = systemId;
  		fBaseSystemId = baseSystemId;
  		fData = data;
  		fEncoding = encoding;
       } // DOMInputSourceImpl(String,String,String,String,String)
  
     /**
       * An attribute of a language-binding dependent type that represents a 
       * stream of bytes.
       * <br>The parser will ignore this if there is also a character stream 
       * specified, but it will use a byte stream in preference to opening a 
       * URI connection itself.
       * <br>If the application knows the character encoding of the byte stream, 
       * it should set the encoding property. Setting the encoding in this way 
       * will override any encoding specified in the XML declaration itself.
       */
  
      public InputStream getByteStream(){ 
  	return fByteStream;
      } 
  
      /**
       * An attribute of a language-binding dependent type that represents a 
       * stream of bytes.
       * <br>The parser will ignore this if there is also a character stream 
       * specified, but it will use a byte stream in preference to opening a 
       * URI connection itself.
       * <br>If the application knows the character encoding of the byte stream, 
       * it should set the encoding property. Setting the encoding in this way 
       * will override any encoding specified in the XML declaration itself.
       */
  
       public void setByteStream(InputStream byteStream){
   	fByteStream = byteStream;
       }
  
      /**
       *  An attribute of a language-binding dependent type that represents a 
       * stream of 16-bit units. Application must encode the stream using 
       * UTF-16 (defined in  and Amendment 1 of ). 
       * <br>If a character stream is specified, the parser will ignore any byte 
       * stream and will not attempt to open a URI connection to the system 
       * identifier.
       */
      public Reader getCharacterStream(){
  	return fCharStream;
      }
      /**
       *  An attribute of a language-binding dependent type that represents a 
       * stream of 16-bit units. Application must encode the stream using 
       * UTF-16 (defined in  and Amendment 1 of ). 
       * <br>If a character stream is specified, the parser will ignore any byte 
       * stream and will not attempt to open a URI connection to the system 
       * identifier.
       */
  
       public void setCharacterStream(Reader characterStream){
  	fCharStream = characterStream;
       }
  
      /**
       * A string attribute that represents a sequence of 16 bit units (utf-16 
       * encoded characters).
       * <br>If string data is available in the input source, the parser will 
       * ignore the character stream and the byte stream and will not attempt 
       * to open a URI connection to the system identifier.
       */
      public String getStringData(){
  	return fData;
      }
  
     /**
       * A string attribute that represents a sequence of 16 bit units (utf-16 
       * encoded characters).
       * <br>If string data is available in the input source, the parser will 
       * ignore the character stream and the byte stream and will not attempt 
       * to open a URI connection to the system identifier.
       */
      
       public void setStringData(String stringData){
  		fData = stringData;
       }
  
      /**
       *  The character encoding, if known. The encoding must be a string 
       * acceptable for an XML encoding declaration ( section 4.3.3 "Character 
       * Encoding in Entities"). 
       * <br>This attribute has no effect when the application provides a 
       * character stream. For other sources of input, an encoding specified 
       * by means of this attribute will override any encoding specified in 
       * the XML claration or the Text Declaration, or an encoding obtained 
       * from a higher level protocol, such as HTTP .
       */
  
      public String getEncoding(){
  	return fEncoding;
      }
  
      /**
       *  The character encoding, if known. The encoding must be a string 
       * acceptable for an XML encoding declaration ( section 4.3.3 "Character 
       * Encoding in Entities"). 
       * <br>This attribute has no effect when the application provides a 
       * character stream. For other sources of input, an encoding specified 
       * by means of this attribute will override any encoding specified in 
       * the XML claration or the Text Declaration, or an encoding obtained 
       * from a higher level protocol, such as HTTP .
       */
      public void setEncoding(String encoding){
  	fEncoding = encoding;
      }
  
      /**
       * The public identifier for this input source. The public identifier is 
       * always optional: if the application writer includes one, it will be 
       * provided as part of the location information.
       */
      public String getPublicId(){
  	return fPublicId;
      }
      /**
       * The public identifier for this input source. The public identifier is 
       * always optional: if the application writer includes one, it will be 
       * provided as part of the location information.
       */
      public void setPublicId(String publicId){
  	fPublicId = publicId;
      }
  
      /**
       * The system identifier, a URI reference , for this input source. The 
       * system identifier is optional if there is a byte stream or a 
       * character stream, but it is still useful to provide one, since the 
       * application can use it to resolve relative URIs and can include it in 
       * error messages and warnings (the parser will attempt to fetch the 
       * ressource identifier by the URI reference only if there is no byte 
       * stream or character stream specified).
       * <br>If the application knows the character encoding of the object 
       * pointed to by the system identifier, it can register the encoding by 
       * setting the encoding attribute.
       * <br>If the system ID is a relative URI reference (see section 5 in ), 
       * the behavior is implementation dependent.
       */
      public String getSystemId(){
  	return fSystemId;
      }
      /**
       * The system identifier, a URI reference , for this input source. The 
       * system identifier is optional if there is a byte stream or a 
       * character stream, but it is still useful to provide one, since the 
       * application can use it to resolve relative URIs and can include it in 
       * error messages and warnings (the parser will attempt to fetch the 
       * ressource identifier by the URI reference only if there is no byte 
       * stream or character stream specified).
       * <br>If the application knows the character encoding of the object 
       * pointed to by the system identifier, it can register the encoding by 
       * setting the encoding attribute.
       * <br>If the system ID is a relative URI reference (see section 5 in ), 
       * the behavior is implementation dependent.
       */
      public void setSystemId(String systemId){
  	fSystemId = systemId;
      }
  
      /**
       *  The base URI to be used (see section 5.1.4 in ) for resolving relative 
       * URIs to absolute URIs. If the baseURI is itself a relative URI, the 
       * behavior is implementation dependent. 
       */
      public String getBaseURI(){
  	return fBaseSystemId;	
      }
      /**
       *  The base URI to be used (see section 5.1.4 in ) for resolving relative 
       * URIs to absolute URIs. If the baseURI is itself a relative URI, the 
       * behavior is implementation dependent. 
       */
      public void setBaseURI(String baseURI){
  	fBaseSystemId = baseURI;
      }
  
  }// class DOMInputSourceImpl
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/dom/DOMLocatorImpl.java
  
  Index: DOMLocatorImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.dom;
  
  import org.apache.xerces.dom3.DOMLocator;
  import org.w3c.dom.Node;
  
  
  /**
   * <code>DOMLocatorImpl</code> is an implementaion that describes a location (e.g. 
   * where an error occured).
   * <p>See also the <a href='http://www.w3.org/TR/2001/WD-DOM-Level-3-Core-20010913'>Document Object Model (DOM) Level 3 Core Specification</a>.
   *
   * @author Gopal Sharma, SUN Microsystems Inc.
   */
   
  public class DOMLocatorImpl implements DOMLocator {
  
      //
      // Data
      //
  
     /**
      * The column number where the error occured, 
      * or -1 if there is no column number available.
      */
     int fColumnNumber = -1;
  
     /**
      * The DOM Node where the error occured, or 
      * null if there is no Node available.
      */
     Node fErrorNode = null;
  
     /**
      * The line number where the error occured, 
      * or -1 if there is no line number available.
      */
     int fLineNumber = -1;
  
     /**
      * The byte or character offset into the input source, 
      * if we're parsing a file or a byte stream then this 
      * will be the byte offset into that stream, but if a character media 
      * is parsed then the offset will be the character offset
      */
     int fOffset = -1;
  
     /**
      * The URI where the error occured, 
      * or null if there is no URI available.
      */
     String fUri = null;
       
     //
     // Constructors
     //
  
     public DOMLocatorImpl (int lineNumber, int columnNumber, String uri ){
  	fLineNumber = lineNumber ;
  	fColumnNumber = columnNumber ;
  	fUri = uri;
     } // DOMLocatorImpl (int lineNumber, int columnNumber, String uri )
  
    public DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node errorNode, String uri ){
  	fLineNumber = lineNumber ;
  	fColumnNumber = columnNumber ;
  	fOffset = offset ;
  	fErrorNode = errorNode ;
  	fUri = uri;
    } // DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node errorNode, String uri )
  
    /**
     * The line number where the error occured, or -1 if there is no line 
     * number available.
     */
     public int getLineNumber(){
   	return fLineNumber;
     }
  
    /**
     * The column number where the error occured, or -1 if there is no column 
     * number available.
     */
    public int getColumnNumber(){
  	return fColumnNumber;
    }
  
    /**
     * The byte or character offset into the input source, if we're parsing a 
     * file or a byte stream then this will be the byte offset into that 
     * stream, but if a character media is parsed then the offset will be 
     * the character offset.
     */
    public int getOffset(){
  	return fOffset;
    }
    /**
     * The DOM Node where the error occured, or null if there is no Node 
     * available.
     */
    public Node getErrorNode(){
  	return fErrorNode;
    }
  
    /**
     * The URI where the error occured, or null if there is no URI available.
     */
    public String getUri(){
  	return fUri;
    }
  
    
  
  }// class DOMLocatorImpl
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/util/DOMEntityResolverWrapper.java
  
  Index: DOMEntityResolverWrapper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.util;
  
  
  import org.apache.xerces.xni.XNIException;
  import org.apache.xerces.xni.parser.XMLEntityResolver;
  import org.apache.xerces.xni.parser.XMLInputSource;
  
  import org.apache.xerces.dom3.ls.DOMEntityResolver;
  import org.apache.xerces.dom3.ls.DOMInputSource;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.Reader;
  
  
  /**
   * This class wraps DOM entity resolver to XNI entity resolver.
   *
   * @see DOMEntityResolver
   *
   * @author Gopal Sharma, SUN MicroSystems Inc.
   * @author Elena Litani, IBM 
   * 
   */
  public class DOMEntityResolverWrapper
      implements XMLEntityResolver {
  
      //
      // Data
      //
  
      /** The DOM entity resolver. */
      protected DOMEntityResolver fEntityResolver;
  
      //
      // Constructors
      //
  
      /** Default constructor. */
      public DOMEntityResolverWrapper() {}
  
      /** Wraps the specified DOM entity resolver. */
      public DOMEntityResolverWrapper(DOMEntityResolver entityResolver) {
          setEntityResolver(entityResolver);
      } // DOMEntityResolver
  
      //
      // Public methods
      //
  
      /** Sets the DOM entity resolver. */
      public void setEntityResolver(DOMEntityResolver entityResolver) {
          fEntityResolver = entityResolver;
      } // setEntityResolver(DOMEntityResolver)
  
      /** Returns the DOM entity resolver. */
      public DOMEntityResolver getEntityResolver() {
          return fEntityResolver;
      } // getEntityResolver():DOMEntityResolver
  
      //
      // XMLEntityResolver methods
      //
      
      /**
       * Resolves an external parsed entity. If the entity cannot be
       * resolved, this method should return null.
       *
       * @param publicId
       * @param systemId
       * @param baseSystemId The base system identifier.
       *
       * @throws XNIException Thrown on general error.
       * @throws IOException  Thrown if resolved entity stream cannot be
       *                      opened or some other i/o error occurs.
       */
      public XMLInputSource resolveEntity(String publicId, String systemId, 
                                          String baseSystemId) 
          throws XNIException, IOException {
  
          // resolve entity using DOM entity resolver
          if (fEntityResolver != null) {
              try {
                  DOMInputSource inputSource = 
                      fEntityResolver.resolveEntity(publicId, systemId, baseSystemId);
                  if (inputSource != null) {
                      publicId = inputSource.getPublicId();
                      systemId = inputSource.getSystemId();
                      InputStream byteStream = inputSource.getByteStream();
                      Reader charStream = inputSource.getCharacterStream();
                      String encoding = inputSource.getEncoding();
                      XMLInputSource xmlInputSource =
                          new XMLInputSource(publicId, systemId, baseSystemId);
                      xmlInputSource.setByteStream((InputStream)byteStream);
                      xmlInputSource.setCharacterStream(charStream);
                      xmlInputSource.setEncoding(encoding);
                      return xmlInputSource;
                  }
              }
  
              // error resolving entity
              catch (Exception e) {
                  // REVISIT:
                  // can at this point we receive wrapped exception?
  
                  throw new XNIException(e);
              }
          }
  
          // unable to resolve entity
          return null;
  
      } // resolveEntity(String,String,String):XMLInputSource
      
  } // DOMEntityResolverWrapper
  
  
  
  1.1                  xml-xerces/java/src/org/apache/xerces/util/DOMErrorHandlerWrapper.java
  
  Index: DOMErrorHandlerWrapper.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xerces" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, International
   * Business Machines, Inc., http://www.apache.org.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.xerces.util;
  
  import org.apache.xerces.xni.XNIException;
  import org.apache.xerces.xni.parser.XMLErrorHandler;
  import org.apache.xerces.xni.parser.XMLParseException;
  
  import org.apache.xerces.dom3.DOMError;
  import org.apache.xerces.dom3.DOMLocator;
  import org.apache.xerces.dom3.DOMErrorHandler;
  
  import org.apache.xerces.dom.DOMErrorImpl;
  
  import java.io.PrintWriter;
  
  /**
   * This class handles DOM errors .
   *
   * @see DOMErrorHandler
   *
   * @author Gopal Sharma, SUN Microsystems Inc.
   */
  
  // REVISIT: current implementations wraps error several times:
  //          XMLErrorReport.reportError creates XMLParserException (by wrapping all info)
  //          and goes via switch to send errors.
  //          DOMErrorHandlerWrapper catches calls, copies info from XMLParserException and
  //          sends one call back to the application
  //          I think we can avoid this indirection if we modify XMLErrorReporter. --el
  
  public class DOMErrorHandlerWrapper
      implements XMLErrorHandler, DOMErrorHandler {
  
  
    // It keeps the reference of DOMErrorHandler of application
       protected DOMErrorHandler fDomErrorHandler;
       
    // Error Status
       boolean eStatus = true ;
       
    // Print writer
       protected PrintWriter fOut;
  
   	
    //
    // Constructors
    //
     
    // Default constructor /
    
     public DOMErrorHandlerWrapper() {
          fOut = new PrintWriter(System.err);
     }
  
     
     public DOMErrorHandlerWrapper(DOMErrorHandler domErrorHandler) {
  	fDomErrorHandler = domErrorHandler;		
     } // DOMErrorHandlerWrapper(DOMErrorHandler domErrorHandler)
  
      
     //
     // Public methods
     //
  
     /** Sets the DOM error handler. */
     public void setErrorHandler(DOMErrorHandler errorHandler) {
         fDomErrorHandler = errorHandler;
     } // setErrorHandler(ErrorHandler)
      
  
     public DOMErrorHandler getErrorHandler(){
  	return fDomErrorHandler;	
     } //getErrorHandler()
  	
     //
     // XMLErrorHandler methods
     //
  
     /**
      * Reports a warning. Warnings are non-fatal and can be safely ignored
      * by most applications.
      *
      * @param domain    The domain of the warning. The domain can be any
      *                  string but is suggested to be a valid URI. The
      *                  domain can be used to conveniently specify a web
      *                  site location of the relevent specification or
      *                  document pertaining to this warning.
      * @param key       The warning key. This key can be any string and
      *                  is implementation dependent.
      * @param exception Exception.
      *
      * @throws XNIException Thrown to signal that the parser should stop
      *                      parsing the document.
      */
  
     public void warning(String domain, String key, 
  			XMLParseException exception) throws XNIException {
  	DOMError error = new DOMErrorImpl(DOMError.SEVERITY_WARNING, exception);
  	fDomErrorHandler.handleError(error); 
     } // warning(String,String,XMLParseException)
  
     /**
      * Reports an error. Errors are non-fatal and usually signify that the
      * document is invalid with respect to its grammar(s).
      *
      * @param domain    The domain of the error. The domain can be any
      *                  string but is suggested to be a valid URI. The
      *                  domain can be used to conveniently specify a web
      *                  site location of the relevent specification or
      *                  document pertaining to this error.
      * @param key       The error key. This key can be any string and
      *                  is implementation dependent.
      * @param exception Exception.
      *
      * @throws XNIException Thrown to signal that the parser should stop
      *                      parsing the document.
      */
     public void error(String domain, String key, 
  			XMLParseException exception) throws XNIException {
  	DOMError error = new DOMErrorImpl(DOMError.SEVERITY_ERROR, exception);
  	fDomErrorHandler.handleError(error);                        
     } // error(String,String,XMLParseException)
  
     /**
      * Report a fatal error. Fatal errors usually occur when the document
      * is not well-formed and signifies that the parser cannot continue
      * normal operation.
      * <p>
      * <strong>Note:</strong> The error handler should <em>always</em>
      * throw an <code>XNIException</code> from this method. This exception
      * can either be the same exception that is passed as a parameter to
      * the method or a new XNI exception object. If the registered error
      * handler fails to throw an exception, the continuing operation of
      * the parser is undetermined.
      *
      * @param domain    The domain of the fatal error. The domain can be 
      *                  any string but is suggested to be a valid URI. The
      *                  domain can be used to conveniently specify a web
      *                  site location of the relevent specification or
      *                  document pertaining to this fatal error.
      * @param key       The fatal error key. This key can be any string 
      *                  and is implementation dependent.
      * @param exception Exception.
      *
      * @throws XNIException Thrown to signal that the parser should stop
      *                      parsing the document.
      */
     public void fatalError(String domain, String key, 
  			XMLParseException exception) throws XNIException {
  	DOMError error = new DOMErrorImpl(DOMError.SEVERITY_FATAL_ERROR, exception);
  	fDomErrorHandler.handleError(error);                             
     } // fatalError(String,String,XMLParseException)
      
      
     public boolean handleError(DOMError error) {
         printError(error);
         return eStatus;
     }
      
     /** Prints the error message. */
      
     private void printError(DOMError error) {
  	int severity = -1;
  	fOut.print("[");
  	if ( severity == DOMError.SEVERITY_WARNING){
  		fOut.print("Warning");
  	}else if ( severity == DOMError.SEVERITY_ERROR){
  		fOut.print("Error");
  	}else{
  		fOut.print("Fatal Error");
  		eStatus = false ; //REVISIT: Abort processing if fatal error, do we need to??
  	}
          fOut.print("] ");
  	fOut.print(": ");
  	fOut.print(error.getMessage());
  	fOut.print(':');
          fOut.print(error.getException());		
  	DOMLocator locator = error.getLocation();
  	if (locator != null){
  		fOut.print(":L ");
  	        fOut.print(locator.getLineNumber());
  	        fOut.print(":C ");
  	        fOut.print(locator.getColumnNumber());
  		fOut.print(": ");
  	        fOut.print(locator.getOffset());
  	        fOut.print(": ");
  	        fOut.print(locator.getErrorNode().getNodeName());
  		String systemId = locator.getUri();
  		if (systemId != null) {
  		    int index = systemId.lastIndexOf('/');
  			if (index != -1)
  				systemId = systemId.substring(index + 1);
  		    fOut.print(": ");
  	            fOut.print(systemId);
  		}
  			
  	}
  	fOut.println();
  	fOut.flush();
  
      } // printError(DOMError)
      
  } // class DOMErrorHandlerWrapper
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org