You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2003/07/15 16:06:17 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor Convertor.java ConvertorBuilder.java DefaultFormatCache.java DummyStringConvertor.java DummyStringConvertorBuilder.java FormattingDateConvertor.java FormattingDateConvertorBuilder.java LocaleMap.java MillisDateConvertor.java MillisDateConvertorBuilder.java PlainLongConvertor.java PlainLongConvertorBuilder.java package.html

bruno       2003/07/15 07:06:17

  Added:       src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl
                        DateType.java DateTypeBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/util
                        SimpleServiceSelector.java
               src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor
                        Convertor.java ConvertorBuilder.java
                        DefaultFormatCache.java DummyStringConvertor.java
                        DummyStringConvertorBuilder.java
                        FormattingDateConvertor.java
                        FormattingDateConvertorBuilder.java LocaleMap.java
                        MillisDateConvertor.java
                        MillisDateConvertorBuilder.java
                        PlainLongConvertor.java
                        PlainLongConvertorBuilder.java package.html
  Log:
  initial commit
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/DateType.java
  
  Index: DateType.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import java.util.Date;
  
  /**
   * A {@link org.apache.cocoon.woody.datatype.Datatype} implementation for
   * java.util.Date's (so includes a time-component).
   */
  public class DateType extends AbstractDatatype {
  
      public Class getTypeClass() {
          return Date.class;
      }
  
      public String getDescriptiveName() {
          return "date";
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/DateTypeBuilder.java
  
  Index: DateTypeBuilder.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  <st...@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 DateType}s.
   */
  public class DateTypeBuilder extends AbstractDatatypeBuilder {
      public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
          DateType type = new DateType();
          type.setArrayType(arrayType);
          type.setBuilder(this);
  
          buildValidationRules(datatypeElement, type, datatypeManager);
          buildConvertor(datatypeElement, type);
          buildSelectionList(datatypeElement, type);
  
          return type;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/SimpleServiceSelector.java
  
  Index: SimpleServiceSelector.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.util;
  
  import org.apache.avalon.framework.service.ServiceSelector;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.cocoon.components.LifecycleHelper;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * A very simple ServiceSelector for ThreadSafe services.
   */
  public class SimpleServiceSelector extends AbstractLogEnabled implements ServiceSelector, Configurable, LogEnabled, Composable {
      private final String hintShortHand;
      private final Class componentClass;
      private Map components = new HashMap();
      private ComponentManager componentManager;
  
      public SimpleServiceSelector(String hintShortHand, Class componentClass) {
          this.hintShortHand = hintShortHand;
          this.componentClass = componentClass;
      }
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.componentManager = componentManager;
      }
  
      public void configure(Configuration configuration) throws ConfigurationException {
          Configuration[] componentConfs = configuration.getChildren(hintShortHand);
          for (int i = 0; i < componentConfs.length; i++) {
              String name = componentConfs[i].getAttribute("name");
              String src = componentConfs[i].getAttribute("src");
  
              Class clazz = null;
              try {
                  clazz = Class.forName(src);
              } catch (ClassNotFoundException e) {
                  throw new ConfigurationException("Class not found: " + src + ", declared at " + componentConfs[i].getLocation(), e);
              }
  
              if (!componentClass.isAssignableFrom(clazz))
                  throw new ConfigurationException("The class \"" + src + "\" is of an incorrect type, it should implement or exted " + componentClass.getName());
  
              Object component = null;
              try {
                  component = clazz.newInstance();
                  LifecycleHelper lifecycleHelper = new LifecycleHelper(getLogger(), null, componentManager, null, null, componentConfs[i]);
                  lifecycleHelper.setupComponent(component);
              } catch (Exception e) {
                  throw new ConfigurationException("Error creating " + hintShortHand + " declared at " + componentConfs[i], e);
              }
  
              components.put(name, component);
          }
      }
  
      public Object select(Object hint) throws ServiceException {
          if (!isSelectable(hint))
              throw new ServiceException((String)hint, "Non-existing component for this hint");
          String stringHint = (String)hint;
          return components.get(stringHint);
      }
  
      public boolean isSelectable(Object hint) {
          String stringHint = (String)hint;
          return components.containsKey(stringHint);
      }
  
      public void release(Object o) {
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/Convertor.java
  
  Index: Convertor.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  <st...@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;
  
  /**
   * The purpose of a Convertor is to convert between Object and String
   * representations of the same thing. For example, convert
   * {@link Long}s or {@link java.util.Date Date}s to strings, and vice
   * versa. The behaviour of this conversion process can depend on the
   * user's Locale.
   *
   * <p>If you need to do mass conversion of a lot of values, it may be
   * beneficial to pass a {@link FormatCache} object to the convert methods.
   * Some convertors need to build and configure parser or formatting objects,
   * which can be expensive if it needs to be done repeatedly.
   */
  public interface Convertor {
      /**
       * Returns null if conversion failes.
       *
       * @param formatCache can be null if not needed
       */
      public Object convertFromString(String value, Locale locale, FormatCache formatCache);
  
      public String convertToString(Object value, Locale locale, FormatCache formatCache);
  
      public Class getTypeClass();
  
      public interface FormatCache {
          public Object get();
          public void store(Object object);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/ConvertorBuilder.java
  
  Index: ConvertorBuilder.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  <st...@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;
  
  /**
   * Interface to be implemented by components that can build a Convertor
   * based on a XML configuration (supplied as DOM Element).
   *
   * <p>The element will (should)
   * always have the local name "convertor" and the woody definition namespace,
   * but attributes and content of the element can vary depending on the
   * ConvertorBuilder implementation.
   */
  public interface ConvertorBuilder {
      /**
       * @param configElement is allowed to be null!
       */
      public Convertor build(Element configElement) throws Exception;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/DefaultFormatCache.java
  
  Index: DefaultFormatCache.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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.convertor;
  
  public class DefaultFormatCache implements Convertor.FormatCache {
      private Object object;
  
      public Object get() {
          return object;
      }
  
      public void store(Object object) {
          this.object = object;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/DummyStringConvertor.java
  
  Index: DummyStringConvertor.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  <st...@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;
  
  /**
   * Convertor that converts between strings and strings, in other words,
   * it does nothing.
   */
  public class DummyStringConvertor implements Convertor {
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
          return value;
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
          return (String)value;
      }
  
      public Class getTypeClass() {
          return String.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/DummyStringConvertorBuilder.java
  
  Index: DummyStringConvertorBuilder.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  <st...@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;
  
  /**
   * Builds {@link DummyStringConvertor}s.
   */
  public class DummyStringConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) throws Exception {
          return new DummyStringConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingDateConvertor.java
  
  Index: FormattingDateConvertor.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  <st...@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.DateFormat;
  import org.outerj.i18n.I18nSupport;
  
  import java.util.Locale;
  import java.util.Date;
  import java.text.ParseException;
  
  /**
   * A Convertor for {@link java.util.Date Date} objects backed by the
   * {@link java.text.SimpleDateFormat SimpleDateFormat} class.
   *
   * <p>It can be configured to use one of three <strong>variants</strong>: date,
   * time or datetime and one of four <strong>styles</strong>: long, full, medium or short.
   *
   * <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.SimpleDateFormat
   * is not entirely correct. In fact, it uses a small wrapper class that will either delegate to
   * java.text.SimpleDateFormat or com.ibm.icu.text.SimpleDateFormat. 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 FormattingDateConvertor implements Convertor {
      /** See {@link #setStyle}. */
      private int style;
      /** See {@link #setVariant}. */
      private int variant;
      /** Locale-specific formatting patterns. */
      private LocaleMap localizedPatterns;
      /** Non-locale specific formatting pattern. */
      private String nonLocalizedPattern;
  
      public static final int DATE = 1;
      public static final int TIME = 2;
      public static final int DATE_TIME = 3;
  
      public FormattingDateConvertor() {
          this.style = 0;
          this.variant = DATE;
          this.localizedPatterns = new LocaleMap();
      }
  
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
          DateFormat dateFormat = getDateFormat(locale, formatCache);
          try {
              return dateFormat.parse(value);
          } catch (ParseException e) {
              return null;
          }
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
          DateFormat dateFormat = getDateFormat(locale, formatCache);
          return dateFormat.format((Date)value);
      }
  
      private final DateFormat getDateFormat(Locale locale, Convertor.FormatCache formatCache) {
          DateFormat dateFormat = null;
          if (formatCache != null)
              dateFormat = (DateFormat)formatCache.get();
          if (dateFormat == null) {
              dateFormat = getDateFormat(locale);
              if (formatCache != null)
                  formatCache.store(dateFormat);
          }
          return dateFormat;
      }
  
      protected DateFormat getDateFormat(Locale locale) {
          DateFormat dateFormat = null;
  
          switch (variant) {
              case DATE:
                  dateFormat = I18nSupport.getInstance().getDateFormat(style, locale);
                  break;
              case TIME:
                  dateFormat = I18nSupport.getInstance().getTimeFormat(style, locale);
                  break;
              case DATE_TIME:
                  dateFormat = I18nSupport.getInstance().getDateTimeFormat(style, style, locale);
                  break;
          }
  
          String pattern = (String)localizedPatterns.get(locale);
  
          if (pattern != null)
              dateFormat.applyLocalizedPattern(pattern);
          else if (nonLocalizedPattern != null)
              dateFormat.applyPattern(nonLocalizedPattern);
  
          return dateFormat;
      }
  
      public Class getTypeClass() {
          return Date.class;
      }
  
      /**
       *
       * @param style one of the constants FULL, LONG, MEDIUM or SHORT defined in the {@link Date} class.
       */
      public void setStyle(int style) {
          this.style = style;
      }
  
      public void setVariant(int variant) {
          if (variant != DATE && variant != TIME && variant != DATE_TIME)
              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;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/FormattingDateConvertorBuilder.java
  
  Index: FormattingDateConvertorBuilder.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  <st...@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.text.DateFormat;
  import java.util.Locale;
  
  /**
   * Builds {@link FormattingDateConvertor}s.
   */
  public class FormattingDateConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) throws Exception {
          FormattingDateConvertor convertor = new FormattingDateConvertor();
  
          if (configElement == null)
              return convertor;
  
          String style = configElement.getAttribute("style");
          if (!style.equals("")) {
              if (style.equals("short"))
                  convertor.setStyle(DateFormat.SHORT);
              else if (style.equals("medium"))
                  convertor.setStyle(DateFormat.MEDIUM);
              else if (style.equals("long"))
                  convertor.setStyle(DateFormat.LONG);
              else if (style.equals("full"))
                  convertor.setStyle(DateFormat.FULL);
              else
                  throw new Exception("Invalid value \"" + style + "\" for style attribute at " + DomHelper.getLocation(configElement));
          }
  
          String variant = configElement.getAttribute("variant");
          if (!variant.equals("")) {
              if (variant.equals("date"))
                  convertor.setVariant(FormattingDateConvertor.DATE);
              else if (variant.equals("time"))
                  convertor.setVariant(FormattingDateConvertor.TIME);
              else if (variant.equals("datetime"))
                  convertor.setVariant(FormattingDateConvertor.DATE_TIME);
              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;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/LocaleMap.java
  
  Index: LocaleMap.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  <st...@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.apache.commons.collections.FastHashMap;
  
  import java.util.Locale;
  
  /**
   * Map using Locale objects as keys.
   *
   * <p>This map should be filled once using calls to {@link #put}, before any calls
   * are made to {@link #get}.
   */
  public class LocaleMap {
      private FastHashMap map = new FastHashMap();
  
      /**
       * Gets an object based on the given locale. An automatic fallback mechanism is used:
       * if nothing is found for language-COUNTRY-variant, then language-COUNTRY is searched,
       * the language, and finally "" (empty string). If nothing is found null is returned.
       */
      public Object get(Locale locale) {
          if (map.size() == 0)
              return null;
  
          String full = getFullKey(locale);
  
          if (!map.containsKey(full)) {
              // check more general variant (lang-COUNTRY and lang), and store result in the map
              // under the full key, so that next time we have a direct hit
              String altKey = locale.getLanguage() + '-' + locale.getCountry();
              Object object = map.get(altKey);
              if (object != null) {
                  map.put(full, object);
                  return object;
              }
  
              altKey = locale.getLanguage();
              object = map.get(altKey);
              if (object != null) {
                  map.put(full, object);
                  return object;
              }
  
              object = map.get("");
              if (object != null) {
                  map.put(full, object);
                  return object;
              }
  
              map.put(full, null);
          }
  
          return map.get(full);
      }
  
      private final String getFullKey(Locale locale) {
          return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant();
      }
  
      private final String getKey(Locale locale) {
          boolean hasLanguage = !locale.getLanguage().equals("");
          boolean hasCountry = !locale.getCountry().equals("");
          boolean hasVariant = !locale.getVariant().equals("");
  
          if (hasLanguage && hasCountry && hasVariant)
              return locale.getLanguage() + '-' + locale.getCountry() + '-' + locale.getVariant();
          else if (hasLanguage && hasCountry)
              return locale.getLanguage() + '-' + locale.getCountry();
          else if (hasLanguage)
              return locale.getLanguage();
          else
              return "";
      }
  
      public void put(Locale locale, Object object) {
          map.put(getKey(locale), object);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/MillisDateConvertor.java
  
  Index: MillisDateConvertor.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  <st...@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.util.Date;
  
  /**
   * A Convertor for Date objects which uses the number of milliseconds since
   * January 1, 1970, 00:00:00 GMT as string representation.
   */
  public class MillisDateConvertor implements Convertor {
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
          try {
              long date = Long.parseLong(value);
              return new Date(date);
          } catch (NumberFormatException e) {
              return null;
          }
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
          Date date = (Date)value;
          return String.valueOf(date.getTime());
      }
  
      public Class getTypeClass() {
          return Date.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/MillisDateConvertorBuilder.java
  
  Index: MillisDateConvertorBuilder.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  <st...@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;
  
  /**
   * Builds {@link MillisDateConvertor}s.
   */
  public class MillisDateConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) {
          return new MillisDateConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainLongConvertor.java
  
  Index: PlainLongConvertor.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  <st...@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;
  
  /**
   * Convertor for java.lang.Longs that does not do any (Locale-dependent)
   * formatting. It simply uses String.valueOf() and Long.parseLong().
   */
  public class PlainLongConvertor implements Convertor {
      public Object convertFromString(String value, Locale locale, Convertor.FormatCache formatCache) {
          try {
              return new Long(Long.parseLong(value));
          } catch (NumberFormatException e) {
              return null;
          }
      }
  
      public String convertToString(Object value, Locale locale, Convertor.FormatCache formatCache) {
          return String.valueOf(value);
      }
  
      public Class getTypeClass() {
          return Long.class;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/PlainLongConvertorBuilder.java
  
  Index: PlainLongConvertorBuilder.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  <st...@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;
  
  /**
   * Builds {@link PlainLongConvertor}s.
   */
  public class PlainLongConvertorBuilder implements ConvertorBuilder {
      public Convertor build(Element configElement) throws Exception {
          return new PlainLongConvertor();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/convertor/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <body>
  General purpose convertors for converting between string and object representations of things (numbers, dates, ...).
  </body>
  </html>