cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel Output.java
Date Fri, 30 Jan 2004 19:19:53 GMT
coliver     2004/01/30 11:19:53

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2
                        ScriptableWidget.java
               src/blocks/woody/java/org/apache/cocoon/woody/formmodel
                        Output.java
  Log:
  Added numeric datatype coercions to Output in ScriptableWidget and getRow() function for
use in JXTemplate or other views: unfortunately it's not possible to support array access
syntax at the moment
  
  Revision  Changes    Path
  1.4       +46 -29    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java
  
  Index: ScriptableWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ScriptableWidget.java	30 Jan 2004 10:00:12 -0000	1.3
  +++ ScriptableWidget.java	30 Jan 2004 19:19:53 -0000	1.4
  @@ -60,6 +60,7 @@
   import org.apache.cocoon.woody.formmodel.Submit;
   import org.apache.cocoon.woody.formmodel.Upload;
   import org.apache.cocoon.woody.formmodel.Widget;
  +import org.apache.cocoon.woody.datatype.Datatype;
   import org.apache.cocoon.woody.datatype.ValidationError;
   import org.apache.cocoon.woody.datatype.SelectionList;
   import org.apache.cocoon.woody.event.FormHandler;
  @@ -283,46 +284,55 @@
           }
       }
   
  -    public int jsGet_length() {
  +    public Integer jsGet_length() {
           if (delegate instanceof Repeater) {
               Repeater repeater = (Repeater)delegate;
  -            return repeater.getSize();
  +            return new Integer(repeater.getSize());
           }
  -        //TODO - added for making this compile
  -        return 0;
  +        return null;
       }
   
       public void jsSet_value(Object value) throws JavaScriptException {
  -        if (delegate instanceof Field) {
  -            Field field = (Field)delegate;
  +        if (delegate instanceof Field || delegate instanceof Output) {
  +            // fix me: Unify Field and Output with a "DataTypeWidget" interface
               value = unwrap(value);
  -            if (value instanceof Double) {
  -                // make woody accept a JS Number
  -                Class typeClass = 
  -                    field.getFieldDefinition().getDatatype().getTypeClass();
  -                if (typeClass == long.class || typeClass == Long.class) {
  -                    value = new Long(((Number)value).longValue());
  -                } else if (typeClass == int.class || 
  -                           typeClass == Integer.class) {
  -                    value = new Integer(((Number)value).intValue());
  -                } else if (typeClass == float.class || 
  -                           typeClass == Float.class) {
  -                    value = new Float(((Number)value).floatValue());
  -                } else if (typeClass == short.class || 
  -                           typeClass == Short.class) {
  -                    value = new Short(((Number)value).shortValue());
  -                } else if (typeClass == BigDecimal.class) {
  -                    value = new BigDecimal(((Number)value).doubleValue());
  +            if (value != null) {
  +                Datatype datatype;
  +                if (delegate instanceof Field) {
  +                    datatype = ((Field)delegate).getFieldDefinition().getDatatype();
  +                } else {
  +                    datatype = ((Output)delegate).getOutputDefinition().getDatatype();
  +                }
  +                Class typeClass = datatype.getTypeClass();
  +                if (typeClass == String.class) {
  +                    value = Context.toString(value);
  +                } else if (typeClass == boolean.class || 
  +                           typeClass == Boolean.class) {
  +                    value = Context.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE;
  +                } else {
  +                    if (value instanceof Double) {
  +                        // make woody accept a JS Number
  +                        if (typeClass == long.class || typeClass == Long.class) {
  +                            value = new Long(((Number)value).longValue());
  +                        } else if (typeClass == int.class || 
  +                                   typeClass == Integer.class) {
  +                            value = new Integer(((Number)value).intValue());
  +                        } else if (typeClass == float.class || 
  +                                   typeClass == Float.class) {
  +                            value = new Float(((Number)value).floatValue());
  +                        } else if (typeClass == short.class || 
  +                                   typeClass == Short.class) {
  +                            value = new Short(((Number)value).shortValue());
  +                        } else if (typeClass == BigDecimal.class) {
  +                            value = new BigDecimal(((Number)value).doubleValue());
  +                        }
  +                    } 
                   }
  -            } 
  -            field.setValue(value);
  +            }
  +            delegate.setValue(value);
           } else if (delegate instanceof BooleanField) {
               BooleanField field = (BooleanField)delegate;
               field.setValue(new Boolean(Context.toBoolean(value)));
  -        } else if (delegate instanceof Output) {
  -            Output field = (Output)delegate;
  -            value = unwrap(value);
  -            field.setValue(Context.toString(value));
           } else if (delegate instanceof Repeater) {
               Repeater repeater = (Repeater)delegate;
               if (value instanceof NativeArray) {
  @@ -502,6 +512,13 @@
       public ScriptableWidget jsFunction_addRow() {
           if (delegate instanceof Repeater) {
               return wrap(((Repeater)delegate).addRow());
  +        }
  +        return null;
  +    }
  +
  +    public ScriptableObject jsFunction_getRow(int index) {
  +        if (delegate instanceof Repeater) {
  +            return wrap(((Repeater)delegate).getRow(index));
           }
           return null;
       }
  
  
  
  1.6       +4 -0      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Output.java
  
  Index: Output.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Output.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Output.java	28 Jan 2004 12:35:37 -0000	1.5
  +++ Output.java	30 Jan 2004 19:19:53 -0000	1.6
  @@ -19,6 +19,10 @@
       private OutputDefinition definition;
       private Object value;
   
  +    public OutputDefinition getOutputDefinition() {
  +        return definition;
  +    }
  +
       protected Output(OutputDefinition definition) {
           this.definition = definition;
           setLocation(definition.getLocation());
  
  
  

Mime
View raw message