rdonkin 2003/01/19 15:25:53 Modified: betwixt/src/java/org/apache/commons/betwixt/digester AttributeRule.java ElementRule.java betwixt/src/test/org/apache/commons/betwixt/dotbetwixt TestBeanToXml.java betwixt/xdocs tasks.xml Added: betwixt/src/test/org/apache/commons/betwixt/dotbetwixt BadDotBetwixtNamesBean.betwixt BadDotBetwixtNamesBean.java Log: Added validity check for element and attribute names in .betwixt files. Only certain names are allowed by the XML specification. Now when the name specified in a .betwixt will be checked to make sure it complied with these rules. Revision Changes Path 1.6 +9 -1 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java Index: AttributeRule.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/AttributeRule.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AttributeRule.java 7 Jan 2003 22:32:57 -0000 1.5 +++ AttributeRule.java 19 Jan 2003 23:25:52 -0000 1.6 @@ -61,6 +61,7 @@ import org.apache.commons.betwixt.AttributeDescriptor; import org.apache.commons.betwixt.ElementDescriptor; +import org.apache.commons.betwixt.XMLUtils; import org.apache.commons.betwixt.expression.ConstantExpression; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -95,12 +96,19 @@ * Process the beginning of this element. * * @param attributes The attribute list of this element - * @throws SAXException if the attribute tag is not inside an element tag + * @throws SAXException 1. If the attribute tag is not inside an element tag. + * 2. If the name attribute is not valid XML attribute name. */ public void begin(Attributes attributes) throws SAXException { AttributeDescriptor descriptor = new AttributeDescriptor(); String name = attributes.getValue( "name" ); + + // check that name is well formed + if ( !XMLUtils.isWellFormedXMLName( name ) ) { + throw new SAXException("'" + name + "' would not be a well formed xml attribute name."); + } + descriptor.setQualifiedName( name ); descriptor.setLocalName( name ); String uri = attributes.getValue( "uri" ); 1.7 +8 -1 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java Index: ElementRule.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/digester/ElementRule.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ElementRule.java 7 Jan 2003 22:32:57 -0000 1.6 +++ ElementRule.java 19 Jan 2003 23:25:52 -0000 1.7 @@ -63,6 +63,7 @@ import org.apache.commons.betwixt.ElementDescriptor; import org.apache.commons.betwixt.XMLBeanInfo; +import org.apache.commons.betwixt.XMLUtils; import org.apache.commons.betwixt.expression.ConstantExpression; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -96,10 +97,16 @@ * Process the beginning of this element. * * @param attributes The attribute list of this element - * @throws SAXException when this tag's parent is not either an info or element tag + * @throws SAXException 1. If this tag's parent is not either an info or element tag. + * 2. If the name attribute is not valid XML element name. */ public void begin(Attributes attributes) throws SAXException { String name = attributes.getValue( "name" ); + + // check that name is well formed + if ( !XMLUtils.isWellFormedXMLName( name ) ) { + throw new SAXException("'" + name + "' would not be a well formed xml element name."); + } ElementDescriptor descriptor = new ElementDescriptor(); descriptor.setQualifiedName( name ); 1.8 +21 -4 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java Index: TestBeanToXml.java =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- TestBeanToXml.java 30 Dec 2002 22:45:05 -0000 1.7 +++ TestBeanToXml.java 19 Jan 2003 23:25:52 -0000 1.8 @@ -148,5 +148,22 @@ parseString(xml)); */ } + + /** + * This tests that only well formed names for elements and attributes are allowed by .betwixt files + */ + public void testBadDotBetwixtNames() throws Exception { + // this will work by testing that the output is well formed + + StringWriter out = new StringWriter(); + out.write("<?xml version='1.0' encoding='UTF-8'?>"); + BeanWriter writer = new BeanWriter(out); + writer.write(new BadDotBetwixtNamesBean("one", "two")); + + System.out.println(out.toString()); + + // this should fail if the output is not well formed + parseString(out.toString()); + } } 1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/BadDotBetwixtNamesBean.betwixt Index: BadDotBetwixtNamesBean.betwixt =================================================================== <?xml version='1.0'?> <info primitiveTypes='attribute'> <element name='bean'> <element property='alpha' name='this is trouble'/> <attribute property='beta' name='this is more trouble'/> </element> </info> 1.1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/BadDotBetwixtNamesBean.java Index: BadDotBetwixtNamesBean.java =================================================================== /* * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/BadDotBetwixtNamesBean.java,v 1.1 2003/01/19 23:25:52 rdonkin Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 23:25:52 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2003 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 acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", 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 [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 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. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: BadDotBetwixtNamesBean.java,v 1.1 2003/01/19 23:25:52 rdonkin Exp $ */ package org.apache.commons.betwixt.dotbetwixt; /** * This is a simple bean * * @author Robert Burrell Donkin */ public class BadDotBetwixtNamesBean { //-------------------------- Attributes private String alpha; private String beta; //-------------------------- Constructors public BadDotBetwixtNamesBean() {} public BadDotBetwixtNamesBean(String alpha, String beta) { setAlpha(alpha); setBeta(beta); } //--------------------------- Properties public String getAlpha() { return alpha; } public void setAlpha(String alpha) { this.alpha = alpha; } public String getBeta() { return beta; } public void setBeta(String beta) { this.beta = beta; } } 1.3 +24 -0 jakarta-commons/betwixt/xdocs/tasks.xml Index: tasks.xml =================================================================== RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/tasks.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- tasks.xml 19 Jan 2003 15:52:53 -0000 1.2 +++ tasks.xml 19 Jan 2003 23:25:53 -0000 1.3 @@ -178,6 +178,30 @@ <li> <strong>Created DTD for .betwixt files.</strong> </li> + <li> + <strong>Added validity check for element and attribute names in .betwixt files</strong> + .betwixt files contain names for xml elements and attributes. Only certain names + for elements and attributes are allowed by the xml specification. Betwixt now + check to ensure that the names are appropraite and terminates processing with an + Exception if they are not. + </li> + <li> + <strong>Created XMLUtils</strong> + Separated out basic xml utilty methods into a static utility class called XMLUtils. + This should allow them to be reused in isolation. + </li> + </ul> + </subsection> +</section> +<section name='Deprecated'> + <subsection name='Since 1.0-Alpha Release'> + <ul> + <li> + <code>BeanWriter.escapeAttributeValue()</code> moved into XMLUtils + </li> + <li> + <code>BeanWriter.escapeBodyValue()</code> moved into XMLUtils + </li> </ul> </subsection> </section>
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>