avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl LeadingTrimStringFunction.java TrailingTrimStringFunction.java
Date Mon, 31 Dec 2001 06:59:43 GMT
hammant     01/12/30 22:59:43

  Modified:    apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql
                        SelectColumnHelper.java
  Added:       apps/db/src/java/org/apache/avalon/db/functions/impl
                        LeadingTrimStringFunction.java
                        TrailingTrimStringFunction.java
  Log:
  leading and trailing string functions.
  
  Revision  Changes    Path
  1.5       +10 -2     jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/SelectColumnHelper.java
  
  Index: SelectColumnHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/basic/handlers/lxsql/SelectColumnHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SelectColumnHelper.java	29 Dec 2001 00:33:09 -0000	1.4
  +++ SelectColumnHelper.java	31 Dec 2001 06:59:43 -0000	1.5
  @@ -36,6 +36,8 @@
   import org.apache.avalon.db.functions.impl.MonthIntegerFunction;
   import org.apache.avalon.db.functions.impl.SecondIntegerFunction;
   import org.apache.avalon.db.functions.impl.YearIntegerFunction;
  +import org.apache.avalon.db.functions.impl.LeadingTrimStringFunction;
  +import org.apache.avalon.db.functions.impl.TrailingTrimStringFunction;
   import org.apache.avalon.db.functions.StringFunction;
   import org.apache.avalon.db.functions.NumericFunction;
   import org.w3c.dom.Element;
  @@ -50,7 +52,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class SelectColumnHelper {
   
  @@ -77,7 +79,13 @@
           } else if (nodeName.equals("const")) {
               return getColumnConst(queryable, elem, colHldr);
           } else if (nodeName.equals("trim")) {
  -            return getStringColumnFromStringFunction(queryable, elem, new TrimStringFunction(),
colHldr);
  +            if (elem.getAttribute("type").equals("leading")) {
  +                return getStringColumnFromStringFunction(queryable, elem, new LeadingTrimStringFunction(),
colHldr);
  +            } else if (elem.getAttribute("type").equals("trailing")) {
  +                return getStringColumnFromStringFunction(queryable, elem, new TrailingTrimStringFunction(),
colHldr);
  +            } else {
  +                return getStringColumnFromStringFunction(queryable, elem, new TrimStringFunction(),
colHldr);
  +            }
           } else if (nodeName.equals("lowercase")) {
               return getStringColumnFromStringFunction(queryable, elem, new LowerCaseStringFunction(),
colHldr);
           } else if (nodeName.equals("uppercase")) {
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/LeadingTrimStringFunction.java
  
  Index: LeadingTrimStringFunction.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  import java.util.Locale;
  
  
  /**
   * Class LeadingTrimStringFunction
   *
   * @author Larry McCay <a href="mailto:lawrence_mccay-iii@hp.com">lawrence_mccay-iii@hp.com</a>
   * @version $Revision: 1.1 $
   */
  public class LeadingTrimStringFunction extends AbstractStringFunction {
  
      /**
       * Method getStringValue
       *
       *
       * @param row
       *
       * @return
       *
       */
      public String getStringValue(Row row) {
          return ltrim(((String) mColumns[0].getValue(row)));
      }
  
      /**
       * Method getMaxLength
       *
       *
       * @return
       *
       */
      public int getMaxLength() {
  
          StringColumn sTyp = (StringColumn) mColumns[0];
  
          return sTyp.getMaxLength();
      }
  
      private String ltrim(String value) {
  
          int len = value.length();
          int st = 0;
  
          while ((st < len) && (value.charAt(st) <= ' ')) {
              st++;
          }
  
          return (st > 0) ? value.substring(st, len) : value;
      }
  
      /**
       * Method getMinCols
       *
       *
       * @return
       *
       */
      public int getMinCols() {
          return 1;
      }
  
      /**
       * Method getMaxCols
       *
       *
       * @return
       *
       */
      public int getMaxCols() {
          return 1;
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/functions/impl/TrailingTrimStringFunction.java
  
  Index: TrailingTrimStringFunction.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.functions.impl;
  
  
  
  import org.apache.avalon.db.data.Row;
  import org.apache.avalon.db.data.types.StringColumn;
  import org.apache.avalon.db.functions.StringFunction;
  
  import java.util.Locale;
  
  
  /**
   * Class TrailingTrimStringFunction
   *
   * @author Larry McCay <a href="mailto:lawrence_mccay-iii@hp.com">lawrence_mccay-iii@hp.com</a>
   * @version $Revision: 1.1 $
   */
  public class TrailingTrimStringFunction extends AbstractStringFunction {
  
      /**
       * Method getStringValue
       *
       *
       * @param row
       *
       * @return
       *
       */
      public String getStringValue(Row row) {
          return rtrim(((String) mColumns[0].getValue(row)));
      }
  
      /**
       * Method getMaxLength
       *
       *
       * @return
       *
       */
      public int getMaxLength() {
  
          StringColumn sTyp = (StringColumn) mColumns[0];
  
          return sTyp.getMaxLength();
      }
  
      private String rtrim(String value) {
  
          int len = value.length();
  
          while ((0 < len) && (value.charAt(len - 1) <= ' ')) {
              len--;
          }
  
          return (len < value.length()) ? value.substring(0, len) : value;
      }
  
      /**
       * Method getMinCols
       *
       *
       * @return
       *
       */
      public int getMinCols() {
          return 1;
      }
  
      /**
       * Method getMaxCols
       *
       *
       * @return
       *
       */
      public int getMaxCols() {
          return 1;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message