You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mo...@apache.org on 2002/10/16 18:18:43 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml TestXMLValidation.java

morgand     2002/10/16 09:18:43

  Modified:    jelly/src/java/org/apache/commons/jelly/parser
                        XMLParser.java
               jelly/src/test/org/apache/commons/jelly/test/xml
                        TestXMLValidation.java
  Log:
  XMLParser.error(SAXParseException) and XMLParser.fatalError(SAXParseException)
  [but not XMLParser.warning(SAXParseException)] will now throw
  a SAXException by default when no error handler is supplied.  As a result,
  invalid Jelly scripts will now fail when validation is enabled by
  Jelly.setValidateXML(boolean).
  
  Revision  Changes    Path
  1.34      +14 -8     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java
  
  Index: XMLParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/parser/XMLParser.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- XMLParser.java	16 Oct 2002 12:45:52 -0000	1.33
  +++ XMLParser.java	16 Oct 2002 16:18:42 -0000	1.34
  @@ -858,7 +858,7 @@
   
       /**
        * Forward notification of a parsing error to the application supplied
  -     * error handler (if any).
  +     * error handler, if any, otherwise throw a SAXException with the error.
        *
        * @param exception The error information
        *
  @@ -875,12 +875,14 @@
               exception);
           if (errorHandler != null) {
               errorHandler.error(exception);
  +        } else {
  +            throw exception;
           }
       }
   
       /**
        * Forward notification of a fatal parsing error to the application
  -     * supplied error handler (if any).
  +     * supplied error handler, if any, otherwise throw a SAXException with the error.
        *
        * @param exception The fatal error information
        *
  @@ -897,12 +899,16 @@
               exception);
           if (errorHandler != null) {
               errorHandler.fatalError(exception);
  +        } else {
  +            throw exception;        
           }
       }
   
       /**
        * Forward notification of a parse warning to the application supplied
  -     * error handler (if any).
  +     * error handler (if any).  Unlike XMLParser.error(SAXParseException) and
  +     * XMLParser.fatalError(SAXParseException), this implementation will
  +     * NOT throw a SAXException by default if no error handler is supplied.
        *
        * @param exception The warning information
        *
  
  
  
  1.2       +10 -7     jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml/TestXMLValidation.java
  
  Index: TestXMLValidation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml/TestXMLValidation.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLValidation.java	14 Oct 2002 19:17:01 -0000	1.1
  +++ TestXMLValidation.java	16 Oct 2002 16:18:42 -0000	1.2
  @@ -73,6 +73,8 @@
   import org.apache.commons.jelly.Script;
   import org.apache.commons.jelly.XMLOutput;
   
  +import org.xml.sax.SAXParseException;
  +
   /**
    * A test to confirm that invalid documents are
    * reject iff jelly.setValidateXML(true)
  @@ -132,10 +134,11 @@
           // with validation
           setUp("invalidScript1.jelly");
           jelly.setValidateXML(true);
  -        Script script = jelly.compileScript();
  -        script.run(context,xmlOutput);
  -        assertTrue("should have set 'foo' variable to 'bar'",
  -                   context.getVariable("foo").equals("bar"));
  +        try {
  +            Script script = jelly.compileScript();
  +            fail("Invalid scripts should throw SAXParseException on parse");
  +        } catch (SAXParseException e) {
  +        }
       }
   
       public void testValidXML1Validation()throws Exception {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>