cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype EnumSelectionList.java EnumSelectionListBuilder.java
Date Fri, 07 Nov 2003 22:04:38 GMT
ugo         2003/11/07 14:04:38

  Modified:    src/blocks/woody/samples/forms form2_model.xml
               src/blocks/woody/java/org/apache/cocoon/woody/samples
                        Sex.java
               src/blocks/woody/conf woody-datatype.xconf
  Added:       src/blocks/woody/java/org/apache/cocoon/woody/datatype
                        EnumSelectionList.java
                        EnumSelectionListBuilder.java
  Log:
  Added a selection list for Woody that is filled with the possible
  values for a class implementing the Enum interface.
  
  Revision  Changes    Path
  1.11      +1 -4      cocoon-2.1/src/blocks/woody/samples/forms/form2_model.xml
  
  Index: form2_model.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/samples/forms/form2_model.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- form2_model.xml	6 Nov 2003 22:58:36 -0000	1.10
  +++ form2_model.xml	7 Nov 2003 22:04:38 -0000	1.11
  @@ -86,10 +86,7 @@
             <wd:enum>org.apache.cocoon.woody.samples.Sex</wd:enum>
         	</wd:convertor>
         </wd:datatype>
  -      <wd:selection-list>
  -        <wd:item value="male"/>
  -        <wd:item value="female"/>
  -      </wd:selection-list>
  +      <wd:selection-list type="enum" class="org.apache.cocoon.woody.samples.Sex"/>
       </wd:field>
     
       <wd:repeater id="contacts">
  
  
  
  1.3       +11 -1     cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/samples/Sex.java
  
  Index: Sex.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/samples/Sex.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Sex.java	6 Nov 2003 23:03:50 -0000	1.2
  +++ Sex.java	7 Nov 2003 22:04:38 -0000	1.3
  @@ -50,6 +50,9 @@
   */
   package org.apache.cocoon.woody.samples;
   
  +import java.util.ArrayList;
  +import java.util.Collection;
  +import java.util.List;
   import java.util.Locale;
   
   import org.apache.cocoon.woody.datatype.Enum;
  @@ -86,6 +89,13 @@
        */
       public String convertToString(Locale locale) {
           return toString();
  +    }
  +    
  +    public static Collection listValues() {
  +        Collection values = new ArrayList(2);
  +        values.add(Sex.FEMALE);
  +        values.add(Sex.MALE);
  +        return values;
       }
   
   }
  
  
  
  1.7       +1 -0      cocoon-2.1/src/blocks/woody/conf/woody-datatype.xconf
  
  Index: woody-datatype.xconf
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/conf/woody-datatype.xconf,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- woody-datatype.xconf	6 Nov 2003 22:58:36 -0000	1.6
  +++ woody-datatype.xconf	7 Nov 2003 22:04:38 -0000	1.7
  @@ -60,6 +60,7 @@
     <woody-selection-lists default="default">
       <selection-list name="default" class="org.apache.cocoon.woody.datatype.DefaultSelectionListBuilder"/>
       <selection-list name="flow-jxpath" class="org.apache.cocoon.woody.datatype.FlowJXPathSelectionListBuilder"/>
  +    <selection-list name="enum" class="org.apache.cocoon.woody.datatype.EnumSelectionListBuilder"/>
     </woody-selection-lists>
   
   </xconf>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/EnumSelectionList.java
  
  Index: EnumSelectionList.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;
  
  import java.lang.reflect.Method;
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Locale;
  
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.xml.AttributesImpl;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * Builds a selection list with possible values for a class implementing
   * the {@link Enum} interface.
   * @version CVS $Id: EnumSelectionList.java,v 1.1 2003/11/07 22:04:38 ugo Exp $
   */
  public class EnumSelectionList implements SelectionList {
      public static final String I18N_NS = "http://apache.org/cocoon/i18n/2.1";
      public static final String I18N_PREFIX_COLON = "i18n:";
      public static final String TEXT_EL = "text";
      
      private Datatype datatype;
      private Class clazz;
  
      /**
       * @param className
       * @param datatype
       */
      public EnumSelectionList(String className, Datatype datatype) throws ClassNotFoundException
{
          this.datatype = datatype;
          // FIXME: use the correct class loader.
          this.clazz = Class.forName(className);
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.woody.datatype.SelectionList#getDatatype()
       */
      public Datatype getDatatype() {
          return datatype;
      }
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.woody.datatype.SelectionList#generateSaxFragment(org.xml.sax.ContentHandler,
java.util.Locale)
       */
      public void generateSaxFragment(
          ContentHandler contentHandler,
          Locale locale)
          throws SAXException {
          try {
              Method method = clazz.
                  getMethod("listValues", new Class[] {});
              Iterator iter = ((Collection) method.invoke(null, null)).iterator();
              contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON
+ SELECTION_LIST_EL, Constants.EMPTY_ATTRS);
              while(iter.hasNext()) {
                  String stringValue = ((Enum) iter.next()).convertToString(locale);
                  // Output this item
                  AttributesImpl itemAttrs = new AttributesImpl();
                  itemAttrs.addCDATAAttribute("value", stringValue);
                  contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON
+ ITEM_EL, itemAttrs);
                  contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON
+ LABEL_EL, Constants.EMPTY_ATTRS);
                  contentHandler.startElement(I18N_NS, TEXT_EL, I18N_PREFIX_COLON + TEXT_EL,
Constants.EMPTY_ATTRS);
                  contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
                  contentHandler.endElement(I18N_NS, TEXT_EL, I18N_PREFIX_COLON + TEXT_EL);
                  contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON
+ LABEL_EL);
                  contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON
+ ITEM_EL);
              }
              // End the selection-list
              contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON
+ SELECTION_LIST_EL);
          } catch (Exception e) {
              throw new SAXException("Got exception trying to get enum's values", e);
          }
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/EnumSelectionListBuilder.java
  
  Index: EnumSelectionListBuilder.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;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * Description of EnumSelectionListBuilder.
   * @version CVS $Id: EnumSelectionListBuilder.java,v 1.1 2003/11/07 22:04:38 ugo Exp $
   */
  public class EnumSelectionListBuilder implements SelectionListBuilder {
  
      /* (non-Javadoc)
       * @see org.apache.cocoon.woody.datatype.SelectionListBuilder#build(org.w3c.dom.Element,
org.apache.cocoon.woody.datatype.Datatype)
       */
      public SelectionList build(Element selectionListElement, Datatype datatype)
          throws Exception {
          String className = DomHelper.getAttribute(selectionListElement, "class");
          return new EnumSelectionList(className, datatype);
      }
  
  }
  
  
  

Mime
View raw message