incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r471687 - in /incubator/adffaces/branches/stable-06-nov/trinidad: trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/ trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-build/src/main/resources/META-INF/...
Date Mon, 06 Nov 2006 10:45:04 GMT
Author: matzew
Date: Mon Nov  6 02:45:03 2006
New Revision: 471687

URL: http://svn.apache.org/viewvc?view=rev&rev=471687
Log:
merged dateRestrictionValidator to november branch

Added:
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/clientDateRestrictionValidate.jspx
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsonUtils.java
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java
Modified:
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
    incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/java/org/apache/myfaces/trinidad/validator/DateRestrictionValidator.java Mon Nov  6 02:45:03 2006
@@ -172,18 +172,8 @@
 
     if (value != null)
     {
-      TimeZone tz = null;
-      RequestContext rctx = RequestContext.getCurrentInstance();
-      if (rctx != null)
-      {
-        tz = rctx.getTimeZone();
-      }
-      else
-      {
-        tz = TimeZone.getDefault();
-      }
-      Calendar calendar = Calendar.getInstance(tz);
-      calendar.setTime(_getDateValue(value));
+      Calendar calendar = getCalendar();
+      calendar.setTime(getDateValue(value));
       Date convertedDate = calendar.getTime();
       
       String weekday = _dayMap.get(calendar.get(Calendar.DAY_OF_WEEK));
@@ -352,13 +342,30 @@
     return converter;
   }
 
+  
+  protected Calendar getCalendar()
+  {
+    TimeZone tz = null;
+    RequestContext rctx = RequestContext.getCurrentInstance();
+    if (rctx != null)
+    {
+      tz = rctx.getTimeZone();
+    }
+    else
+    {
+      tz = TimeZone.getDefault();
+    }
+    return Calendar.getInstance(tz);
+
+  }
+  
   /**
    * Parses the already converted value to a <code>java.util.Date</code>.
    * @param value converted value
    * @return fulltyped <code>java.util.Date</code>
    * @throws IllegalArgumentException
    */
