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 2003/01/26 10:19:27 UTC

cvs commit: jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit ActualTag.java AssertDocumentsEqualTag.java ExpectedTag.java XMLUnitTagSupport.java

morgand     2003/01/26 01:19:27

  Modified:    jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit
                        ActualTag.java AssertDocumentsEqualTag.java
                        ExpectedTag.java XMLUnitTagSupport.java
  Log:
  converted xmlunit taglib from Exception to JellyTagException
  
  Revision  Changes    Path
  1.2       +3 -2      jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/ActualTag.java
  
  Index: ActualTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/ActualTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActualTag.java	5 Jan 2003 08:10:57 -0000	1.1
  +++ ActualTag.java	26 Jan 2003 09:19:27 -0000	1.2
  @@ -57,13 +57,14 @@
   
   package org.apache.commons.jelly.tags.xmlunit;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
   import org.dom4j.Document;
   import org.dom4j.io.SAXReader;
   
   public class ActualTag extends XMLUnitTagSupport {
   
  -	public void doTag(XMLOutput output) throws Exception {
  +	public void doTag(XMLOutput output) throws JellyTagException {
   		Document actualDocument = parseBody();
   
   		AssertDocumentsEqualTag assertTag =
  @@ -72,7 +73,7 @@
   		assertTag.setActual(actualDocument);
   	}
   
  -	protected SAXReader createSAXReader() throws Exception {
  +	protected SAXReader createSAXReader() {
   		return new SAXReader();
   	}
   }
  
  
  
  1.2       +22 -4     jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/AssertDocumentsEqualTag.java
  
  Index: AssertDocumentsEqualTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/AssertDocumentsEqualTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AssertDocumentsEqualTag.java	5 Jan 2003 08:10:57 -0000	1.1
  +++ AssertDocumentsEqualTag.java	26 Jan 2003 09:19:27 -0000	1.2
  @@ -57,11 +57,16 @@
   
   package org.apache.commons.jelly.tags.xmlunit;
   
  +import java.io.IOException;
  +import javax.xml.parsers.ParserConfigurationException;
  +
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
   import org.custommonkey.xmlunit.Diff;
   import org.custommonkey.xmlunit.XMLUnit;
   import org.dom4j.Document;
   import org.dom4j.io.SAXReader;
  +import org.xml.sax.SAXException;
   
   /**
    * Compares two XML documents using XMLUnit (http://xmlunit.sourceforge.net/).
  @@ -83,7 +88,7 @@
   	 */
   	private boolean ignoreWhitespace = false;
   
  -	public void doTag(XMLOutput output) throws Exception {
  +	public void doTag(XMLOutput output) throws JellyTagException {
   		invokeBody(output);
   
   		if (actual != null) {
  @@ -109,10 +114,23 @@
   
   		if (actualDocument != null) {
   			XMLUnit.setIgnoreWhitespace(ignoreWhitespace);
  -			Diff delta =
  -				XMLUnit.compare(
  +            
  +			Diff delta = null;
  +            try {
  +				delta = XMLUnit.compare(
   					expectedDocument.asXML(),
   					actualDocument.asXML());
  +            }
  +            catch (SAXException e) {
  +                throw new JellyTagException(e);
  +            }
  +            catch (IOException e) {
  +                throw new JellyTagException(e);
  +            }
  +            catch (ParserConfigurationException e) {
  +                throw new JellyTagException(e);
  +            }
  +            
   			if (delta.identical()) {
   				return;
   			}
  @@ -145,7 +163,7 @@
   		this.ignoreWhitespace = ignoreWhitespace;
   	}
   
  -	protected SAXReader createSAXReader() throws Exception {
  +	protected SAXReader createSAXReader() {
   		return new SAXReader();
   	}
   
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/ExpectedTag.java
  
  Index: ExpectedTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/ExpectedTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExpectedTag.java	5 Jan 2003 08:10:57 -0000	1.1
  +++ ExpectedTag.java	26 Jan 2003 09:19:27 -0000	1.2
  @@ -57,13 +57,14 @@
   
   package org.apache.commons.jelly.tags.xmlunit;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
   import org.dom4j.Document;
   import org.dom4j.io.SAXReader;
   
   public class ExpectedTag extends XMLUnitTagSupport {
   
  -	public void doTag(XMLOutput output) throws Exception {
  +	public void doTag(XMLOutput output) throws JellyTagException {
   		Document expectedDocument = parseBody();
   
   		AssertDocumentsEqualTag assertTag =
  @@ -72,7 +73,7 @@
   		assertTag.setExpected(expectedDocument);
   	}
   
  -	protected SAXReader createSAXReader() throws Exception {
  +	protected SAXReader createSAXReader() {
   		return new SAXReader();
   	}
   
  
  
  
  1.2       +40 -27    jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/XMLUnitTagSupport.java
  
  Index: XMLUnitTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xmlunit/src/java/org/apache/commons/jelly/tags/xmlunit/XMLUnitTagSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XMLUnitTagSupport.java	5 Jan 2003 08:10:57 -0000	1.1
  +++ XMLUnitTagSupport.java	26 Jan 2003 09:19:27 -0000	1.2
  @@ -61,11 +61,14 @@
   import java.io.Reader;
   import java.net.URL;
   
  +import org.apache.commons.jelly.JellyTagException;
   import org.apache.commons.jelly.XMLOutput;
   import org.apache.commons.jelly.tags.junit.AssertTagSupport;
   import org.dom4j.Document;
  +import org.dom4j.DocumentException;
   import org.dom4j.io.SAXContentHandler;
   import org.dom4j.io.SAXReader;
  +import org.xml.sax.SAXException;
   
   public abstract class XMLUnitTagSupport extends AssertTagSupport {
   
  @@ -73,7 +76,7 @@
   	private SAXReader saxReader;
   
   	/** @return the SAXReader used for parsing, creating one lazily if need be  */
  -	public SAXReader getSAXReader() throws Exception {
  +	public SAXReader getSAXReader() {
   		if (saxReader == null) {
   			saxReader = createSAXReader();
   		}
  @@ -88,43 +91,53 @@
   	/**
   	 * Factory method to create a new SAXReader
   	 */
  -	protected abstract SAXReader createSAXReader() throws Exception;
  +	protected abstract SAXReader createSAXReader();
   
   	/**
   	 * Parses the body of this tag and returns the parsed document
   	 */
  -	protected Document parseBody() throws Exception {
  +	protected Document parseBody() throws JellyTagException {
   		SAXContentHandler handler = new SAXContentHandler();
   		XMLOutput newOutput = new XMLOutput(handler);
  -		handler.startDocument();
  -		invokeBody(newOutput);
  -		handler.endDocument();
  +        try {
  +            handler.startDocument();
  +		    invokeBody(newOutput);
  +		    handler.endDocument();
  +        } 
  +        catch (SAXException e) {
  +            throw new JellyTagException(e);
  +        }
   		return handler.getDocument();
   	}
   
   	/**
   	 * Parses the given source
   	 */
  -	protected Document parse(Object source) throws Exception {
  -		if (source instanceof Document) {
  -			return (Document) source;
  -		} else if (source instanceof String) {
  -			String uri = (String) source;
  -			InputStream in = context.getResourceAsStream(uri);
  -			return getSAXReader().read(in, uri);
  -		} else if (source instanceof Reader) {
  -			return getSAXReader().read((Reader) source);
  -		} else if (source instanceof InputStream) {
  -			return getSAXReader().read((InputStream) source);
  -		} else if (source instanceof URL) {
  -			return getSAXReader().read((URL) source);
  -		} else {
  -			throw new IllegalArgumentException(
  -				"Invalid source argument. Must be a Document, String, Reader, InputStream or URL."
  -					+ " Was type: "
  -					+ source.getClass().getName()
  -					+ " with value: "
  -					+ source);
  -		}
  +	protected Document parse(Object source) throws JellyTagException {
  +        try {
  +		    if (source instanceof Document) {
  +		        return (Document) source;
  +		    } else if (source instanceof String) {
  +		    	String uri = (String) source;
  +		    	InputStream in = context.getResourceAsStream(uri);
  +		    	return getSAXReader().read(in, uri);
  +		    } else if (source instanceof Reader) {
  +		    	return getSAXReader().read((Reader) source);
  +		    } else if (source instanceof InputStream) {
  +		    	return getSAXReader().read((InputStream) source);
  +		    } else if (source instanceof URL) {
  +		    	return getSAXReader().read((URL) source);
  +		    } else {
  +		    	throw new IllegalArgumentException(
  +		    		"Invalid source argument. Must be a Document, String, Reader, InputStream or URL."
  +		    			+ " Was type: "
  +		    			+ source.getClass().getName()
  +		    			+ " with value: "
  +		    			+ source);
  +		    }
  +        }
  +        catch (DocumentException e) {
  +            throw new JellyTagException(e);
  +        }
   	}
   }
  
  
  

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