axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/utils StringUtils.java
Date Sun, 27 Jun 2004 22:49:17 GMT
dims        2004/06/27 15:49:17

  Modified:    java/src/org/apache/axis/message SOAPHandler.java
               java/src/org/apache/axis/utils StringUtils.java
  Log:
  Fix for AXIS-1403 - calling MessageElement#getChildren with a Text-Only content returns
an empty list
  
  Revision  Changes    Path
  1.16      +23 -0     ws-axis/java/src/org/apache/axis/message/SOAPHandler.java
  
  Index: SOAPHandler.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/message/SOAPHandler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SOAPHandler.java	25 Feb 2004 14:02:43 -0000	1.15
  +++ SOAPHandler.java	27 Jun 2004 22:49:17 -0000	1.16
  @@ -26,16 +26,22 @@
   import org.apache.axis.encoding.TypeMappingRegistry;
   import org.apache.axis.soap.SOAPConstants;
   import org.apache.axis.utils.Messages;
  +import org.apache.axis.utils.StringUtils;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.DefaultHandler;
   
  +import javax.xml.soap.SOAPException;
  +import java.io.CharArrayWriter;
  +
   public class SOAPHandler extends DefaultHandler
   {
       public MessageElement myElement = null;
       private MessageElement[] myElements;
       private int myIndex = 0;
   
  +    private final CharArrayWriter val = new CharArrayWriter();
  +    
       public SOAPHandler() {
       }
   
  @@ -106,6 +112,19 @@
           throws SAXException
       {
           if (myElement != null) {
  +
  +            if (val.size() > 0) {
  +                String s = StringUtils.strip(val.toString());
  +                val.reset();
  +                if(s.length()>0){
  +                    try {
  +                        myElement.addTextNode(s);
  +                    } catch (SOAPException e) {
  +                        throw new SAXException(e);
  +                    }
  +                }
  +            }
  +
               if (myElements != null) {
                   myElements[myIndex] = myElement;
               }
  @@ -128,5 +147,9 @@
                              DeserializationContext context)
           throws SAXException
       {
  +    }
  +
  +    public void characters(char[] chars, int start, int end) throws SAXException {
  +        val.write(chars, start, end);
       }
   }
  
  
  
  1.5       +174 -0    ws-axis/java/src/org/apache/axis/utils/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/StringUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StringUtils.java	14 May 2004 12:56:13 -0000	1.4
  +++ StringUtils.java	27 Jun 2004 22:49:17 -0000	1.5
  @@ -114,4 +114,178 @@
           }
           return (String[]) list.toArray(new String[list.size()]);
       }
  +
  +    // Empty checks
  +    //-----------------------------------------------------------------------
  +    /**
  +     * <p>Checks if a String is empty ("") or null.</p>
  +     *
  +     * <pre>
  +     * StringUtils.isEmpty(null)      = true
  +     * StringUtils.isEmpty("")        = true
  +     * StringUtils.isEmpty(" ")       = false
  +     * StringUtils.isEmpty("bob")     = false
  +     * StringUtils.isEmpty("  bob  ") = false
  +     * </pre>
  +     *
  +     * <p>NOTE: This method changed in Lang version 2.0.
  +     * It no longer trims the String.
  +     * That functionality is available in isBlank().</p>
  +     *
  +     * @param str  the String to check, may be null
  +     * @return <code>true</code> if the String is empty or null
  +     */
  +    public static boolean isEmpty(String str) {
  +        return (str == null || str.length() == 0);
  +    }
  +    
  +    // Stripping
  +    //-----------------------------------------------------------------------
  +    /**
  +     * <p>Strips whitespace from the start and end of a String.</p>
  +     *
  +     * <p>This removes whitespace. Whitespace is defined by 
  +     * {@link Character#isWhitespace(char)}.</p>
  +     *
  +     * <p>A <code>null</code> input String returns <code>null</code>.</p>
  +     *
  +     * <pre>
  +     * StringUtils.strip(null)     = null
  +     * StringUtils.strip("")       = ""
  +     * StringUtils.strip("   ")    = ""
  +     * StringUtils.strip("abc")    = "abc"
  +     * StringUtils.strip("  abc")  = "abc"
  +     * StringUtils.strip("abc  ")  = "abc"
  +     * StringUtils.strip(" abc ")  = "abc"
  +     * StringUtils.strip(" ab c ") = "ab c"
  +     * </pre>
  +     *
  +     * @param str  the String to remove whitespace from, may be null
  +     * @return the stripped String, <code>null</code> if null String input
  +     */
  +    public static String strip(String str) {
  +        return strip(str, null);
  +    }
  +    
  +    /**
  +     * <p>Strips any of a set of characters from the start and end of a String.
  +     * This is similar to {@link String#trim()} but allows the characters
  +     * to be stripped to be controlled.</p>
  +     *
  +     * <p>A <code>null</code> input String returns <code>null</code>.
  +     * An empty string ("") input returns the empty string.</p>
  +     *
  +     * <p>If the stripChars String is <code>null</code>, whitespace is
  +     * stripped as defined by {@link Character#isWhitespace(char)}.
  +     * Alternatively use {@link #strip(String)}.</p>
  +     *
  +     * <pre>
  +     * StringUtils.strip(null, *)          = null
  +     * StringUtils.strip("", *)            = ""
  +     * StringUtils.strip("abc", null)      = "abc"
  +     * StringUtils.strip("  abc", null)    = "abc"
  +     * StringUtils.strip("abc  ", null)    = "abc"
  +     * StringUtils.strip(" abc ", null)    = "abc"
  +     * StringUtils.strip("  abcyx", "xyz") = "  abc"
  +     * </pre>
  +     *
  +     * @param str  the String to remove characters from, may be null
  +     * @param stripChars  the characters to remove, null treated as whitespace
  +     * @return the stripped String, <code>null</code> if null String input
  +     */
  +    public static String strip(String str, String stripChars) {
  +        if (isEmpty(str)) {
  +            return str;
  +        }
  +        str = stripStart(str, stripChars);
  +        return stripEnd(str, stripChars);
  +    }
  +
  +    /**
  +     * <p>Strips any of a set of characters from the start of a String.</p>
  +     *
  +     * <p>A <code>null</code> input String returns <code>null</code>.
  +     * An empty string ("") input returns the empty string.</p>
  +     *
  +     * <p>If the stripChars String is <code>null</code>, whitespace is
  +     * stripped as defined by {@link Character#isWhitespace(char)}.</p>
  +     *
  +     * <pre>
  +     * StringUtils.stripStart(null, *)          = null
  +     * StringUtils.stripStart("", *)            = ""
  +     * StringUtils.stripStart("abc", "")        = "abc"
  +     * StringUtils.stripStart("abc", null)      = "abc"
  +     * StringUtils.stripStart("  abc", null)    = "abc"
  +     * StringUtils.stripStart("abc  ", null)    = "abc  "
  +     * StringUtils.stripStart(" abc ", null)    = "abc "
  +     * StringUtils.stripStart("yxabc  ", "xyz") = "abc  "
  +     * </pre>
  +     *
  +     * @param str  the String to remove characters from, may be null
  +     * @param stripChars  the characters to remove, null treated as whitespace
  +     * @return the stripped String, <code>null</code> if null String input
  +     */
  +    public static String stripStart(String str, String stripChars) {
  +        int strLen;
  +        if (str == null || (strLen = str.length()) == 0) {
  +            return str;
  +        }
  +        int start = 0;
  +        if (stripChars == null) {
  +            while ((start != strLen) && Character.isWhitespace(str.charAt(start)))
{
  +                start++;
  +            }
  +        } else if (stripChars.length() == 0) {
  +            return str;
  +        } else {
  +            while ((start != strLen) && (stripChars.indexOf(str.charAt(start))
!= -1)) {
  +                start++;
  +            }
  +        }
  +        return str.substring(start);
  +    }
  +
  +    /**
  +     * <p>Strips any of a set of characters from the end of a String.</p>
  +     *
  +     * <p>A <code>null</code> input String returns <code>null</code>.
  +     * An empty string ("") input returns the empty string.</p>
  +     *
  +     * <p>If the stripChars String is <code>null</code>, whitespace is
  +     * stripped as defined by {@link Character#isWhitespace(char)}.</p>
  +     *
  +     * <pre>
  +     * StringUtils.stripEnd(null, *)          = null
  +     * StringUtils.stripEnd("", *)            = ""
  +     * StringUtils.stripEnd("abc", "")        = "abc"
  +     * StringUtils.stripEnd("abc", null)      = "abc"
  +     * StringUtils.stripEnd("  abc", null)    = "  abc"
  +     * StringUtils.stripEnd("abc  ", null)    = "abc"
  +     * StringUtils.stripEnd(" abc ", null)    = " abc"
  +     * StringUtils.stripEnd("  abcyx", "xyz") = "  abc"
  +     * </pre>
  +     *
  +     * @param str  the String to remove characters from, may be null
  +     * @param stripChars  the characters to remove, null treated as whitespace
  +     * @return the stripped String, <code>null</code> if null String input
  +     */
  +    public static String stripEnd(String str, String stripChars) {
  +        int end;
  +        if (str == null || (end = str.length()) == 0) {
  +            return str;
  +        }
  +
  +        if (stripChars == null) {
  +            while ((end != 0) && Character.isWhitespace(str.charAt(end - 1))) {
  +                end--;
  +            }
  +        } else if (stripChars.length() == 0) {
  +            return str;
  +        } else {
  +            while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1))
{
  +                end--;
  +            }
  +        }
  +        return str.substring(0, end);
  +    }
   }
  
  
  

Mime
View raw message