morgand 2003/01/26 00:44:58 Modified: jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate AssertValidTag.java ValidateTag.java VerifierTag.java Log: converted validate taglib from Exception to JellyTagException Revision Changes Path 1.2 +6 -5 jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/AssertValidTag.java Index: AssertValidTag.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/AssertValidTag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AssertValidTag.java 6 Jan 2003 15:46:01 -0000 1.1 +++ AssertValidTag.java 26 Jan 2003 08:44:58 -0000 1.2 @@ -61,6 +61,7 @@ */ package org.apache.commons.jelly.tags.validate; +import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.tags.junit.JellyAssertionFailedError; @@ -101,7 +102,7 @@ */ // Tag interface //------------------------------------------------------------------------- - public void doTag(final XMLOutput output) throws Exception { + public void doTag(final XMLOutput output) throws JellyTagException { buffer.setLength(0); super.doTag(output); } @@ -114,7 +115,7 @@ * Derived classes can overload this method to do different things, such * as to throw assertion exceptions etc. */ - protected void handleValid(boolean valid) throws Exception { + protected void handleValid(boolean valid) { super.handleValid(valid); if ( ! valid ) { 1.2 +33 -21 jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/ValidateTag.java Index: ValidateTag.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/ValidateTag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ValidateTag.java 6 Jan 2003 15:46:01 -0000 1.1 +++ ValidateTag.java 26 Jan 2003 08:44:58 -0000 1.2 @@ -61,6 +61,7 @@ */ package org.apache.commons.jelly.tags.validate; +import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; @@ -95,7 +96,7 @@ // Tag interface //------------------------------------------------------------------------- - public void doTag(final XMLOutput output) throws Exception { + public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException { if ( verifier == null ) { throw new MissingAttributeException("verifier"); } @@ -103,18 +104,24 @@ // evaluate the body using the current Verifier if ( errorHandler != null ) { - // we are redirecting errors to another handler - // so just filter the body - VerifierFilter filter = verifier.getVerifierFilter(); - // now install the current output in the filter chain... - // #### - - ContentHandler handler = filter.getContentHandler(); - handler.startDocument(); - invokeBody( new XMLOutput( handler ) ); - handler.endDocument(); - valid = filter.isValid(); + try { + // we are redirecting errors to another handler + // so just filter the body + VerifierFilter filter = verifier.getVerifierFilter(); + + // now install the current output in the filter chain... + // #### + + ContentHandler handler = filter.getContentHandler(); + handler.startDocument(); + invokeBody( new XMLOutput( handler ) ); + handler.endDocument(); + valid = filter.isValid(); + } + catch (SAXException e) { + throw new JellyTagException(e); + } } else { // outputting the errors to the current output @@ -134,11 +141,16 @@ } ); - VerifierHandler handler = verifier.getVerifierHandler(); - handler.startDocument(); - invokeBody( new XMLOutput( handler ) ); - handler.endDocument(); - valid = handler.isValid(); + try { + VerifierHandler handler = verifier.getVerifierHandler(); + handler.startDocument(); + invokeBody( new XMLOutput( handler ) ); + handler.endDocument(); + valid = handler.isValid(); + } + catch (SAXException e) { + throw new JellyTagException(e); + } } handleValid(valid); } @@ -195,7 +207,7 @@ * Derived classes can overload this method to do different things, such * as to throw assertion exceptions etc. */ - protected void handleValid(boolean valid) throws Exception { + protected void handleValid(boolean valid) { if (var != null ) { Boolean value = (valid) ? Boolean.TRUE : Boolean.FALSE; context.setVariable(var, value); 1.2 +37 -19 jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java Index: VerifierTag.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/validate/src/java/org/apache/commons/jelly/tags/validate/VerifierTag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- VerifierTag.java 6 Jan 2003 15:46:01 -0000 1.1 +++ VerifierTag.java 26 Jan 2003 08:44:58 -0000 1.2 @@ -63,14 +63,17 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.io.IOException; -import org.apache.commons.jelly.JellyException; +import org.apache.commons.jelly.JellyTagException; import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; import org.iso_relax.verifier.Schema; import org.iso_relax.verifier.Verifier; +import org.iso_relax.verifier.VerifierConfigurationException; import org.iso_relax.verifier.VerifierFactory; +import org.xml.sax.SAXException; /** * This tag creates a new Verifier of a schema as a variable @@ -95,7 +98,7 @@ // Tag interface //------------------------------------------------------------------------- - public void doTag(final XMLOutput output) throws Exception { + public void doTag(final XMLOutput output) throws MissingAttributeException, JellyTagException { if ( var == null ) { throw new MissingAttributeException("var"); } @@ -107,7 +110,7 @@ if ( uri != null ) { in = context.getResourceAsStream( uri ); if ( in == null ) { - throw new JellyException( "Could not find resource for uri: " + uri ); + throw new JellyTagException( "Could not find resource for uri: " + uri ); } } else { @@ -116,20 +119,35 @@ in = new ByteArrayInputStream( text.getBytes() ); } - Schema schema = null; - if (systemId != null) { - schema = factory.compileSchema(in, systemId); - } - else if ( uri != null ) { - schema = factory.compileSchema(in, uri); - } - else{ - schema = factory.compileSchema(in); - } - if ( schema == null ) { - throw new JellyException( "Could not create a valid schema" ); + Verifier verifier = null; + try { + Schema schema = null; + if (systemId != null) { + schema = factory.compileSchema(in, systemId); + } + else if ( uri != null ) { + schema = factory.compileSchema(in, uri); + } + else{ + schema = factory.compileSchema(in); + } + + if ( schema == null ) { + throw new JellyTagException( "Could not create a valid schema" ); + } + + verifier = schema.newVerifier(); + } + catch (VerifierConfigurationException e) { + throw new JellyTagException(e); + } + catch (SAXException e) { + throw new JellyTagException(e); + } + catch (IOException e) { + throw new JellyTagException(e); } - Verifier verifier = schema.newVerifier(); + context.setVariable(var, verifier); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>