You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by an...@locus.apache.org on 2000/06/22 20:22:36 UTC

cvs commit: xml-xerces/java/samples/dom/wrappers DOMParser.java Makefile NonValidatingDOMParser.java

andyc       00/06/22 11:22:35

  Modified:    java/samples/dom/wrappers DOMParser.java Makefile
  Removed:     java/samples/dom/wrappers NonValidatingDOMParser.java
  Log:
  Removed NonValidatingDOMParser wrapper class because we are
  adding a more consistent and easier way of setting parser
  features into all of the samples.
  
  This is phase 1. There is still some work left to re-organize
  the features and standard argument processing utilities so
  that they can better be used across DOM and SAX samples.
  Then, the documentation needs to be updated.
  
  Revision  Changes    Path
  1.2       +94 -1     xml-xerces/java/samples/dom/wrappers/DOMParser.java
  
  Index: DOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/wrappers/DOMParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DOMParser.java	1999/11/09 01:13:59	1.1
  +++ DOMParser.java	2000/06/22 18:22:32	1.2
  @@ -57,6 +57,7 @@
   
   package dom.wrappers;
   
  +import dom.Features;
   import dom.DOMParserWrapper;
   
   import org.w3c.dom.Document;
  @@ -70,8 +71,21 @@
    *
    * @version
    */
  -public class DOMParser extends NonValidatingDOMParser {
  +public class DOMParser 
  +    implements DOMParserWrapper, ErrorHandler {
  +
  +    //
  +    // Data
       //
  +
  +    Features feature = null;
  +
  +
  +    /** Parser. */
  +    org.apache.xerces.parsers.DOMParser parser = 
  +        new org.apache.xerces.parsers.DOMParser();
  +
  +    //
       // Constructors
       //
   
  @@ -87,5 +101,84 @@
           parser.setErrorHandler(this);
   
       }
  +
  +    //
  +    // DOMParserWrapper methods
  +    //
  +
  +    /** Parses the specified URI and returns the document. */
  +    public Document parse(String uri) throws Exception {
  +
  +        try {
  +            parser.setFeature( "http://apache.org/xml/features/dom/defer-node-expansion",
  +                             feature.isDeferredDOMSet() );
  +            parser.setFeature( "http://xml.org/sax/features/validation", 
  +                             feature.isValidationSet());
  +            parser.setFeature( "http://xml.org/sax/features/namespaces",
  +                             feature.isNamespaceSet() );
  +            parser.setFeature( "http://apache.org/xml/features/validation/schema",
  +                             feature.isSchemasupportSet() );
  +        } catch (SAXException e) {
  +            System.out.println("error in setting up parser feature");
  +        }
  +
  +        parser.parse(uri);
  +        return parser.getDocument();
  +
  +    } // parse(String):Document
  +
  +    public void setFeatures(Features fea ) {
  +        feature = fea;
  +    }
  +
  +    //
  +    // ErrorHandler methods
  +    //
  +
  +    /** Warning. */
  +    public void warning(SAXParseException ex) {
  +        System.err.println("[Warning] "+
  +                           getLocationString(ex)+": "+
  +                           ex.getMessage());
  +    }
  +
  +    /** Error. */
  +    public void error(SAXParseException ex) {
  +        System.err.println("[Error] "+
  +                           getLocationString(ex)+": "+
  +                           ex.getMessage());
  +    }
  +
  +    /** Fatal error. */
  +    public void fatalError(SAXParseException ex) throws SAXException {
  +        System.err.println("[Fatal Error] "+
  +                           getLocationString(ex)+": "+
  +                           ex.getMessage());
  +        throw ex;
  +    }
  +
  +    //
  +    // Private methods
  +    //
  +
  +    /** Returns a string of the location. */
  +    private String getLocationString(SAXParseException ex) {
  +        StringBuffer str = new StringBuffer();
  +
  +        String systemId = ex.getSystemId();
  +        if (systemId != null) {
  +            int index = systemId.lastIndexOf('/');
  +            if (index != -1) 
  +                systemId = systemId.substring(index + 1);
  +            str.append(systemId);
  +        }
  +        str.append(':');
  +        str.append(ex.getLineNumber());
  +        str.append(':');
  +        str.append(ex.getColumnNumber());
  +
  +        return str.toString();
  +
  +    } // getLocationString(SAXParseException):String
   
   } // class DOMParser
  
  
  
  1.4       +1 -2      xml-xerces/java/samples/dom/wrappers/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/samples/dom/wrappers/Makefile,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Makefile	2000/02/29 02:02:10	1.3
  +++ Makefile	2000/06/22 18:22:33	1.4
  @@ -1,8 +1,7 @@
   # Makefile for directory ./dom/wrappers
   
   TARGETS=\
  -	DOMParser.class\
  -	NonValidatingDOMParser.class
  +	DOMParser.class
   
   DIRS =