cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl DecimalType.java DecimalTypeBuilder.java
Date Fri, 25 Jul 2003 16:21:31 GMT
bruno       2003/07/25 09:21:31

  Added:       src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor
                        FormattingDecimalConvertor.java
                        FormattingDecimalConvertorBuilder.java
                        FormattingLongConvertor.java
                        FormattingLongConvertorBuilder.java
                        PlainDecimalConvertor.java
                        PlainDecimalConvertorBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl
                        DecimalType.java DecimalTypeBuilder.java
  Log:
  initial commit
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingDecimalConvertor.java
  
  Index: FormattingDecimalConvertor.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  import org.outerj.i18n.I18nSupport;
  import org.outerj.i18n.DecimalFormat;
  
  import java.util.Locale;
  import java.text.ParseException;
  import java.math.BigDecimal;
  import java.math.BigInteger;
  
  /**
   * A Convertor for {@link BigDecimal}s backed by the
   * {@link java.text.DecimalFormat DecimalFormat} class.
   *
   * <p>It can be configured to use one of these variants: integer,
   * number, currency or percent.
   *
   * <p>Alternatively, a <strong>formatting pattern</strong> can be used.
This can either be a locale-dependent
   * or locale-independent formatting pattern. When looking up a formatting pattern, a mechansim
   * similar to resource bundle lookup is used. Suppose the locale is nl-BE, then first a
formatting
   * pattern for nl-BE will be sought, then one for nl, and if that is not
   * found, finally the locale-independent formatting pattern will be used.
   *
   * <p>Note: the earlier statement about the fact that this class uses java.text.DecimalFormat
   * is not entirely correct. In fact, it uses a small wrapper class that will either delegate
to
   * java.text.DecimalFormat or com.ibm.icu.text.DecimalFormat. The com.ibm version will automatically
   * be used if it is present on the classpath, otherwise the java.text version will be used.
   */
  public class FormattingDecimalConvertor implements Convertor {
      private int variant;
      /** Locale-specific formatting patterns. */
      private LocaleMap localizedPatterns;
      /** Non-locale specific formatting pattern. */
      private String nonLocalizedPattern;
  
      public static final int INTEGER = 0;
      public static final int NUMBER = 1;
      public static final int CURRENCY = 2;
      public static final int PERCENT = 3;
  
      public FormattingDecimalConvertor() {
          this.variant = getDefaultVariant();
          this.localizedPatterns = new LocaleMap();
      }
  
      protected int getDefaultVariant() {
          return NUMBER;
      }
  
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache)
{
          DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
          try {
              Number decimalValue = decimalFormat.parse(value);
              if (decimalValue instanceof BigDecimal)
                  ;
              else if (decimalValue instanceof Long)
                  decimalValue = new BigDecimal(decimalValue.longValue());
              else if (decimalValue instanceof Double)
                  decimalValue = new BigDecimal(decimalValue.doubleValue());
              else if (decimalValue instanceof BigInteger)
                  decimalValue = new BigDecimal((BigInteger)decimalValue);
              else
                  return null;
  
              return decimalValue;
          } catch (ParseException e) {
              return null;
          }
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache)
{
          DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
          return decimalFormat.format(value);
      }
  
      protected final DecimalFormat getDecimalFormat(Locale locale, Convertor.FormatCache
formatCache) {
          DecimalFormat decimalFormat = null;
          if (formatCache != null)
              decimalFormat = (DecimalFormat)formatCache.get();
          if (decimalFormat == null) {
              decimalFormat = getDecimalFormat(locale);
              if (formatCache != null)
                  formatCache.store(decimalFormat);
          }
          return decimalFormat;
      }
  
      private DecimalFormat getDecimalFormat(Locale locale) {
          DecimalFormat decimalFormat = null;
  
          switch (variant) {
              case INTEGER:
                  decimalFormat = I18nSupport.getInstance().getIntegerFormat(locale);
                  break;
              case NUMBER:
                  decimalFormat = I18nSupport.getInstance().getNumberFormat(locale);
                  break;
              case CURRENCY:
                  decimalFormat = I18nSupport.getInstance().getCurrencyFormat(locale);
                  break;
              case PERCENT:
                  decimalFormat = I18nSupport.getInstance().getPercentFormat(locale);
                  break;
          }
  
          String pattern = (String)localizedPatterns.get(locale);
  
          if (pattern != null)
              decimalFormat.applyLocalizedPattern(pattern);
          else if (nonLocalizedPattern != null)
              decimalFormat.applyPattern(nonLocalizedPattern);
  
          return decimalFormat;
      }
  
      public void setVariant(int variant) {
          if (variant != INTEGER && variant != NUMBER && variant != CURRENCY
&& variant != PERCENT)
              throw new IllegalArgumentException("Invalid value for variant parameter.");
          this.variant = variant;
      }
  
      public void addFormattingPattern(Locale locale, String pattern) {
          localizedPatterns.put(locale, pattern);
      }
  
      public void setNonLocalizedPattern(String pattern) {
          this.nonLocalizedPattern = pattern;
      }
  
      public Class getTypeClass() {
          return java.math.BigDecimal.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingDecimalConvertorBuilder.java
  
  Index: FormattingDecimalConvertorBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  import org.w3c.dom.Element;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.i18n.I18nUtils;
  
  import java.util.Locale;
  
  /**
   * Builds {@link FormattingDecimalConvertor}s.
   */
  public class FormattingDecimalConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) throws Exception {
          FormattingDecimalConvertor convertor = createConvertor();
  
          if (configElement == null)
              return convertor;
  
          String variant = configElement.getAttribute("variant");
          if (!variant.equals("")) {
              if (variant.equals("integer"))
                  convertor.setVariant(FormattingDecimalConvertor.INTEGER);
              else if (variant.equals("number"))
                  convertor.setVariant(FormattingDecimalConvertor.NUMBER);
              else if (variant.equals("percent"))
                  convertor.setVariant(FormattingDecimalConvertor.PERCENT);
              else if (variant.equals("currency"))
                  convertor.setVariant(FormattingDecimalConvertor.CURRENCY);
              else
                  throw new Exception("Invalid value \"" + variant + "\" for variant attribute
at " + DomHelper.getLocation(configElement));
          }
  
          Element patternsEl = DomHelper.getChildElement(configElement, Constants.WD_NS, "patterns",
false);
          if (patternsEl != null) {
              Element patternEl[] = DomHelper.getChildElements(patternsEl, Constants.WD_NS,
"pattern");
              for (int i = 0; i < patternEl.length; i++) {
                  String locale = patternEl[i].getAttribute("locale");
                  String pattern = DomHelper.getElementText(patternEl[i]);
                  if (pattern.equals(""))
                      throw new Exception("pattern element does not contain any content at
" + DomHelper.getLocation(patternEl[i]));
                  if (locale.equals(""))
                      convertor.setNonLocalizedPattern(pattern);
                  else {
                      Locale loc = I18nUtils.parseLocale(locale);
                      convertor.addFormattingPattern(loc, pattern);
                  }
              }
          }
  
          return convertor;
      }
  
      protected FormattingDecimalConvertor createConvertor() {
          return new FormattingDecimalConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingLongConvertor.java
  
  Index: FormattingLongConvertor.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  import org.outerj.i18n.DecimalFormat;
  
  import java.util.Locale;
  import java.text.ParseException;
  
  /**
   * A Convertor for {@link Long}s backed by the
   * {@link java.text.DecimalFormat DecimalFormat} class.
   *
   * <p>This class is mostly the same as the {@link FormattingDecimalConvertor},
   * so see there for more information.
   */
  public class FormattingLongConvertor extends FormattingDecimalConvertor {
  
      public FormattingLongConvertor() {
          super();
      }
  
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache)
{
          DecimalFormat decimalFormat = getDecimalFormat(locale, formatCache);
          try {
              Number decimalValue = decimalFormat.parse(value);
              if (decimalValue instanceof Long)
                  return decimalValue;
              else
                  return new Long(decimalValue.longValue());
          } catch (ParseException e) {
              return null;
          }
      }
  
      protected int getDefaultVariant() {
          return INTEGER;
      }
  
      public Class getTypeClass() {
          return Long.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingLongConvertorBuilder.java
  
  Index: FormattingLongConvertorBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  /**
   * Builds {@link FormattingLongConvertor}s.
   */
  public class FormattingLongConvertorBuilder extends FormattingDecimalConvertorBuilder {
      protected FormattingDecimalConvertor createConvertor() {
          return new FormattingLongConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainDecimalConvertor.java
  
  Index: PlainDecimalConvertor.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  import java.util.Locale;
  import java.math.BigDecimal;
  
  /**
   * Convertor for java.math.BigDecimals that does not do any (Locale-dependent)
   * formatting.
   */
  public class PlainDecimalConvertor implements Convertor {
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache)
{
          try {
              return new BigDecimal(value);
          } catch (NumberFormatException e) {
              return null;
          }
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache)
{
          return value.toString();
      }
  
      public Class getTypeClass() {
          return BigDecimal.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainDecimalConvertorBuilder.java
  
  Index: PlainDecimalConvertorBuilder.java
  ===================================================================
  package org.apache.cocoon.woody.datatype.convertor;
  
  import org.w3c.dom.Element;
  
  public class PlainDecimalConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) throws Exception {
          return new PlainDecimalConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/DecimalType.java
  
  Index: DecimalType.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  /**
   * A {@link org.apache.cocoon.woody.datatype.Datatype Datatype} implementation
   * for decimal numbers (backed by the java.math.BigDecimal class).
   */
  public class DecimalType extends AbstractDatatype {
      public Class getTypeClass() {
          return java.math.BigDecimal.class;
      }
  
      public String getDescriptiveName() {
          return "decimal";
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/DecimalTypeBuilder.java
  
  Index: DecimalTypeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.datatype.DatatypeManager;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link DecimalType}s.
   */
  public class DecimalTypeBuilder extends AbstractDatatypeBuilder {
      public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager)
throws Exception {
          DecimalType type = new DecimalType();
          type.setArrayType(arrayType);
          type.setBuilder(this);
  
          buildValidationRules(datatypeElement, type, datatypeManager);
          buildConvertor(datatypeElement, type);
          buildSelectionList(datatypeElement, type);
  
          return type;
      }
  }
  
  
  

Mime
View raw message