commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/xdocs tasks.xml
Date Mon, 08 Sep 2003 21:41:48 GMT
rdonkin     2003/09/08 14:41:48

  Modified:    betwixt/src/java/org/apache/commons/betwixt/strategy
                        DefaultNameMapper.java
               betwixt/src/java/org/apache/commons/betwixt XMLUtils.java
               betwixt/xdocs tasks.xml
  Added:       betwixt/src/java/org/apache/commons/betwixt/strategy
                        BadCharacterReplacingNMapper.java
  Log:
  Added new NameMapper which corrects character which are not legal in XML. Also changed DefaultNameMapper
so that this mapper is delegated to.
  
  Revision  Changes    Path
  1.4       +27 -8     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/DefaultNameMapper.java
  
  Index: DefaultNameMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/DefaultNameMapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultNameMapper.java	6 Jan 2003 22:50:45 -0000	1.3
  +++ DefaultNameMapper.java	8 Sep 2003 21:41:48 -0000	1.4
  @@ -72,13 +72,32 @@
    */
   public class DefaultNameMapper implements NameMapper {
   
  +    /** Used to convert bad character in the name */
  +    private static final BadCharacterReplacingNMapper badCharacterReplacementNMapper 
  +        = new BadCharacterReplacingNMapper( new PlainMapper() );
  +    
  +    /** Base implementation chained by bad character replacement mapper */
  +    private static final class PlainMapper implements NameMapper {
  +        /**
  +        * This implementation returns the parameter passed in without modification.
  +        *  
  +        * @param typeName the string to convert 
  +        * @return the typeName parameter without modification
  +        */
  +        public String mapTypeToElementName( String typeName ) {
  +            return typeName ;
  +        }  
  +    }
  +
       /**
  -     * This implementation returns the parameter passed in without modification.
  +     * This implementation returns the parameter passed after
  +     * deleting any characters which the XML specification does not allow
  +     * in element names.
        *  
        * @param typeName the string to convert 
        * @return the typeName parameter without modification
        */
  -    public String mapTypeToElementName(String typeName) {
  -        return typeName;
  +    public String mapTypeToElementName( String typeName ) {
  +        return badCharacterReplacementNMapper.mapTypeToElementName( typeName );
       }
   }
  
  
  
  1.1                  jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/BadCharacterReplacingNMapper.java
  
  Index: BadCharacterReplacingNMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/strategy/BadCharacterReplacingNMapper.java,v
1.1 2003/09/08 21:41:48 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/09/08 21:41:48 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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 apache@apache.org.
   *
   * 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: BadCharacterReplacingNMapper.java,v 1.1 2003/09/08 21:41:48 rdonkin Exp $
   */
  package org.apache.commons.betwixt.strategy;
  
  import org.apache.commons.betwixt.XMLUtils;
  
  /**
   * <code>NameMapper</code> implementation that processes a name by replacing
or stripping
   * illegal characters before passing result down the chain.
   * 
   * @author Robert Burrell Donkin
   * @version $Revision: 1.1 $
   */
  public class BadCharacterReplacingNMapper implements NameMapper {
      /** Next mapper in chain, possibly null */
      private NameMapper chainedMapper;
      /** Replacement character, possibly null */
      private Character replacement = null;
      
      /**
        * Constructs a replacing mapper which delegates to given mapper.
        * @param chainedMapper next link in processing chain, possibly null
        */
      public BadCharacterReplacingNMapper(NameMapper chainedMapper) {
          this.chainedMapper = chainedMapper;
      }	
  
      /**
        * Gets the character that should be used to replace bad characters
        * if null then bad characters will be deleted.
        * @return the replacement Character possibly null
        */
      public Character getReplacement() {
          return replacement;
      }
      
      /**
        * Sets the character that should be used to replace bad characters.
        * @param replacement the Charcter to be used for replacement if not null.
        * Otherwise, indicates that illegal characters should be deleted.
        */
      public void setReplacement( Character replacement ) {
          this.replacement = replacement;
      } 
  
      /**
       * This implementation processes characters which are not allowed in xml
       * element names and then returns the result from the next link in the chain.
       * This processing consists of deleting them if no replacement character
       * has been set. 
       * Otherwise, the character will be replaced.
       *  
       * @param typeName the string to convert 
       * @return the processed input
       */
      public String mapTypeToElementName(String typeName) {
          
          StringBuffer buffer = new StringBuffer( typeName );
          for (int i=0, size = buffer.length(); i< size; i++) {
              char nextChar = buffer.charAt( i );
              boolean bad = false;
              if ( i==0 ) {
                  bad = !XMLUtils.isNameStartChar( nextChar );
              } else {
                  bad = !XMLUtils.isNameChar( nextChar );
              }
                  
              if (bad) {
                  if ( replacement != null ) {
                      buffer.setCharAt( i, replacement.charValue() );
                  } else {
                      // delete
                      buffer.deleteCharAt( i );
                      i--;
                      size--;
                  }
              }
          }
          
          if ( buffer.length() == 0 ) {
              throw new IllegalArgumentException(
  "Element name contains no legal characters and no replacements have been set.");
          }
          
          typeName = buffer.toString();
          
          if ( chainedMapper == null ) {
              return typeName;
          }
          return chainedMapper.mapTypeToElementName( typeName );
      }
  }
  
  
  
  1.5       +9 -9      jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/XMLUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XMLUtils.java	26 May 2003 10:46:57 -0000	1.4
  +++ XMLUtils.java	8 Sep 2003 21:41:48 -0000	1.5
  @@ -400,14 +400,14 @@
           }
           
           char ch = name.charAt(0);
  -        if( isNameStart(ch) == false) {
  +        if( isNameStartChar(ch) == false) {
              return false;
              
           }
           
           for (int i = 1; i < name.length(); i++ ) {
              ch = name.charAt(i);
  -           if( isName( ch ) == false ) {
  +           if( isNameChar( ch ) == false ) {
                 return false;
              }
           }
  @@ -421,7 +421,7 @@
        * @param c The character to check.
        * @return true if this is an XML name character
        */
  -    private static boolean isName(int c) {
  +    public static boolean isNameChar(int c) {
           return c < 0x10000 && (CHARS[c] & MASK_NAME) != 0;
       }
       
  @@ -432,7 +432,7 @@
        * @param c The character to check.
        * @return trus if this is an XML name start character
        */
  -    private static boolean isNameStart(int c) {
  +    public static boolean isNameStartChar(int c) {
           return c < 0x10000 && (CHARS[c] & MASK_NAME_START) != 0;
       }
   }
  
  
  
  1.24      +3 -0      jakarta-commons/betwixt/xdocs/tasks.xml
  
  Index: tasks.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/tasks.xml,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- tasks.xml	8 Sep 2003 14:05:38 -0000	1.23
  +++ tasks.xml	8 Sep 2003 21:41:48 -0000	1.24
  @@ -261,6 +261,9 @@
   <strong>Improved Support For Interfaces including Entity Beans (ClassNormalizer)</strong>
   Added ClassNormalizer strategy. This allows the Class introspector to differ from that
of the Object.
               </li>
  +            <li>
  +<strong>Added Support For Replacement Of Bad Characters</strong> to default
mapping of element names.
  +            </li>
           </ul>
       </subsection>
   </section>
  
  
  

Mime
View raw message