-  private static Date _getDateValue(
+  protected static Date getDateValue(
       Object value) throws IllegalArgumentException
     {
       if (value instanceof Date)

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts Mon Nov  6 02:45:03 2006
@@ -177,7 +177,7 @@
   <resource
      key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH">Date is not in a valid month.</resource>
   <resource
-    key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH_detail">The date entered, "{1}", is inside the month {2}.</resource>
+    key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.MONTH_detail">The date entered, "{1}", is in an invalid month.</resource>
 
   <!-- Date outside date range error               -->
   <!-- {0} the label that identifies the component -->
@@ -186,7 +186,7 @@
   <!-- {3} represents the maximum allowed date     -->
   <resource key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY">Date is not within a valid weekday.</resource>
 
-  <resource key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY_detail">The date entered, "{1}", is a {2} and therefor not valid.</resource>
+  <resource key="org.apache.myfaces.trinidad.validator.DateRestrictionValidator.WEEKDAY_detail">The date entered, "{1}", is an invalid day of the week.</resource>
 
   <!-- Number exceeds number range error               -->
   <!-- {0} the label that identifies the component -->

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/validators/trinidad/DateRestriction.xml Mon Nov  6 02:45:03 2006
@@ -1,29 +1,31 @@
 <?xml version="1.0" ?>
-<!--
-  Copyright 2006 The Apache Software Foundation.
-
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
-
-      http://www.apache.org/licenses/LICENSE-2.0
-
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
--->
+<!--
+  Copyright 2006 The Apache Software Foundation.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
 <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:tr="http://myfaces.apache.org/trinidad"
               xmlns:mfp="http://myfaces.apache.org/maven-faces-plugin">
   <validator>
-    <description><![CDATA[Validate that the date entered is within a given range.]]></description>
+    <description><![CDATA[Validate that the date entered is within a given restriction.]]></description>
     <display-name>validateDateRestriction</display-name>
     <validator-id>org.apache.myfaces.trinidad.DateRestriction</validator-id>
-    <validator-class>org.apache.myfaces.trinidad.validator.DateRestrictionValidator</validator-class>
+    <validator-class>org.apache.myfaces.trinidadinternal.validator.DateRestrictionValidator</validator-class>
     <property>
-      <description><![CDATA[the .]]>
+      <description><![CDATA[Specify the month which are invalid for your use case.
+           The attribute takes a whitespace delimited list of months.
+           Possible values are jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.]]>
       </description>
       <property-name>invalidMonths</property-name>
       <property-class>java.lang.String[]</property-class>
@@ -31,7 +33,9 @@
     </property>
     
     <property>
-      <description><![CDATA[the .]]>
+      <description><![CDATA[Specify the weekdays which are invalid for your use case.
+           The attribute takes whitespace delimited list of weekdays.
+           Possible values are sun, mon, tue, wed, thu, fri, sat.]]>
       </description>
       <property-name>invalidDaysOfWeek</property-name>
       <property-class>java.lang.String[]</property-class>
@@ -39,16 +43,39 @@
     </property>
     
     <property>
-      <description><![CDATA[the .]]>
+      <description><![CDATA[To specifiy a concrete List of Dates, use the invalidDays attribute and wire it
+           to a DateListProvider implementation. This returns a list of dates, which are invalid.]]>
       </description>
       <property-name>invalidDays</property-name>
       <property-class>org.apache.myfaces.trinidad.model.DateListProvider</property-class>
-      <property-extension/>
+      <property-extension>
+        <mfp:property-metadata>
+          <mfp:preferred>true</mfp:preferred>
+        </mfp:property-metadata>
+      </property-extension>
     </property>
-    
+
     <property>
       <description><![CDATA[<p>
            The detail error message to be used for constructing faces messages,
+           when input value exceeds the <code>invalidMonths</code> value
+           set.
+          </p>
+          <p>
+           <strong>
+            Parameters:
+           </strong>
+           <ul>
+            <li>
+             {0} the label that identifies the component
+            </li>
+            <li>
+             {1} value entered by the user
+            </li>
+            <li>
+             {2} the invalid month
+            </li>
+           </ul>
           </p>]]>
       </description>
       <property-name>messageDetailInvalidMonths</property-name>
@@ -59,9 +86,28 @@
         </mfp:property-metadata>
       </property-extension>
     </property>
+
     <property>
       <description><![CDATA[<p>
            The detail error message to be used for constructing faces messages,
+           when input value is less than the set <code>invalidDaysOfWeek</code>
+           value.
+          </p>
+          <p>
+           <strong>
+            Parameters:
+           </strong>
+           <ul>
+            <li>
+             {0} the label that identifies the component
+            </li>
+            <li>
+             {1} value entered by the user
+            </li>
+            <li>
+             {2} the invalid weekday
+            </li>
+           </ul>
           </p>]]>
       </description>
       <property-name>messageDetailInvalidDaysOfWeek</property-name>
@@ -72,9 +118,28 @@
         </mfp:property-metadata>
       </property-extension>
     </property>
+    
     <property>
       <description><![CDATA[<p>
            The detail error message to be used for constructing faces messages,
+           when input value is less than the set <code>invalidDate</code>
+           value.
+          </p>
+          <p>
+           <strong>
+            Parameters:
+           </strong>
+           <ul>
+            <li>
+             {0} the label that identifies the component
+            </li>
+            <li>
+             {1} value entered by the user
+            </li>
+            <li>
+             {2} the invalid date
+            </li>
+           </ul>
           </p>]]>
       </description>
       <property-name>messageDetailInvalidDays</property-name>
@@ -89,8 +154,33 @@
     <validator-extension>
       <mfp:tag-name>tr:validateDateRestriction</mfp:tag-name>
       <mfp:tag-class>org.apache.myfaces.trinidadinternal.taglib.validator.ValidateDateRestrictionTag</mfp:tag-class>
+      <mfp:long-description><![CDATA[<html:p>
+
+        Validate that the date is valid with some given restrictions.
+</html:p>]]></mfp:long-description>
+      <mfp:example>
+        <mfp:source-code>
+        <![CDATA[<tr:inputDate id="days" value="#{bean.date}"
+                                  label="Select a date, but check possible holidays first">
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidDays="#{bean.date.nationalHolidays}" />
+              </tr:inputDate>
+              
+              <tr:inputDate id="month" value="#{bean.date}"
+                                  label="Select a date, but not within November or December">
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidMonths="Nov Dec" />
+              </tr:inputDate>
+              
+              <tr:inputDate id="daysOfWeek" value="#{bean.date}"
+                                  label="Select a date, but not a Monday">
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidDaysOfWeek="Mon"/>
+              </tr:inputDate>]]>
+     </mfp:source-code>
+      </mfp:example>
       <mfp:author>Matthias Wessendorf</mfp:author>
       <mfp:uix2-local-name>validateDateTimeRange</mfp:uix2-local-name>
     </validator-extension>
   </validator>
-</faces-config>
+</faces-config>
\ No newline at end of file

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/WEB-INF/faces-config.xml Mon Nov  6 02:45:03 2006
@@ -1852,6 +1852,12 @@
     </navigation-case>
 
     <navigation-case>
+      <from-outcome>clientDateRestrictionValidate</from-outcome>
+      <to-view-id>/convertValidate/clientDateRestrictionValidate.jspx</to-view-id>
+      <redirect/>
+    </navigation-case>
+
+    <navigation-case>
       <from-outcome>convertValidateDemos</from-outcome>
       <to-view-id>/convertValidate/index.jspx</to-view-id>
       <redirect/>

Added: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/clientDateRestrictionValidate.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/clientDateRestrictionValidate.jspx?view=auto&rev=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/clientDateRestrictionValidate.jspx (added)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/clientDateRestrictionValidate.jspx Mon Nov  6 02:45:03 2006
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
+<!--
+  Copyright 2006 The Apache Software Foundation.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
+          xmlns:f="http://java.sun.com/jsf/core"
+          xmlns:tr="http://myfaces.apache.org/trinidad"
+          xmlns:trdemo="http://myfaces.apache.org/trinidaddemo">
+  <jsp:directive.page contentType="text/html;charset=utf-8"/>
+  <f:view>
+    <tr:document title="Client-side Date Restriction Validator">
+        <tr:form usesUpload="true">
+          <tr:panelPage>
+            <tr:messages/>
+            <f:facet name="navigationGlobal">
+              <tr:navigationPane hint="buttons">
+                <tr:commandNavigationItem text="Converters and Validators"
+                                    action="convertValidateDemos"
+                                    immediate="true"/>
+              </tr:navigationPane>
+            </f:facet>
+           <tr:panelHeader text="Client-side Date Restriction Validator">
+            <tr:outputText styleClass="AFInstructionText"
+                           value="In the following examples, the date Restriction validator runs on the client, avoiding a round trip."/>
+            <tr:spacer height="10"/>
+            <tr:panelHeader text="Client Validators"/>
+            <tr:spacer height="10"/>
+            <tr:panelFormLayout>
+
+              <tr:inputDate id="month" value="#{dateRestrictionValidator.testInvalidMonth}"
+                                  label="Select a date!">
+                <f:facet name="help">
+                  <tr:outputText value="November/December dates are not allowed here!"/>
+                </f:facet>
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidMonths="Nov Dec" />
+              </tr:inputDate>
+              
+              <tr:inputDate id="daysOfWeek" value="#{dateRestrictionValidator.testInvalidDaysOfWeek}"
+                                  label="Select a date!">
+                <f:facet name="help">
+                  <tr:outputText value="Please no Mondays...!"/>
+                </f:facet>
+                <tr:convertDateTime pattern="yyyy-MM-dd"/>
+                <tr:validateDateRestriction  invalidDaysOfWeek="Mon"/>
+              </tr:inputDate>
+
+            </tr:panelFormLayout>
+           </tr:panelHeader>
+            <tr:panelButtonBar>
+              <tr:commandButton text="Submit"/>
+            </tr:panelButtonBar>
+          </tr:panelPage>
+        </tr:form>
+    </tr:document>
+  </f:view>
+</jsp:root>
\ No newline at end of file

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-demo/src/main/webapp/convertValidate/index.jspx Mon Nov  6 02:45:03 2006
@@ -33,6 +33,7 @@
               <tr:panelGroupLayout layout="vertical">
                 <tr:commandLink text="client converters and validators" action="clientConvert"/>
                 <tr:commandLink text="converters and validators" action="convertValidate"/>
+                <tr:commandLink text="client Date Restriction Validator" action="clientDateRestrictionValidate" />
                 <tr:commandLink text="Date Restriction Validator" action="dateRestrictionValidate" />
                 <tr:commandLink text="message customization on validators and converters" action="messageCustomization"/>
               </tr:panelGroupLayout>

Added: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsonUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsonUtils.java?view=auto&rev=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsonUtils.java (added)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/JsonUtils.java Mon Nov  6 02:45:03 2006
@@ -0,0 +1,474 @@
+package org.apache.myfaces.trinidadinternal.util;
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.awt.Color;
+import java.io.IOException;
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.myfaces.trinidadinternal.convert.GenericConverterFactory;
+
+/**
+ * Utilities for writing out JSON notation strings inside XML attribute or text.
+ * @author Apache Trinidad team
+ */
+public final class JsonUtils
+{
+
+  static public void writeObject(
+      StringBuilder out,
+      Object        attrValue,
+      boolean       escapeXML) throws IOException
+    {
+      if (attrValue == null)
+      {
+        out.append("null");
+      }
+      else
+      {
+        if (attrValue instanceof CharSequence)
+        {
+          writeString(out, ((CharSequence)attrValue), escapeXML);
+          return;
+        }
+
+        Class valueClass = attrValue.getClass();
+        if (Boolean.class == valueClass)
+        {
+          writeBoolean(out, ((Boolean)attrValue).booleanValue());
+          return;
+        }
+        else if (Integer.class == valueClass)
+        {
+          writeInt(out, ((Integer)attrValue).intValue());
+          return;
+        }
+        else if (Character.class == valueClass)
+        {
+          writeChar(out, ((Character)attrValue).charValue(), escapeXML);
+          return;
+        }
+        else if (valueClass.isArray())
+        {
+          out.append('[');
+
+          int length = Array.getLength(attrValue);
+
+          for (int i = 0; i < length; i++)
+          {
+            writeObject(out, Array.get(attrValue, i), escapeXML);
+
+            if ( i != (length - 1))
+              out.append(',');
+          }
+
+          out.append(']');
+          return;
+        }
+        
+        GenericConverterFactory converter =
+          GenericConverterFactory.getCurrentInstance();
+        if (Byte.class == valueClass)
+        {
+          writeByte(out, ((Byte)attrValue).byteValue());
+        }
+        else if (converter.isConvertible(attrValue, Date.class))
+        {
+          Date date = (Date) converter.convert(attrValue, Date.class);
+          writeDate(out, date);
+        }
+        else if (Double.class == valueClass)
+        {
+          writeDouble(out, ((Double)attrValue).doubleValue());
+        }
+        else if (Float.class == valueClass)
+        {
+          writeFloat(out, ((Float)attrValue).floatValue());
+        }
+        else if (Long.class == valueClass)
+        {
+          writeLong(out, ((Long)attrValue).longValue());
+        }
+        else if (Short.class == valueClass)
+        {
+          writeShort(out, ((Short)attrValue).shortValue());
+        }
+        else if (converter.isConvertible(attrValue, Number.class))
+        {
+          Number num = (Number) converter.convert(attrValue, Number.class);
+          writeDouble(out, num.doubleValue());
+        }
+        else if (Map.class.isAssignableFrom(valueClass))
+        {
+          writeMap(out, ((Map)attrValue), escapeXML);
+        }
+        else if (Collection.class.isAssignableFrom(valueClass))
+        {
+          writeCollection(out, ((Collection)attrValue), escapeXML);
+        }
+        else if (Color.class == valueClass)
+        {
+          writeColor(out, ((Color)attrValue));
+        }
+      }
+    }
+
+    /**
+     * Encodes a boolean in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the boolean value
+     */
+    static public void writeBoolean(
+      StringBuilder out,
+      boolean      value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a byte in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the byte value
+     */
+    static public void writeByte(
+      StringBuilder out,
+      byte         value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a char in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the char value
+     */
+    static public void writeChar(
+      StringBuilder out,
+      char         value,
+      boolean      escapeXML) throws IOException
+    {
+      out.append('\'');
+      _escapeChar(out, value, escapeXML);
+      out.append('\'');
+    }
+
+    /**
+     * Encodes a Collection in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the List value
+     */
+    static public void writeCollection(
+      StringBuilder out,
+      Collection   value,
+      boolean      escapeXML) throws IOException
+    {
+      if (value == null)
+      {
+        out.append("null");
+      }
+      else if (value.isEmpty())
+      {
+        out.append("[]");
+      }
+      else
+      {
+        out.append("[");
+        for (Iterator iter = value.iterator();
+             iter.hasNext();)
+        {
+          Object item = iter.next();
+          writeObject(out, item, escapeXML);
+          if (iter.hasNext())
+            out.append(',');
+        }
+        out.append(']');
+      }
+    }
+
+    static public void writeDate(StringBuilder out, Date value) throws IOException
+    {
+      out.append("new Date("+value.getTime()+")");
+    }
+
+    static public void writeColor(StringBuilder out, Color color) throws IOException
+    {
+      if(color.getAlpha() == 0)
+      {
+        out.append("null");
+      }
+      else
+      {
+        out.append("new TrColor(");
+        out.append(color.getRed());
+        out.append(",");
+        out.append(color.getGreen());
+        out.append(",");
+        out.append(color.getBlue());
+        out.append(")");
+      }
+    }
+
+    /**
+     * Encodes a double in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the double value
+     */
+    static public void writeDouble(
+      StringBuilder out,
+      double       value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a float in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the float value
+     */
+    static public void writeFloat(
+      StringBuilder out,
+      float        value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a long in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the long value
+     */
+    static public void writeLong(
+      StringBuilder out,
+      long         value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a int in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the int value
+     */
+    static public void writeInt(
+      StringBuilder out,
+      int          value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a short in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the short value
+     */
+    static public void writeShort(
+      StringBuilder out,
+      short        value) throws IOException
+    {
+      out.append(value);
+    }
+
+    /**
+     * Encodes a String in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param value         the String value
+     */
+    static public void writeString(
+      StringBuilder out,
+      CharSequence  value,
+      boolean       escapeXML) throws IOException
+    {
+      if (value == null)
+      {
+        out.append("null");
+      }
+      else
+      {
+        // escape chars as necessary
+
+        out.append('\'');
+
+        for (int i=0; i < value.length(); i++)
+        {
+          char ch = value.charAt(i);
+          _escapeChar(out, ch, escapeXML);
+        }
+
+        out.append('\'');
+      }
+    }
+
+    /**
+     * Encodes a Map in JavaScript Object Notation.
+     *
+     * @param out           the output buffer
+     * @param map           the Map value
+     */
+    static public void writeMap(
+      StringBuilder out,
+      Map          map,
+      boolean      escapeXML) throws IOException
+    {
+      if (map == null)
+      {
+        out.append("null");
+      }
+      else if (map.isEmpty())
+      {
+        out.append("{}");
+      }
+      else
+      {
+        out.append("{");
+        Set entries = map.entrySet();
+        for (Iterator iter = entries.iterator();
+             iter.hasNext();)
+        {
+          Map.Entry entry = (Map.Entry)iter.next();
+          Object rawKey = entry.getKey();
+          if(rawKey == null)
+            throw new IllegalArgumentException("Javascript does not support null keys");
+          String key = rawKey.toString(); 
+          Object value = entry.getValue();
+          writeString(out, key, escapeXML);
+          out.append(':');
+          writeObject(out, value, escapeXML);
+          if (iter.hasNext())
+            out.append(',');
+        }
+        out.append('}');
+      }
+    }
+
+  
+
+  /**
+   * prevent object creation
+   *
+   */
+  private JsonUtils()
+  {
+  }
+  
+  /**
+   * Encodes a char in JavaScript Object Notation.
+   *
+   * @param out           the output buffer
+   * @param value         the char value
+   */
+  static private void _escapeChar(
+    StringBuilder out,
+    char         value,
+    boolean      escapeXML)
+  {
+    switch (value)
+    {
+      // Escapes needed for XML
+      case '&':
+        if (escapeXML)
+          out.append("&amp;");
+        else
+          out.append('&');
+        break;
+      case '<':
+        if (escapeXML)
+          out.append("&lt;");
+        else
+          out.append('<');
+        break;
+      case '>':
+        if (escapeXML)
+          out.append("&gt;");
+        else
+          out.append('>');
+        break;
+
+      // Double quote
+      case '\"':
+        if (escapeXML)
+          out.append("\\&quot;");
+        else
+          out.append("\\\"");
+        break;
+      // Apostrophe
+      case '\'':
+        out.append("\\\'");
+        break;
+      // Backslash
+      case '\\':
+        out.append("\\\\");
+        break;
+      case '\b':
+        out.append("\\b");
+        break;
+      case '\f':
+        out.append("\\f");
+        break;
+      case '\n':
+        out.append("\\n");
+        break;
+      case '\r':
+        out.append("\\r");
+        break;
+      case '\t':
+        out.append("\\t");
+        break;
+      default:
+        if (value >= 32 && value < 128)
+        {
+          // no escaping necessary
+          out.append(value);
+        }
+        else
+        {
+          String hex = Integer.toHexString(value);
+
+          if (value > 0x00FF)
+          {
+            // use unicode escaping
+            out.append("\\u");
+            if (value < 0x1000)
+              out.append('0');
+            out.append(hex);
+          }
+          else
+          {
+            // use hex escaping
+            out.append("\\x");
+            if (value < 0x10)
+              out.append('0');
+            out.append(hex);
+          }
+        }
+        break;
+    }
+  }
+}
\ No newline at end of file

Added: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java?view=auto&rev=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java (added)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/DateRestrictionValidator.java Mon Nov  6 02:45:03 2006
@@ -0,0 +1,215 @@
+package org.apache.myfaces.trinidadinternal.validator;
+/*
+* Copyright 2006 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.validator.ValidatorException;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.trinidad.util.MessageFactory;
+import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidadinternal.convert.GenericConverterFactory;
+import org.apache.myfaces.trinidadinternal.ui.laf.base.xhtml.XhtmlLafUtils;
+import org.apache.myfaces.trinidadinternal.util.JsonUtils;
+
+/**
+ * @author Matthias Wessendorf
+ *
+ */
+public class DateRestrictionValidator extends org.apache.myfaces.trinidad.validator.DateRestrictionValidator
+                                       implements ClientValidator
+{
+  public DateRestrictionValidator()
+  {
+    super();
+    _initJsDateMap();
+  }
+
+  @Override
+  public void validate(
+    FacesContext context,
+    UIComponent  component,
+    Object       value) throws ValidatorException
+  {
+    if (value == null)
+      return;
+    
+    if (!(value instanceof Date))
+    {
+      GenericConverterFactory fac = GenericConverterFactory.getCurrentInstance();
+      value = fac.convert(value, Date.class);
+    }
+    super.validate(context, component, value);
+  }
+  
+  public Collection<String> getClientImportNames()
+  {
+    return _IMPORT_NAMES;
+  }
+
+  public String getClientScript(
+   FacesContext context,
+   UIComponent component)
+  {
+    return null;
+  }
+
+
+  /**
+   * @todo this should have not_in_range messages, not just max and min!
+   * @todo Format these numbers properly.
+   */
+  public String getClientValidation(
+    FacesContext context,
+    UIComponent component)
+  {
+    String[] weekdaysValue = getInvalidDaysOfWeek();
+    String weekdaysValues = null;
+    StringBuilder sb1 = new StringBuilder();
+    
+    String[] monthValue = getInvalidMonths();
+    String monthValues = null;
+    StringBuilder sb2 = new StringBuilder();
+    monthValues = sb2.toString();
+
+    try
+    {
+      JsonUtils.writeObject(sb1, weekdaysValue, false);
+      weekdaysValues = sb1.toString();
+      JsonUtils.writeObject(sb2, monthValue, false);
+      monthValues = sb2.toString();
+    }
+    catch (IOException e)
+    {
+      weekdaysValues  = "null";
+      monthValues  = "null";
+    }
+
+    return _getTrDateRestrictionValidator(context, component, WEEKDAY_MESSAGE_ID, MONTH_MESSAGE_ID, VALIDATOR_ID, weekdaysValues, monthValues);
+  }
+  
+  
+  public String getClientLibrarySource(
+   FacesContext context)
+  {
+    return null;
+  }
+  
+  private static String _getTrDateRestrictionValidator(
+      FacesContext context,
+      UIComponent component,
+      String weekId,
+      String monthId,
+      String defaultId,
+      String weekdaysValues,
+      String monthValues)
+  {
+    StringBuffer outBuffer = new StringBuffer(250);
+    outBuffer.append("new TrDateRestrictionValidator(");
+
+    FacesMessage weekMessage =
+      MessageFactory.getMessage(context, weekId,
+                                  new Object[]{"{0}", "{1}", "{2}"});
+
+    outBuffer.append("{WV:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(weekMessage.getDetail()));
+
+    outBuffer.append("',WV_S:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(weekMessage.getSummary()));    
+
+    FacesMessage monthMessage =
+      MessageFactory.getMessage(context, monthId,
+                                  new Object[]{"{0}", "{1}", "{2}"});
+
+    outBuffer.append("',MV:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(monthMessage.getDetail()));
+    outBuffer.append("',MV_S:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(monthMessage.getSummary()));  
+    
+    FacesMessage defaultMessage =
+      MessageFactory.getMessage(context, defaultId,
+                                  new Object[]{"{0}", "{1}"});
+
+    outBuffer.append("',D:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(defaultMessage.getDetail())); 
+    outBuffer.append("',D_S:'");
+    outBuffer.append(XhtmlLafUtils.escapeJS(defaultMessage.getSummary()));
+    outBuffer.append("'},null,0,");
+    outBuffer.append(weekdaysValues);
+    outBuffer.append(',');
+    outBuffer.append(monthValues);
+    outBuffer.append(',');
+    outBuffer.append(_getMapAsJson(_jsWeekDays));
+    outBuffer.append(',');
+    outBuffer.append(_getMapAsJson(_jsMonths));
+    outBuffer.append(")");
+
+    return outBuffer.toString();
+  }
+  
+  private static String _getMapAsJson(Map map)
+  {
+    StringBuilder sb = new StringBuilder();
+    try
+    {
+      JsonUtils.writeMap(sb, map, false);
+    }
+    catch (IOException e)
+    {
+      sb.append("null");
+    }
+    return sb.toString();
+  }
+  
+  private void _initJsDateMap()
+  {
+    _jsWeekDays = new HashMap<Integer, String>();
+    _jsWeekDays.put(Calendar.SUNDAY-1, "sun");
+    _jsWeekDays.put(Calendar.MONDAY-1, "mon");
+    _jsWeekDays.put(Calendar.TUESDAY-1, "tue");
+    _jsWeekDays.put(Calendar.WEDNESDAY-1, "wed");
+    _jsWeekDays.put(Calendar.THURSDAY-1, "thu");
+    _jsWeekDays.put(Calendar.FRIDAY-1, "fri");
+    _jsWeekDays.put(Calendar.SATURDAY-1, "sat");
+    
+    _jsMonths = new HashMap<Integer, String>();
+    _jsMonths.put(Calendar.JANUARY, "jan");
+    _jsMonths.put(Calendar.FEBRUARY, "feb");
+    _jsMonths.put(Calendar.MARCH, "mar");
+    _jsMonths.put(Calendar.APRIL, "apr");
+    _jsMonths.put(Calendar.MAY, "may");
+    _jsMonths.put(Calendar.JUNE, "jun");
+    _jsMonths.put(Calendar.JULY, "jul");
+    _jsMonths.put(Calendar.AUGUST, "aug");
+    _jsMonths.put(Calendar.SEPTEMBER, "sep");
+    _jsMonths.put(Calendar.OCTOBER, "oct");
+    _jsMonths.put(Calendar.NOVEMBER, "nov");
+    _jsMonths.put(Calendar.DECEMBER, "dec");
+  }
+  
+  private static final Collection<String> _IMPORT_NAMES = Collections.singletonList( "TrNumberConverter()" );
+  private static Map<Integer, String> _jsMonths = null;
+  private static Map<Integer, String> _jsWeekDays = null;
+}
\ No newline at end of file

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js Mon Nov  6 02:45:03 2006
@@ -14,6 +14,176 @@
  * limitations under the License.
  */
 
+/**
+ * Construct a TrColorConverter with the specifed color pattern.
+ */
+function TrColorConverter(
+  pattern,
+  allowsTransparent,
+  msg_summary,
+  msg_detail,
+  patternsString)
+{
+  // for debugging
+  this._class = "TrColorConverter";
+  this._allowsTransparent = allowsTransparent;  
+  this._msg_summary = msg_summary; 
+  this._msg_detail = msg_detail;
+  this._patternsString = patternsString;     
+  
+  if (pattern != null)
+  {
+    if (typeof(pattern) == "string" ) 
+      pattern = [pattern];
+  }
+
+  this._pattern = pattern;
+}
+
+TrColorConverter.prototype = new TrConverter();
+TrColorConverter.prototype.getAsString = function(
+  formatColor)
+{
+  //pu: Return undefined string for an undefined Color.
+  if (formatColor == null)
+    return null;
+
+  // return localized transparent text for transparent color
+  if (formatColor.alpha == 0)
+    return _cfTrans;
+
+  var stringHolder = new Object();
+  stringHolder.value ="";
+  
+  var pattern = this._pattern;
+  if (typeof pattern != "string")
+    pattern = pattern[0];
+    
+  _cfoDoClumping(pattern,
+              _cfoSubformat,
+              formatColor,
+              stringHolder);
+  
+  return stringHolder.value;
+}
+
+/**
+ * Parses a String into a Color using the current object's pattern.  If the
+ * parsing fails, undefined will be returned.
+ */
+TrColorConverter.prototype.getAsObject  = function(
+  parseString,
+  label)
+{
+  // The following are from the javadoc for Number and DateTimeConverter, same applies to color....
+  // If the specified String is null, return a null. Otherwise, trim leading and trailing whitespace before proceeding.
+  // If the specified String - after trimming - has a zero length, return null.
+  if (parseString == null)
+    return null;
+    
+  parseString = TrUIUtils.trim(parseString);
+  if (parseString.length == 0)
+    return null
+
+  // return transparent color for localized transparent text
+  if (this._allowsTransparent && _cfTrans == parseString)
+    return new TrColor(0,0,0,0);
+     
+  var facesMessage = _createFacesMessage( this._msg_summary,
+                                          this._msg_detail,
+                                          label,
+                                          parseString,
+                                          this._patternsString);
+  
+  var pattern = this._pattern;                                       
+  if (typeof pattern == "string")
+  {
+    return this._rgbColorParseImpl(parseString,
+                              pattern,
+                              facesMessage);
+  }
+  else
+  { 
+    var i;
+    for (i = 0; i < pattern.length; i++)
+    {
+      try{
+        var color = this._rgbColorParseImpl(parseString,
+                                     pattern[i],
+                                     facesMessage);
+        return color;
+      }
+      catch (e)
+      {
+        // if we're not on the last pattern try the next one, 
+        // but if we're on the last pattern, throw the exception
+        if ( i == pattern.length-1)
+          throw e;
+      }
+    }
+  }
+}
+
+TrColorConverter.prototype._rgbColorParseImpl  = function(
+  parseString,
+  parsePattern,
+  msg)
+{
+  var parseContext = new Object();
+  parseContext.currIndex = 0;
+  parseContext.parseString = parseString;
+  parseContext.parseException = new TrConverterException(msg);
+  
+  var parsedColor = new TrColor(0x00, 0x00, 0x00);
+
+  // parse the color
+  if (_cfoDoClumping(parsePattern,
+                  _cfoSubParse,
+                  parseContext,
+                  parsedColor))
+  {
+    if (parseString.length != parseContext.currIndex)
+    {
+      throw parseContext.parseException;
+    }
+
+    return parsedColor;
+  }
+  else
+  {
+    // failure
+    throw parseContext.parseException;
+  }
+}
+
+function TrColor(
+  red,
+  green,
+  blue,
+  alpha)
+{
+  // for debugging
+  this._class = "TrColor";
+  
+  if (alpha == null)
+    alpha = 0xff;
+
+  this.red   = (red & 0xff);
+  this.green = (green & 0xff);
+  this.blue  = (blue & 0xff);
+  this.alpha = (alpha & 0xff);
+}
+
+TrColor.prototype.toString = function()
+{
+  return "rgba(" + this.red + 
+         "," + this.green + 
+         "," + this.blue + 
+         "," + this.alpha + ")";
+}
+
+
+
 
 // External variables used:
 //  _cfTrans    - the localized text for transparent colors
@@ -150,6 +320,7 @@
   stringHolder
   )
 {    
+
   // string to append to the toString
   var appendString = null;
   
@@ -447,172 +618,4 @@
   }
   
   return stringNumber;
-}
-
-/**
- * Construct a TrColorConverter with the specifed color pattern.
- */
-function TrColorConverter(
-  pattern,
-  allowsTransparent,
-  msg_summary,
-  msg_detail,
-  patternsString)
-{
-  // for debugging
-  this._class = "TrColorConverter";
-  this._allowsTransparent = allowsTransparent;  
-  this._msg_summary = msg_summary; 
-  this._msg_detail = msg_detail;
-  this._patternsString = patternsString;     
-  
-  if (pattern != null)
-  {
-    if (typeof(pattern) == "string" ) 
-      pattern = [pattern];
-  }
-
-  this._pattern = pattern;
-}
-
-TrColorConverter.prototype = new TrConverter();
-TrColorConverter.prototype.getAsString = function(
-  formatColor)
-{
-  //pu: Return undefined string for an undefined Color.
-  if (formatColor == null)
-    return null;
-
-  // return localized transparent text for transparent color
-  if (formatColor.alpha == 0)
-    return _cfTrans;
-
-  var stringHolder = new Object();
-  stringHolder.value ="";
-  
-  var pattern = this._pattern;
-  if (typeof pattern != "string")
-    pattern = pattern[0];
-    
-  _cfoDoClumping(pattern,
-              _cfoSubformat,
-              formatColor,
-              stringHolder);
-  
-  return stringHolder.value;
-}
-
-/**
- * Parses a String into a Color using the current object's pattern.  If the
- * parsing fails, undefined will be returned.
- */
-TrColorConverter.prototype.getAsObject  = function(
-  parseString,
-  label)
-{
-  // The following are from the javadoc for Number and DateTimeConverter, same applies to color....
-  // If the specified String is null, return a null. Otherwise, trim leading and trailing whitespace before proceeding.
-  // If the specified String - after trimming - has a zero length, return null.
-  if (parseString == null)
-    return null;
-    
-  parseString = TrUIUtils.trim(parseString);
-  if (parseString.length == 0)
-    return null
-
-  // return transparent color for localized transparent text
-  if (this._allowsTransparent && _cfTrans == parseString)
-    return new TrColor(0,0,0,0);
-     
-  var facesMessage = _createFacesMessage( this._msg_summary,
-                                          this._msg_detail,
-                                          label,
-                                          parseString,
-                                          this._patternsString);
-  
-  var pattern = this._pattern;                                       
-  if (typeof pattern == "string")
-  {
-    return this._rgbColorParseImpl(parseString,
-                              pattern,
-                              facesMessage);
-  }
-  else
-  { 
-    var i;
-    for (i = 0; i < pattern.length; i++)
-    {
-      try{
-        var color = this._rgbColorParseImpl(parseString,
-                                     pattern[i],
-                                     facesMessage);
-        return color;
-      }
-      catch (e)
-      {
-        // if we're not on the last pattern try the next one, 
-        // but if we're on the last pattern, throw the exception
-        if ( i == pattern.length-1)
-          throw e;
-      }
-    }
-  }
-}
-
-TrColorConverter.prototype._rgbColorParseImpl  = function(
-  parseString,
-  parsePattern,
-  msg)
-{
-  var parseContext = new Object();
-  parseContext.currIndex = 0;
-  parseContext.parseString = parseString;
-  parseContext.parseException = new TrConverterException(msg);
-  
-  var parsedColor = new TrColor(0x00, 0x00, 0x00);
-
-  // parse the color
-  if (_cfoDoClumping(parsePattern,
-                  _cfoSubParse,
-                  parseContext,
-                  parsedColor))
-  {
-    if (parseString.length != parseContext.currIndex)
-    {
-      throw parseContext.parseException;
-    }
-
-    return parsedColor;
-  }
-  else
-  {
-    // failure
-    throw parseContext.parseException;
-  }
-}
-
-function TrColor(
-  red,
-  green,
-  blue,
-  alpha)
-{
-  // for debugging
-  this._class = "TrColor";
-  
-  if (alpha == null)
-    alpha = 0xff;
-
-  this.red   = (red & 0xff);
-  this.green = (green & 0xff);
-  this.blue  = (blue & 0xff);
-  this.alpha = (alpha & 0xff);
-}
-
-TrColor.prototype.toString = function()
-{
-  return "rgba(" + this.red + 
-         "," + this.green + 
-         "," + this.blue + 
-         "," + this.alpha + ")";
 }

Modified: incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?view=diff&rev=471687&r1=471686&r2=471687
==============================================================================
--- incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ incubator/adffaces/branches/stable-06-nov/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Mon Nov  6 02:45:03 2006
@@ -93,24 +93,30 @@
   label
 )
 {
-
-  // This should probably do more than call decimalParse!
-  // the following line is needed because what's being passed
-  // into the validator is a number, and _decimalParse expects a string.
-  numberString = "" + value;
-  try
-  {
-    return _decimalParse(numberString, 
-                       this._messages,
-                       this._maxPrecision,
-                       this._maxScale,
-                       this._maxValue,
-                       this._minValue,
-                       label);
+  string = "" + value;
+  numberValue = parseFloat(string);
+  
+  if(numberValue >= this._minValue && numberValue <= this._maxValue)
+  {
+    return string;
   }
-  catch (e)
+  else
   {
-    throw new TrValidatorException(e.getFacesMessage());
+    if(numberValue>this._maxValue)
+    {
+      facesMessage = _createFacesMessage(this._messages[(TrNumberConverter.LV+ '_S')],
+                                       this._messages[TrNumberConverter.LV],
+                                        label,
+                                        string);
+    }
+    else
+    {
+      facesMessage = _createFacesMessage(this._messages[(TrNumberConverter.MV+ '_S')],
+                                       this._messages[TrNumberConverter.MV],
+                                        label,
+                                        string);
+    }
+    throw new TrConverterException(facesMessage);
   }
 }
 
@@ -139,9 +145,6 @@
 )
 {
 
-  // This should probably do more than call decimalParse!
-  // the following line is needed because what's being passed
-  // into the validator is a number, and _decimalParse expects a string.
   string = "" + value;
   length = string.length;
   
@@ -202,6 +205,81 @@
   
 }
 
+function TrDateRestrictionValidator(
+  messages,
+  maxPrecision,
+  maxScale,
+  weekdaysValue,
+  monthValue,
+  weekdaysMap,
+  monthMap)
+{
+  this._messages = messages;
+  this._maxPrecision = maxPrecision;
+  this._maxScale = maxScale;
+  this._weekdaysValue = weekdaysValue;
+  this._monthValue = monthValue;
+  this._weekdaysMap = weekdaysMap;
+  this._monthMap = monthMap;
+
+  // for debugging
+  this._class = "TrDateRestrictionValidator";
+}
+
+// weekday value
+TrDateRestrictionValidator.WV = 'WV';
+// month value
+TrDateRestrictionValidator.MV  = 'MV';
+// default
+TrDateRestrictionValidator.D   = 'D';
+
+TrDateRestrictionValidator.prototype = new TrValidator();
+TrDateRestrictionValidator.prototype.validate  = function(
+  value,
+  label
+)
+{
+
+  submittedDay = value.getDay();
+  weekDaysArray = eval(this._weekdaysValue);
+  if(weekDaysArray)
+  {
+  	var dayString = this._weekdaysMap[submittedDay];
+  	for(var i = 0; i < weekDaysArray.length; ++i)
+  	{
+  		if(weekDaysArray[i].toLowerCase() == dayString)
+  		{
+        facesMessage = _createFacesMessage(this._messages[(TrDateRestrictionValidator.WV+ '_S')],
+                                       this._messages[TrDateRestrictionValidator.WV],
+                                        label,
+                                        ""+value,
+                                        dayString);
+        throw new TrConverterException(facesMessage);
+  		}
+  	}
+  }
+  
+  submittedMonth = value.getMonth();
+  monthArray = eval(this._monthValue);
+  if(monthArray)
+  {
+  	var monthString = this._monthMap[submittedMonth];
+  	for(var i = 0; i < monthArray.length; ++i)
+  	{
+  		if(monthArray[i].toLowerCase() == monthString)
+  		{
+        facesMessage = _createFacesMessage(this._messages[(TrDateRestrictionValidator.MV+ '_S')],
+                                       this._messages[TrDateRestrictionValidator.MV],
+                                        label,
+                                        ""+value,
+                                        monthString);
+        throw new TrConverterException(facesMessage);
+  		}
+  	}
+  }
+	return value;
+}
+
 function _decimalParse(
   numberString,
   messages,
@@ -269,38 +347,37 @@
       if (sepIndex != -1)
       {
         integerDigits = sepIndex;
-        fractionDigits = numberString.length - sepIndex -1;
+        fractionDigits = parseInt(numberString.length - parseInt(sepIndex -1));
       }
       
       var messageKey;
-      
-      if ((maxValue != (void 0)) &&
+      if ((maxValue != null) &&
           (result  > maxValue))
       {
         messageKey = TrNumberConverter.LV;
       }
-      else if ((minValue != (void 0)) &&
+      else if ((minValue != null) &&
                (result  < minValue))
       {
         messageKey = TrNumberConverter.MV;
       }
-      else if ((maxPrecision != (void 0)) &&
+      else if ((maxPrecision != null) &&
                (integerDigits  > maxPrecision))
       {
         messageKey = TrNumberConverter.LID;
       }
-      else if ((maxScale != (void 0)) &&
+
+      else if ((maxScale != null) &&
                (fractionDigits  > maxScale))
       {
         messageKey = TrNumberConverter.LFD;
       }
 
-      if (messageKey != (void 0))
+      if (messageKey != null)
       {
         var messages = messages;
-        
-        if ((messages == (void 0)) ||
-            (messages[messageKey] == (void 0)))
+        if ((messages == null) ||
+            (messages[messageKey] == null))
           throw  new TrConverterException(null, null, "Conversion failed, but no appropriate message found");  // default error format
         else
         {



Mime
View raw message