incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r515587 [4/19] - in /incubator/adffaces/branches/matzew-core-1.0.0-incubation: ./ examples/ examples/trinidad-demo/ examples/trinidad-demo/src/ examples/trinidad-demo/src/conf/ examples/trinidad-demo/src/main/ examples/trinidad-demo/src/mai...
Date Wed, 07 Mar 2007 14:44:48 GMT
Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,254 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import java.io.IOException;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.NumberConverter;
+import javax.faces.event.ValueChangeEvent;
+import javax.faces.validator.LongRangeValidator;
+
+import org.apache.myfaces.trinidad.component.UIXEditableValue;
+import org.apache.myfaces.trinidad.component.core.output.CoreOutputText;
+import org.apache.myfaces.trinidad.component.core.input.CoreInputText;
+
+/**
+ * An experiment in building a composite component.  Some basic
+ * principles:
+ * <ul>
+ * <li> We're a NamingContainer, so our children won't show up in
+ *   findComponent() calls.
+ * <li> The child components get re-created on each pass through
+ *    the system;  this means seeing if they exist in both Apply Request
+ *    Values (<code>processDecodes</code>) and Render Response
+ *    (<code>encodeBegin()</code>), and marking the components
+ *    transient so they don't get saved.
+ * <li> The model is the tricky part:  instead of using real
+ *   <code>ValueBindings</code> on the children, I let them
+ *   use local values, and then manully transfer over their local values
+ *   into an overall "local value" during validate().  Unfortunately,
+ *   using ValueBindings to automate the transfer wouldn't quite work,
+ *   since the transfer wouldn't happen 'til Update Model, which is
+ *   too late to preserve the semantics of an editable value component in JSF.
+ * <li>Apply Request Values and Update Model don't need to do anything special
+ *  for the children;  they just run as needed.
+ * </ul>
+ * @author Adam Winer
+ */
+public class DateField extends UIXEditableValue implements NamingContainer
+{
+  public DateField()
+  {
+    super(null);
+  }
+
+  @Override
+  public void processDecodes(FacesContext context)
+  {
+    _addChildren(context);
+    super.processDecodes(context);
+  }
+
+  @Override
+  public void validate(FacesContext context)
+  {
+    if (!_month.isValid() ||
+        !_year.isValid() ||
+        !_day.isValid())
+    {
+      setValid(false);
+      return;
+    }
+
+    int year = ((Number) _year.getValue()).intValue();
+    // We'll be 1970 - 2069.  Good enough for a demo.
+    if (year < 70)
+      year += 100;
+
+    int month = ((Number) _month.getValue()).intValue() - 1;
+    int day = ((Number) _day.getValue()).intValue();
+
+    Date oldValue = (Date) getValue();
+    Calendar calendar = Calendar.getInstance();
+    calendar.setLenient(true);
+    calendar.setTime(oldValue);
+    calendar.set(Calendar.YEAR, year);
+    calendar.set(Calendar.MONTH, month);
+    calendar.set(Calendar.DAY_OF_MONTH, day);
+
+    //=-=AEW RUN VALIDATORS!
+
+    // Invalid day given the month
+    if (day != calendar.get(Calendar.DAY_OF_MONTH))
+    {
+      int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
+      FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                    "Invalid date.",
+                    "This month only has " + numberOfDaysInMonth + " days!");
+      setValid(false);
+      context.addMessage(getClientId(context), message);
+    }
+    // Looks good
+    else
+    {
+      setValid(true);
+
+      // And if the value actually changed, store it and send a value change
+      // event.
+      Date newValue = calendar.getTime();
+      if (!calendar.getTime().equals(oldValue))
+      {
+        setValue(newValue);
+        queueEvent(new ValueChangeEvent(this, oldValue, newValue));
+      }
+    }
+  }
+
+  @Override
+  public void encodeBegin(FacesContext context) throws IOException
+  {
+    _addChildren(context);
+    super.encodeBegin(context);
+  }
+
+  @SuppressWarnings("unchecked")
+  @Override
+  public void encodeChildren(FacesContext context) throws IOException
+  {
+    for(UIComponent child : (List<UIComponent>)getChildren())
+    {
+      assert(child.getChildCount() == 0);
+      assert(child.getFacets().isEmpty());
+      child.encodeBegin(context);
+      child.encodeChildren(context);
+      child.encodeEnd(context);
+    }
+  }
+
+  @Override
+  public boolean getRendersChildren()
+  {
+    return true;
+  }
+
+  @SuppressWarnings("unchecked")
+  private void _addChildren(FacesContext context)
+  {
+    if (_month != null)
+      return;
+
+    List<UIComponent> children = getChildren();
+    children.clear();
+
+    Date value = (Date) getValue();
+    Calendar calendar = null;
+    if(value != null)
+    {
+      calendar = Calendar.getInstance();
+      calendar.setLenient(true);
+      calendar.setTime(value);
+    }
+
+    // A proper implementation would add children in the correct
+    // order for the current locale
+    _month = _createTwoDigitInput(context);
+    _month.setId("month");
+    _month.setShortDesc("Month");
+    LongRangeValidator monthRange = _createLongRangeValidator(context);
+    monthRange.setMinimum(1);
+    monthRange.setMaximum(12);
+    _month.addValidator(monthRange);
+    if (value != null)
+      _month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
+
+    _day = _createTwoDigitInput(context);
+    _day.setId("day");
+    _day.setShortDesc("Day");
+    LongRangeValidator dayRange = _createLongRangeValidator(context);
+    dayRange.setMinimum(1);
+    dayRange.setMaximum(31);
+    _day.addValidator(dayRange);
+    if (value != null)
+      _day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
+
+    _year = _createTwoDigitInput(context);
+    _year.setId("year");
+    _year.setShortDesc("Year");
+    if (value != null)
+    {
+      int yearValue = calendar.get(Calendar.YEAR) - 1900;
+      if (yearValue >= 100)
+        yearValue -= 100;
+      _year.setValue(new Integer(yearValue));
+    }
+
+    children.add(_month);
+    children.add(_createSeparator(context));
+    children.add(_day);
+    children.add(_createSeparator(context));
+    children.add(_year);
+  }
+
+  private LongRangeValidator _createLongRangeValidator(FacesContext context)
+  {
+    return (LongRangeValidator)
+      context.getApplication().createValidator(LongRangeValidator.VALIDATOR_ID);
+  }
+
+  private CoreInputText _createTwoDigitInput(FacesContext context)
+  {
+    CoreInputText input = new CoreInputText();
+    input.setColumns(2);
+    input.setMaximumLength(2);
+    input.setTransient(true);
+    input.setRequired(true);
+    input.setSimple(true);
+
+    NumberConverter converter = (NumberConverter)
+      context.getApplication().createConverter(NumberConverter.CONVERTER_ID);
+    converter.setIntegerOnly(true);
+    converter.setMaxIntegerDigits(2);
+    converter.setMinIntegerDigits(2);
+    input.setConverter(converter);
+
+    return input;
+  }
+
+  // A proper implementation would create a separator appropriate
+  // to the current locale
+  private CoreOutputText _createSeparator(FacesContext context)
+  {
+    CoreOutputText output = new CoreOutputText();
+    output.setValue("/");
+    output.setTransient(true);
+    return output;
+  }
+
+  private transient CoreInputText _month;
+  private transient CoreInputText _year;
+  private transient CoreInputText _day;
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateField.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,257 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Map;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.NumberConverter;
+import javax.faces.render.Renderer;
+import javax.faces.validator.LongRangeValidator;
+
+import org.apache.myfaces.trinidad.component.core.input.CoreInputText;
+
+/**
+ * An experiment in building a renderer that uses a composite
+ * component strategy to render.  Some basic principles:
+ * <ul>
+ * <li> The child components get re-created on each pass through
+ *    the system;  this means seeing if they exist in both Apply Request
+ *    Values (<code>decode()</code>) and Render Response
+ *    (<code>encodeBegin()</code>), and marking the components
+ *    transient so they don't get saved.
+ * <li> The model is the tricky part:  instead of using real
+ *   <code>ValueBindings</code> on the children, I let them
+ *   use local values, and then manully transfer over their local values
+ *   into an overall "local value" during validate().  Unfortunately,
+ *   using ValueBindings to automate the transfer wouldn't quite work,
+ *   since the transfer wouldn't happen 'til Update Model, which is
+ *   too late to preserve the semantics of an editable value component in JSF.
+ * </ul>
+ * @author Adam Winer
+ */
+public class DateFieldAsRenderer extends Renderer
+{
+  @SuppressWarnings("unchecked")
+  @Override
+  public void decode(FacesContext context, UIComponent component)
+  {
+    _addChildren(context, component);
+
+    Map<String, UIComponent> attrs = component.getAttributes();
+    if (Boolean.TRUE.equals(attrs.get("readOnly")) ||
+        Boolean.TRUE.equals(attrs.get("disabled")))
+      return;
+
+    // Just clue in component that we have been "submitted" so
+    // that it doesn't short-circuit anything
+    EditableValueHolder evh = (EditableValueHolder) component;
+    evh.setSubmittedValue(Boolean.TRUE);
+
+    // Because these components weren't around during processDecodes(),
+    // they didn't get decoded.  So, run that now.
+    component.getFacet("month").processDecodes(context);
+    component.getFacet("year").processDecodes(context);
+    component.getFacet("day").processDecodes(context);
+  }
+
+  @Override
+  public Object getConvertedValue(
+    FacesContext context,
+    UIComponent  component,
+    Object       submittedValue)
+  {
+    EditableValueHolder monthComp = (EditableValueHolder) component.getFacet("month");
+    EditableValueHolder yearComp = (EditableValueHolder) component.getFacet("year");
+    EditableValueHolder dayComp = (EditableValueHolder) component.getFacet("day");
+
+    if (!monthComp.isValid() ||
+        !yearComp.isValid() ||
+        !dayComp.isValid())
+    {
+      // =-=AEW What to do????????
+      //setValid(false);
+      return null;
+    }
+
+    int year = ((Number) yearComp.getValue()).intValue();
+    // We'll be 1970 - 2069.  Good enough for a demo.
+    if (year < 70)
+      year += 100;
+
+    int month = ((Number) monthComp.getValue()).intValue() - 1;
+    int day = ((Number) dayComp.getValue()).intValue();
+
+    Date oldValue = (Date) ((EditableValueHolder) component).getValue();
+    //Date newValue = (Date) oldValue.clone();
+    Calendar calendar = Calendar.getInstance();
+    calendar.setLenient(true);
+    calendar.setTime(oldValue);
+    calendar.set(Calendar.YEAR, year);
+    calendar.set(Calendar.MONTH, month);
+    calendar.set(Calendar.DAY_OF_MONTH, day);
+    
+    // Invalid day given the month
+    if (day != calendar.get(Calendar.DAY_OF_MONTH))
+    {
+      int numberOfDaysInMonth = day - calendar.get(Calendar.DAY_OF_MONTH);
+      FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                    "Invalid date.",
+                    "This month only has " + numberOfDaysInMonth + " days!");
+      throw new ConverterException(message);
+    }
+
+    return calendar.getTime();
+  }
+
+  @Override
+  public void encodeBegin(FacesContext context,
+                          UIComponent component) throws IOException
+  {
+    _addChildren(context, component);
+  }
+
+  @Override
+  public void encodeChildren(FacesContext context,
+                             UIComponent component) throws IOException
+  {
+    ResponseWriter out = context.getResponseWriter();
+
+    UIComponent month = component.getFacet("month");
+    month.encodeBegin(context);
+    month.encodeChildren(context);
+    month.encodeEnd(context);
+
+    out.writeText("\u00a0/\u00a0", null);
+
+    UIComponent day = component.getFacet("day");
+    day.encodeBegin(context);
+    day.encodeChildren(context);
+    day.encodeEnd(context);
+
+    out.writeText("\u00a0/\u00a0", null);
+
+    UIComponent year = component.getFacet("year");
+    year.encodeBegin(context);
+    year.encodeChildren(context);
+    year.encodeEnd(context);
+  }
+
+  @Override
+  public boolean getRendersChildren()
+  {
+    return true;
+  }
+
+  @SuppressWarnings("unchecked")
+  private void _addChildren(FacesContext context, UIComponent component)
+  {
+    // If the components are already there, bail.
+    if (component.getFacet("month") != null)
+      return;
+
+    String id = component.getId();
+    if (id == null)
+    {
+      id = context.getViewRoot().createUniqueId();
+      component.setId(id);
+    }
+
+    Map<String, UIComponent> facets = component.getFacets();
+    facets.clear();
+
+    Date value = (Date) ((EditableValueHolder) component).getValue();
+    Calendar calendar = null;
+    if(value != null)
+    {
+      calendar = Calendar.getInstance();
+      calendar.setLenient(true);
+      calendar.setTime(value);
+    }
+
+    CoreInputText month = _createTwoDigitInput(context);
+    month.setShortDesc("Month");
+    month.setId(id + "_month");
+
+    LongRangeValidator monthRange = _createLongRangeValidator(context);
+    monthRange.setMinimum(1);
+    monthRange.setMaximum(12);
+    month.addValidator(monthRange);
+    if (value != null)
+      month.setValue(new Integer(calendar.get(Calendar.MONTH) + 1));
+    facets.put("month", month);
+
+    CoreInputText day = _createTwoDigitInput(context);
+    day.setShortDesc("Day");
+    day.setId(id + "_day");
+    LongRangeValidator dayRange = _createLongRangeValidator(context);
+    dayRange.setMinimum(1);
+    dayRange.setMaximum(31);
+    day.addValidator(dayRange);
+    if (value != null)
+      day.setValue(new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
+    facets.put("day", day);
+
+    CoreInputText year = _createTwoDigitInput(context);
+    year.setShortDesc("Year");
+    year.setId(id + "_year");
+    if (value != null)
+    {
+      int yearValue = calendar.get(Calendar.YEAR) - 1900;
+      if (yearValue >= 100)
+        yearValue -= 100;
+      year.setValue(new Integer(yearValue));
+    }
+
+    facets.put("year", year);
+  }
+
+  private LongRangeValidator _createLongRangeValidator(FacesContext context)
+  {
+    return (LongRangeValidator)
+      context.getApplication().createValidator(LongRangeValidator.VALIDATOR_ID);
+  }
+
+  private CoreInputText _createTwoDigitInput(FacesContext context)
+  {
+    CoreInputText input = new CoreInputText();
+    input.setColumns(2);
+    input.setMaximumLength(2);
+    input.setTransient(true);
+    input.setRequired(true);
+    input.setSimple(true);
+
+    NumberConverter converter = (NumberConverter)
+      context.getApplication().createConverter(NumberConverter.CONVERTER_ID);
+    converter.setIntegerOnly(true);
+    converter.setMaxIntegerDigits(2);
+    converter.setMinIntegerDigits(2);
+    input.setConverter(converter);
+
+    return input;
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldAsRenderer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.composite;
+
+import org.apache.myfaces.trinidadinternal.taglib.UIXEditableValueTag;
+
+
+/**
+ * NOTE: a clients may not extend UIXEditableValueTag (or
+ * any other tag classes), as these are not part of the public
+ * API (note the package);  I'm doing it for expedience here.
+ */
+public class DateFieldTag extends UIXEditableValueTag
+{
+  @Override
+  public String getComponentType()
+  {
+    return "org.apache.myfaces.trinidaddemo.DateField";
+  }
+
+  @Override
+  public String getRendererType()
+  {
+    return null;
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/composite/DateFieldTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import javax.faces.convert.Converter;
+import javax.faces.webapp.ConverterTag;
+
+import javax.servlet.jsp.JspException;
+
+
+public class ConvertSSNTag extends ConverterTag
+{
+
+  public ConvertSSNTag()
+  {
+  }
+
+  @Override
+  public int doStartTag() throws JspException
+  {
+    super.setConverterId(SSNConverter.CONVERTER_ID);
+    return super.doStartTag();
+  }
+
+  /**
+   * 
+   */
+  @Override
+  protected Converter createConverter() throws JspException
+  {
+    SSNConverter converter =
+                              (SSNConverter)super.createConverter();
+    return converter;
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ConvertSSNTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,121 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Password validator - this is an incredibly simple
+ * password validator that makes sure there's at least one number
+ * in the password.</p>
+ *
+ */
+public class PasswordValidator implements Validator, ClientValidator
+{
+  public static final String VALIDATOR_ID = "org.apache.myfaces.trinidaddemo.PasswordValidator";
+
+  public void validate(
+    FacesContext context,
+    UIComponent component,
+    Object value) throws ValidatorException
+  {
+
+    String password = "";
+
+    if ( value != null)
+      password = value.toString().trim();
+
+    for (int j = 0;j < password.length();j++)
+    {
+      if (Character.isDigit(password.charAt(j)))
+      {
+        return;
+      }
+    }
+
+    // Using the LabeledFacesMessage allows the <tr:messages> component to
+    // properly prepend the label as a link.
+    LabeledFacesMessage lfm =
+      new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+                              "Validation Error",
+                              "The password must contain at least one number");
+    lfm.setLabel(_getLabel(component));
+    throw new ValidatorException(lfm);
+  }
+
+
+  public String getClientValidation(
+    FacesContext context,
+   UIComponent component)
+  {
+    return (_VALIDATOR_INSTANCE_STRING);
+  }
+
+
+  public Collection<String> getClientImportNames()
+  {
+    return null;
+  }
+
+  public String getClientLibrarySource(
+   FacesContext context)
+  {
+    return context.getExternalContext().getRequestContextPath() + 
+            "/jsLibs/passwordValidator.js";    
+  }
+
+
+  @SuppressWarnings("unchecked")
+  public String getClientScript(
+   FacesContext context,
+   UIComponent component)
+  {
+      return null;
+   }
+
+  private static Object _getLabel(UIComponent component)
+  {
+    Object o = null;
+    if (component != null)
+    {
+      o = component.getAttributes().get("label");
+      if (o == null)
+        o = component.getValueBinding("label");
+    }
+    return o;
+  }
+
+  // in a real app the messages would be translated
+  // The fourth field marker gets the field label
+  private static final String _VALIDATOR_INSTANCE_STRING =
+    "new PasswordValidator({"
+    + "NS:'The password is invalid.',"
+    + "ND:'The password value must contain at least one number.'})";
+
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,180 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.apache.myfaces.trinidad.convert.ClientConverter;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Social Security number converter.</p>
+ *
+ */
+public class SSNConverter implements Converter, ClientConverter
+{
+    public static final String CONVERTER_ID = "org.apache.myfaces.trinidaddemo.SSN";
+
+    public Object getAsObject(
+      FacesContext context,
+      UIComponent component,
+      String value)
+    {
+      // In a real app all the error messages would be translated
+      if ( value == null || value.trim().length() == 0)
+        return null;
+
+      String tValue = value.trim();
+
+      int length = tValue.length();
+      if ( length < 9 )
+      {
+        throw new ConverterException(_getMessage(component, _SHORT_ERROR_TEXT));
+      }
+
+      if ( length > 11 )
+      {
+        throw new ConverterException(_getMessage(component, _LONG_ERROR_TEXT));
+      }
+
+      if (length == 9)
+      {
+        try
+        {
+          return Integer.valueOf(tValue);
+        }
+        catch(NumberFormatException nfe)
+        {
+          throw new ConverterException(_getMessage(component,
+                                                   _INVALID_ERROR_TEXT));
+        }
+      }
+
+      if ( length == 11 &&
+           tValue.charAt(3) == '-' &&
+           tValue.charAt(6) == '-')
+      {
+        String v = tValue.substring(0,3) +
+                   tValue.substring(4,6) +
+                   tValue.substring(7);
+
+        try
+        {
+          return Integer.valueOf(v);
+        }
+        catch(NumberFormatException nfe)
+        {
+          throw new ConverterException(_getMessage(component,
+                                                   _INVALID_ERROR_TEXT));
+        }
+
+      }
+      throw new ConverterException(_getMessage(component, _INVALID_ERROR_TEXT));
+    }
+
+    public String getAsString(
+      FacesContext context,
+      UIComponent component,
+      Object value)
+    {
+      if ( value == null || !(value instanceof Integer))
+        return null;
+
+      Integer integerValue = (Integer)value;
+
+      String valueString = integerValue.toString();
+
+      String ssn = valueString.substring(0,3) + '-' +
+                   valueString.substring(3,5) + '-' +
+                   valueString.substring(5,9);
+      return ssn;
+    }
+
+
+  public Collection<String> getClientImportNames()
+  {
+    return null;
+  }
+
+  public String getClientLibrarySource(
+   FacesContext context)
+  {
+    return context.getExternalContext().getRequestContextPath() + 
+            "/jsLibs/ssnConverter.js";    
+  }
+
+  public String getClientConversion(
+    FacesContext context,
+   UIComponent component)
+  {
+
+    // in a real app the messages would be translated
+    return ("new SSNConverter({"
+            + "SUM:'Invalid social security number.',"
+            + "S:'Value \"{1}\" is too short.',"
+            + "L:'Value \"{1}\" is too long.',"
+            + "N:'Value \"{1}\" is not a valid social security number.'})"
+            );
+  }
+
+  @SuppressWarnings("unchecked")
+  public String getClientScript(
+   FacesContext context,
+   UIComponent component)
+  {
+    return null;
+  }
+  
+  private LabeledFacesMessage _getMessage(
+   UIComponent component,
+   String text)
+  {
+    // Using the LabeledFacesMessage allows the <tr:messages> component to
+    // properly prepend the label as a link.
+    LabeledFacesMessage lfm =
+      new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+                              "Conversion Error", text);
+    if (component != null)
+    {
+      Object label = null;
+      label = component.getAttributes().get("label");
+      if (label == null)
+        label = component.getValueBinding("label");
+      if (label != null)
+        lfm.setLabel(label);
+    }
+    return lfm;
+  }
+
+  private static final String _SHORT_ERROR_TEXT
+    = "The value is too short to be a social security number";
+
+  private static final String _LONG_ERROR_TEXT
+    = "The value is too long to be a social security number";
+
+  private static final String _INVALID_ERROR_TEXT
+    = "The value is not a valid social security number";
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,50 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorTag;
+import javax.servlet.jsp.JspException;
+
+
+public class ValidatePasswordTag extends ValidatorTag
+{
+
+  public ValidatePasswordTag()
+  {
+  }
+
+  @Override
+  public int doStartTag() throws JspException
+  {
+    super.setValidatorId(PasswordValidator.VALIDATOR_ID);
+    return super.doStartTag();
+  }
+
+  /**
+   * 
+   */
+  @Override
+  protected Validator createValidator() throws JspException
+  {
+    PasswordValidator validator =
+                              (PasswordValidator)super.createValidator();
+    return validator;
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,56 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.event.ReturnEvent;
+
+public class ChooseIntegerBean
+{
+  public Integer getValue1()
+  {
+    return _value1;
+  }
+
+  public void setValue1(Integer value1)
+  {
+    _value1 = value1;
+  }
+
+  public Integer getValue2()
+  {
+    return _value2;
+  }
+
+  public void setValue2(Integer value2)
+  {
+    _value2 = value2;
+  }
+
+  public void sayHello(ReturnEvent event)
+  {
+    FacesMessage message = new FacesMessage("Hello!");
+    FacesContext.getCurrentInstance().addMessage(null, message);
+  }
+
+  private Integer _value1;
+  private Integer _value2;
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import java.util.Date;
+import java.util.Map;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.component.UIXInput;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.event.ReturnEvent;
+import org.apache.myfaces.trinidad.event.LaunchEvent;
+import org.apache.myfaces.trinidad.event.PollEvent;
+
+public class LaunchDialogBean
+{
+  public UIXInput getInput()
+  {
+    return _input;
+  }
+
+  public void setInput(UIXInput input)
+  {
+    _input = input;
+  }
+
+  public void addParameter(LaunchEvent event)
+  {
+    // Pass an integer into the dialog.  Some automatic
+    // coercion would really help here (coming in JSF 1.2?)
+    Object value = getInput().getValue();
+    if (value != null)
+    {
+      try
+      {
+        Integer i = Integer.valueOf(value.toString());
+        event.getDialogParameters().put("value", i);
+      }
+      catch (Exception e)
+      {
+      }
+    }
+  }
+
+  public String doLaunch()
+  {
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    Map<String, Object> process = afContext.getPageFlowScope();
+    process.put("lastLaunch", new Date());
+
+    return "dialog:chooseInteger";
+  }
+
+  public void returned(ReturnEvent event)
+  {
+    if (event.getReturnValue() != null)
+    {
+      getInput().setSubmittedValue(null);
+      getInput().setValue(event.getReturnValue());
+
+      RequestContext afContext = RequestContext.getCurrentInstance();
+      afContext.addPartialTarget(getInput());
+
+      FacesContext context = FacesContext.getCurrentInstance();
+      UIViewRoot root = context.getApplication().getViewHandler().createView(
+                           context, "/demos/successDialog.jspx");
+      // Launch a new, success dialog with a different width and height;
+      // this shows how to do so by queueing a LaunchEvent.
+      LaunchEvent launchEvent = new LaunchEvent(event.getComponent(), root);
+      launchEvent.getWindowProperties().put("width", "200");
+      launchEvent.getWindowProperties().put("height", "100");
+      launchEvent.queue();
+    }
+  }
+
+
+  public void poll(PollEvent event)
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    UIViewRoot root = context.getApplication().getViewHandler().createView(
+                           context, "/demos/simpleDialog.jspx");
+
+    // Launch a dialog with a call to RequestContext
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    afContext.launchDialog(root, null, event.getComponent(), true, null);
+    // Stop the poll from running
+    event.getComponent().setRendered(false);
+  }
+
+  public UIXInput getTableInput()
+  {
+    return _tableInput;
+  }
+
+  public void setTableInput(UIXInput tableInput)
+  {
+    _tableInput = tableInput;
+  }
+
+  public void tableReturned(ReturnEvent event)
+  {
+    if (event.getReturnValue() != null)
+    {
+      getTableInput().setValue(event.getReturnValue());
+      RequestContext afContext = RequestContext.getCurrentInstance();
+      afContext.addPartialTarget(getTableInput());
+    }
+  }
+
+  private UIXInput _input;
+  private UIXInput _tableInput;
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,68 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import java.util.Iterator;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.trinidad.component.UIXTable;
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+public class PeriodicDialogBean
+{
+  public UIXTable getTable()
+  {
+    return _table;
+  }
+
+  public void setTable(UIXTable table)
+  {
+    _table = table;
+  }
+
+  public String cancel()
+  {
+    RequestContext.getCurrentInstance().returnFromDialog(null, null);
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  public String select()
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    // The tableSelectOne is marked as required; so there'd better
+    // be a selected row - an exception will result here if there
+    // isn't.  Is there some better code?
+    Iterator<Object> iterator = _table.getSelectedRowKeys().iterator();
+    String rowKey = (String) iterator.next();
+    Object oldRowKey = _table.getRowKey();
+    _table.setRowKey(rowKey);
+    ValueBinding binding = context.getApplication().
+      createValueBinding("#{row.symbol}");
+    Object value = binding.getValue(context);
+    RequestContext.getCurrentInstance().returnFromDialog(value, null);
+    _table.setRowKey(oldRowKey);
+
+    return null;
+  }
+
+  private UIXTable _table;
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,372 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.application.FacesMessage;
+
+import javax.faces.context.FacesContext;
+
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Store;
+
+import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
+import org.apache.myfaces.trinidad.model.TreeModel;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+/**
+ * Root bean which stores information and actions related to the email account
+ *
+ * @version 1.0
+ */
+public final class AccountData implements java.io.Serializable
+{
+
+  public AccountData()
+  {
+    _initializeFromProperties();
+  }
+
+  /**
+   * Returns the user name.
+   */
+  public String getUsername()
+  {
+    return _username;
+  }
+
+  /**
+   * Returns the domain.
+   */
+  public String getDomain()
+  {
+    return _domain;
+  }
+
+  /**
+   * Returns the IMAP server.
+   */
+  public String getServer()
+  {
+    return _server;
+  }
+
+  /**
+   * Returns the SMTP server.
+   */
+  public String getSmtpServer()
+  {
+    return _smtpServer;
+  }
+
+  /**
+   * Returns the password for the current user.
+   */
+  public String getPassword()
+  {
+    return _password;
+  }
+
+  /**
+   * Returns the JavaMail Store object.
+   */
+  public Store getStore()
+  {
+    return _store;
+  }
+
+  /**
+   * Returns the currently selected folder.
+   */
+  public FolderData getCurrentFolder()
+  {
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    return (FolderData) afContext.getPageFlowScope().get("currentFolder");
+  }
+
+  /**
+   * Returns the root folders.
+   */
+  public FolderData[] getRootFolders()
+  {
+    return _rootFolders;
+  }
+
+  /**
+   * Returns the current user's preferences
+   */
+  public PreferencesData getPreferences()
+  {
+    return _preferences;
+  }
+
+  /**
+   * Get the folder model used in the Trinidad tree component showing folders.
+   */
+  public TreeModel getFolderModel()
+  {
+    return _folderModel;
+  }
+
+  /**
+   * Sets the user name.
+   */
+  public void setUsername(String userName)
+  {
+    _username = userName;
+  }
+
+  /**
+   * Sets the domain for the current user.
+   */
+  public void setDomain(String domain)
+  {
+    _domain = domain;
+  }
+
+  /**
+   * Sets the IMAP server for the current user.
+   */
+  public void setServer(String server)
+  {
+    _server = server;
+  }
+
+  /**
+   * Sets the SMTP server.
+   */
+  public void setSmtpServer(String smtpServer)
+  {
+    _smtpServer = smtpServer;
+  }
+
+  /**
+   * Sets the password for the current user.
+   */
+  public void setPassword(String password)
+  {
+    _password = password;
+  }
+
+  /**
+   * Sets the Store.
+   */
+  public void setStore(Store store)
+  {
+    _store = store;
+  }
+
+  /**
+   * Sets the current folder.
+   */
+  public void setCurrentFolder(FolderData folderData)
+  {
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    afContext.getPageFlowScope().put("currentFolder", folderData);
+  }
+
+  /**
+   * Sets the root folders.
+   */
+  public void setRootFolders(FolderData[] rootFolders)
+  {
+    _rootFolders = rootFolders;
+
+    List<Object> rootFolderList = Arrays.asList((Object[]) _rootFolders);
+
+    TreeModel folderTreeModel = new ChildPropertyTreeModel(rootFolderList, "subFolders");
+    setFolderModel(folderTreeModel);
+  }
+
+  /**
+   * Sets the Preferences for the current user.
+   */
+   public void setPreferences(PreferencesData preferences)
+     throws MessagingException
+  {
+    _preferences = preferences;
+
+    // Keep the block size in sync with the current preferences
+  // refreshPreferences(); ???
+  }
+
+  /**
+   * Set the folder model used in the Trinidad tree component showing folders.
+   */
+  public void setFolderModel(TreeModel model)
+  {
+    _folderModel = model;
+  }
+
+
+  /**
+   * Process login. Connect to server and move to folder display page.
+   */
+  public String login()
+  {
+    try
+    {
+      // login to the IMAP server
+      Properties props = new Properties();
+      Session session = Session.getInstance(props, null);
+      Store store = session.getStore("imap");
+      store.connect(_server, _username, _password);
+      setStore(store);
+
+      setRootFolders(FolderData.toFolderData(this, store.getDefaultFolder().list()));
+
+      // TODO: Add logged in indicator to restrict access
+
+      _gotoFolder(null);
+
+      // Set up the user's preferences;  in a real app, these would
+      // be persisted somewhere.
+      PreferencesData preferences = new PreferencesData();
+      setPreferences(preferences);
+    }
+    // catch all exceptions and report them as errors
+    catch (Exception e)
+    {
+      FacesMessage errorMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                                                   e.getMessage(), null);
+
+      FacesContext context = FacesContext.getCurrentInstance();
+    context.addMessage(null, errorMessage);
+
+      return null;
+    }
+
+    return "success";
+  }
+
+  /**
+   * Log out, and close up everything.
+   */
+  public String logout()
+  {
+    destroy();
+
+    setCurrentFolder(null);
+
+    _password = null;
+    _folderModel = null;
+    _rootFolders = null;
+    _preferences = null;
+
+    return "loggedOut";
+  }
+
+  /**
+   * Frees up resources used by this object.
+   */
+  public synchronized void destroy()
+  {
+    if (_store != null)
+    {
+      try
+      {
+        _store.close();
+        _store = null;
+      }
+      catch (MessagingException e)
+      {
+        e.printStackTrace();
+      }
+    }
+  }
+
+  /**
+   * Clean up resources
+   */
+  @Override
+  protected void finalize() throws Throwable
+  {
+    destroy();
+    super.finalize();
+  }
+
+  /**
+   * Go to a specified folder.
+   * @param newFolder the new folder to view. Maybe null, in which case INBOX
+   * will be opened.
+   */
+  private void _gotoFolder(String newFolder)
+    throws MessagingException
+  {
+    if (newFolder==null)
+      newFolder = "INBOX";
+
+    Folder folder  = getStore().getFolder(newFolder);
+    FolderData fdata = new FolderData(this, folder);
+    setCurrentFolder(fdata);
+  }
+
+  // Initialize everything (but the password!) from a .properties file
+  // for convenience
+  private void _initializeFromProperties()
+  {
+    String home = System.getProperty("user.home");
+    File file = new File(home, "adf-email-demo.properties");
+    _LOG.log(Level.FINE, "Loading properties from {0}", file);
+    try
+    {
+      InputStream stream = new FileInputStream(file);
+      Properties properties = new Properties();
+      properties.load(stream);
+
+      setUsername(properties.getProperty("username"));
+      setDomain(properties.getProperty("domain"));
+      setServer(properties.getProperty("server"));
+      String smtp = properties.getProperty("smtpserver");
+      if (smtp == null)
+        smtp = System.getProperty("mail.smtp.host");
+      setSmtpServer(properties.getProperty("smtpserver"));
+    }
+    catch (IOException ioe)
+    {
+      // The file doesn't have to be there.
+      ;
+    }
+  }
+
+  // No real attempt to support failover here, but just trying
+  // not to fail a Serialization test
+  private String _username, _password, _domain, _server;
+  private String _smtpServer;
+  private transient Store _store;
+  private transient TreeModel _folderModel;
+  private transient FolderData[] _rootFolders;
+  private transient PreferencesData _preferences;      // User preferences
+
+  static private final Logger _LOG =
+    Logger.getLogger(AccountData.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import javax.faces.component.UIComponent;
+import javax.faces.convert.Converter;
+import javax.faces.context.FacesContext;
+
+/**
+ * Converter that displays just the name, or the full
+ * e-mail address if the name is not available.
+ */
+public class EmailDisplayConverter implements Converter
+{
+  public EmailDisplayConverter()
+  {
+  }
+
+  public String getAsString(FacesContext context, UIComponent component,
+                            Object value)
+  {
+    if (value == null)
+      return null;
+
+    String val = value.toString();
+    int lessThanIndex = val.indexOf('<');
+    if (lessThanIndex < 0)
+      return val;
+
+    return val.substring(0, lessThanIndex).trim();
+  }
+
+  public Object getAsObject(FacesContext context, UIComponent component,
+                            String value)
+  {
+    throw new UnsupportedOperationException();
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,247 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.model.DataModel;
+
+import javax.mail.Folder;
+import javax.mail.FetchProfile;
+import javax.mail.MessagingException;
+
+/**
+ * Reflects the folder information provided by javaMail folder
+ * @version 1.0
+ */
+public class FolderData
+{
+
+  /**
+   * @param data the user who owns this folder
+   * @param folder the folder being reflected
+   */
+  public FolderData(AccountData data, Folder folder) throws MessagingException
+  {
+    _folder = folder;
+    _accountData = data;
+    _holdsMessages  = (_folder.getType() & Folder.HOLDS_MESSAGES) > 0;
+  }
+
+
+  public void flush()
+  {
+    _messageListModel = null;
+  }
+
+  
+  /**
+   * Returns true if the folder can hold messages.
+   */
+  public boolean isHoldsMessages()
+  {
+    return _holdsMessages;
+  }
+
+  /**
+   * @return the number of messages in this folder
+   */
+  public int getMessageCount() throws MessagingException
+  {
+    // remember, we can only get messages if the type of this folder is
+    // Folder.HOLDS_MESSAGES
+    if (_holdsMessages)
+      return _folder.getMessageCount();
+
+    return 0;
+  }
+
+  /**
+   * @return the number of unread messages in this folder
+   */
+  public int getUnreadMessageCount() throws MessagingException
+  {
+    // remember, we can only get messages if the type of this folder is
+    // Folder.HOLDS_MESSAGES
+    if (_holdsMessages)
+      return _folder.getUnreadMessageCount();
+
+    return 0;
+  }
+
+  /**
+   * @return the index into the list of messages that was last
+   *  used by the messages table.  Stored here to keep it
+   *  scoped to the folder, instead of the session.
+   */
+  public int getStartIndex()
+  {
+    return _startIndex;
+  }
+  
+  /**
+   * Store the index into the list of messages.
+   */
+  public void setStartIndex(int startIndex)
+  {
+    _startIndex = startIndex;
+  }
+
+  /**
+   * gets the name of this folder
+   */
+  public String getName()
+  {
+    return _folder.getName();
+  }
+
+  /**
+   * gets the full name of this folder. This reflects the hierarchy of this
+   * folder.
+   */
+  public String getFullName()
+  {
+    return _folder.getFullName();
+  }
+
+  /**
+   * @return true if this folder is currently selected
+   */
+  /* =-=AEW Not used
+  public boolean isSelected()
+  {
+    return _folder.getFullName().equals
+      (_accountData.getCurrentFolder()._folder.getFullName());
+  }
+  */
+
+  /**
+   * gets this folder's subfolders
+   * @todo Why does this code return "null" instead of the empty list???
+   */
+  @SuppressWarnings("unchecked")
+  public synchronized List<Object> getSubFolders() throws MessagingException
+  {
+    if (_subFolders == Collections.EMPTY_LIST)
+    {
+      return null;
+    }
+    else if (_subFolders == null)
+    {
+      FolderData[] folders = toFolderData(_accountData, _folder.list());
+      if (folders == null)
+      {
+        _subFolders = Collections.EMPTY_LIST;
+        return null;
+      }
+      else
+      {
+        _subFolders = Arrays.asList((Object[]) folders);
+      }
+    }
+
+    return _subFolders;
+  }
+
+  /**
+   * Get the model for the messages in this folder.
+   */
+  public Object getMessageListModel()
+  {
+    if (_holdsMessages)
+    {
+      if (_messageListModel == null)
+      {
+        FetchProfile fetchProfile = new FetchProfile();
+        fetchProfile.add(FetchProfile.Item.ENVELOPE);
+        fetchProfile.add(FetchProfile.Item.FLAGS);
+        _messageListModel = new MessageDataModel(_folder,
+                                                 fetchProfile,
+                                                 _MESSAGE_LOAD_BLOCK_SIZE);
+      }
+
+      return _messageListModel;
+    }
+    else
+    {
+      return null;
+    }
+  }
+
+  /**
+   * converts {@link Folder}s to {@link FolderData}s.
+   */
+  public static FolderData[] toFolderData(AccountData data, Folder[] folders)
+    throws MessagingException
+  {
+    int sz = folders.length;
+    if (sz > 0)
+    {
+      FolderData[] subs = new FolderData[sz];
+      for(int i=0; i<sz; i++)
+      {
+        Folder f = folders[i];
+        subs[i] = new FolderData(data, f);
+      }
+
+      return subs;
+    }
+
+    return null;
+  }
+
+  /**
+   * Get the underlying Folder object.
+   */
+  public Folder getFolder()
+  {
+    return _folder;
+  }
+
+  /**
+   * Action for viewing the messages in this folder.
+   */
+  public String viewMessages()
+  {
+    // update the currentFolder on the account to point to this folder
+    _accountData.setCurrentFolder(this);
+	
+    _LOG.log(Level.FINE, 
+             "Showing messages for folder named {0} ", getName());
+  
+    return "messages";
+  }
+
+  private List<Object>      _subFolders = null;
+  private DataModel         _messageListModel = null;
+  private final Folder      _folder;
+  private final AccountData _accountData;
+  private final boolean     _holdsMessages;
+  private       int         _startIndex;
+  // Load 100 messages at a time (obviously, should be tuneable)
+  private static final int _MESSAGE_LOAD_BLOCK_SIZE = 100;
+
+  static private final Logger _LOG =
+    Logger.getLogger(FolderData.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,503 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Address;
+import javax.mail.BodyPart;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Part;
+
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMultipart;
+import javax.mail.Flags.Flag;
+
+/**
+ * MessageData contains all the information needed to display a UI
+ * for a javax.mail.Message object.  There are methods to get the
+ * sender, the subject, the size, the date, the to list, the cc list,
+ * the content type, the content itself, and the line count of the message.
+ *
+ * @version 1.0
+ */
+public class MessageData
+{
+  /**
+   * Create a new MessageData object given the message object.
+   */
+  public MessageData(Message message) throws MessagingException
+  {
+    _message = message;
+
+    // cache the size just because it involves a calculation
+    _size = message.getSize() / 1024;
+
+    // cache this since the folder has to be open to get this:
+    _isRead = _message.isSet(Flag.SEEN); 
+    _isDeleted = _message.isSet(Flag.DELETED);
+  }
+
+  /**
+   * Get the number of the message in its containing folder.
+   *
+   * @return the message number. this index is based at 1
+   */
+  public int getMessageNumber()
+  {
+    return _message.getMessageNumber();
+  }
+
+  /**
+   * Get the Address object that corresponds to the sender
+   */
+  public Address getSender() throws MessagingException
+  {
+    // we assume that the original sender is the first one
+    return _message.getFrom()[0];
+  }
+
+  /**
+   * Get the subject of the message.  If the subject is empty or null
+   * we return a string <empty> to indicate the subject did not contain
+   * anything.
+   */
+  public String getSubject() throws MessagingException
+  {
+    String subject = _message.getSubject();
+
+    // if the subject is empty than make sure we return something so the
+    // user can click on it to see its contents!  Need to internationalize this.
+    if ( (subject == null) || "".equals(subject) )
+      subject = "<empty>";
+
+    return subject;
+  }
+
+  /**
+   * Get the size of the message in kilobytes.
+   *
+   * @return size in kilo bytes
+   */
+  public int getSize()
+  {
+    return _size;
+  }
+
+  /**
+   * Get the sent date of the message.
+   */
+  public Date getSentDate() throws MessagingException
+  {
+    return _message.getSentDate();
+  }
+
+  /**
+   * Get an array of Address objects that correspond to the list of
+   * addresses the message was sent to.
+   */
+  public Address[] getTos() throws MessagingException
+  {
+    Address[] tos = _message.getRecipients(Message.RecipientType.TO);
+    return tos;
+  }
+
+  /**
+   * Get an array of Address objects that correspond to the list of
+   * addresses the message was cc'd to.
+   */
+  public Address[] getCcs() throws MessagingException
+  {
+    Address[] ccs = _message.getRecipients(Message.RecipientType.CC);
+    return ccs;
+  }
+
+  /**
+   * Get a string representing the content type of the message.  The
+   * string returned is truncated to just show the initial part of the type
+   * like text/plain.  Also if the original message is a more complex type
+   * like multipart, this method will actually search through all the parts
+   * and try and find a text/plain or text/html to make the UI easier to
+   * handle.
+   */
+  public String getContentType() throws MessagingException
+  {
+    // catch IOExceptions and ignore them, because content type really
+    // shouldn't care much about io exceptions
+    try
+    {
+      _tryInit();
+    }
+    catch (IOException ioe)
+    {
+      ;
+    }
+
+    return _contentType;
+  }
+
+  /**
+   * Get an object representing the content type of the message.  If the
+   * original message is a more complex type like multipart, this method
+   * will actually search through all the parts and try and find a
+   * text/plain or text/html to make the UI easier to handle.
+   */
+  public Object getContent() throws MessagingException, IOException
+  {
+    // catch IOExceptions and ignore them, because content type really
+    // shouldn't care much about io exceptions
+    try
+    {
+      _tryInit();
+    }
+    catch (IOException ioe)
+    {
+      ;
+    }
+
+    return _content;
+  }
+
+  /**
+   * Get the number of lines in the message.  If the original message is a
+   * more complex type like multipart, this method will actually search
+   * through all the parts and try and find a text/plain or text/html
+   * and getLineCount() will return the number of messages in that part.
+   */
+  public int getLineCount() throws MessagingException
+  {
+    // catch IOExceptions and ignore them, because content type really
+    // shouldn't care much about io exceptions
+    try
+    {
+      _tryInit();
+    }
+    catch (IOException ioe)
+    {
+      ;
+    }
+
+    return _lineCount;
+  }
+
+
+  /**
+   * Return true if the message has been read yet.
+   */
+  public boolean isRead()
+  {
+    return _isRead;
+  }
+
+  /**
+   * Return true if the message has been deleted.
+   */
+  public boolean isDeleted()
+  {
+    return _isDeleted;
+  }
+  
+  /**
+   * Get the underlying Message Object.
+   */
+  public Message getMessage()
+  {
+    return _message;
+  }
+
+  /**
+   * Get the list of attachments.
+   */ 
+  public List<BodyPart> getAttachments()
+  {
+    return _attachments;
+  }
+
+  /**
+   * Returns true if any attachments are available.
+   */
+  public boolean isAttachmentPresent()
+  {
+    return (_attachments != null) && (!_attachments.isEmpty());
+  }
+
+
+  ////////////////////////////////////////////////////////////////////////////
+  // private methods
+  ////////////////////////////////////////////////////////////////////////////
+  /**
+   * Initialize the linecount, content type, and content once and for all.
+   */
+  synchronized private void _tryInit() throws MessagingException, IOException
+  {
+    // only gather the information if we haven't been initalized yet
+    if (_lineCount == -1)
+    {
+      int count = 0;
+      String contentType = null;
+      Object content = null;
+
+      // open the folder;  open it read-write if the message hasn't yet
+      // been read (in which case we'll need to set it accordingly)
+      _message.getFolder().open(_isRead
+                                ? Folder.READ_ONLY
+                                : Folder.READ_WRITE);
+      
+      List<BodyPart> attachments = new ArrayList<BodyPart>();
+
+      try
+      {
+        // get the linecount, content type, and content
+        count = _message.getLineCount();
+        contentType = _message.getContentType();
+        content = _message.getContent();
+
+        // if its a multipart type then lets look through all the parts
+        // and see if we can find the more interesting text or html ones
+        // so that we can display them better
+        if (contentType.startsWith(_MULTIPART))
+        {
+          if (content instanceof MimeMultipart)
+          {
+            boolean found = false;
+            
+            MimeMultipart mm = (MimeMultipart)content;
+            for (int i=0;i<mm.getCount();i++)
+            {
+              BodyPart bp = mm.getBodyPart(i);
+              
+              if (!found && (bp instanceof MimeBodyPart))
+              {
+                MimeBodyPart mbp = (MimeBodyPart)bp;
+                String type = mbp.getContentType();
+                
+                if (type.startsWith(_HTML_TEXT) ||
+                    type.startsWith(_PLAIN_TEXT) )
+                {
+                  found = true;
+                  count = mbp.getLineCount();
+                  content = mbp.getContent();
+                  contentType = type;
+                  
+                  // be happy with the first thing we find either plain
+                  // text or html, and skip over it as an attachment
+                  continue;
+                }
+              }
+
+              // OK, now let's see if it's an attachment
+              String disp = bp.getDisposition();
+              if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT))
+              {
+                attachments.add(bp);
+              }
+            }
+            
+            // if we don't find something either text or html, and we don't
+            // have any attachments then we are in trouble.  Just throw an
+            // exception and let the code below set things up properly.
+            if (!found)
+            {
+              if (!attachments.isEmpty())
+                content = "";
+              else
+                throw new IllegalStateException();
+            }
+          }
+        }
+
+        // strip of the extra parts of the content type so we return something
+        // like plain/text or html/text
+        int index = contentType.indexOf(';');
+        if (index != -1)
+          contentType = contentType.substring(0, index);
+
+        // Mark it as seen
+        _message.getFlags().add(Flag.SEEN);
+        _isRead = true;
+      }
+      catch (Exception e)
+      {
+        content = "Error trying to display content";
+        count = 1;
+        contentType = _PLAIN_TEXT;
+        attachments.clear();
+      }
+      // always make sure to close the message in case there was an error.
+      finally
+      {
+        _message.getFolder().close(false);
+      }
+
+      _lineCount = count;
+      _contentType = contentType;
+      _content = content;
+      _attachments = attachments;
+    }
+  }
+
+  // this implementation tries very poorly to handle attachments by just
+  // putting them inline.  If we had more time to figure out java mail we
+  // could do something better with attachements
+  /**
+   * Initialize the linecount, content type, and content once and for all.
+  synchronized private void _tryInit() throws MessagingException, IOException
+  {
+    // only gather the information if we haven't been initalized yet
+    if (_lineCount == -1)
+    {
+      int count = 0;
+      String contentType = null;
+      Object content = null;
+
+      // open the folder
+      _message.getFolder().open(Folder.READ_ONLY);
+
+      try
+      {
+        // get the linecount, content type, and content
+        count = _message.getLineCount();
+        contentType = _message.getContentType();
+        content = _message.getContent();
+
+        // if its a multipart type then lets look through all the parts
+        // and see if we can find the more interesting text or html ones
+        // so that we can display them better
+        if (contentType.startsWith(_MULTIPART))
+        {
+            if (content instanceof MimeMultipart)
+            {
+              MimeMultipart mm = (MimeMultipart)content;
+              Object plainContent = null;
+              Object htmlContent = null;
+              int plainCount = 0;
+              int htmlCount = 0;
+
+              // loop through all of the parts.  If we find more than
+              // one plain text than append then all together so we can
+              // display simple attachements better
+              for (int i=0;i<mm.getCount();i++)
+              {
+                BodyPart bp = mm.getBodyPart(i);
+
+                if (bp instanceof MimeBodyPart)
+                {
+                  MimeBodyPart mbp = (MimeBodyPart)bp;
+                  String type = mbp.getContentType();
+
+                  if (type.startsWith(_PLAIN_TEXT))
+                  {
+                    plainCount += mbp.getLineCount();
+                    Object newContent = mbp.getContent();
+
+                    if (plainContent == null)
+                      plainContent = newContent;
+                    else
+                    {
+                      plainContent = plainContent + "\n---------------------------------\n" + newContent;
+                      plainCount++;
+                    }
+                  }
+                  else if (type.startsWith(_HTML_TEXT))
+                  {
+                    htmlCount += mbp.getLineCount();
+                    Object newContent = mbp.getContent();
+
+                    if (htmlContent == null)
+                      htmlContent = newContent;
+                    else
+                    {
+                      htmlContent = htmlContent + "\n---------------------------------\n" + newContent;
+                      htmlCount++;
+                    }
+                  }
+                }
+              }
+
+              // if we found any plain content use that first
+              if (plainContent != null)
+              {
+                count = plainCount;
+                content = plainContent;
+                contentType = _PLAIN_TEXT;
+              }
+              // then html
+              else if (htmlContent != null)
+              {
+                count = htmlCount;
+                content = htmlContent;
+                contentType = _HTML_TEXT;
+              }
+              // if we found neither thrown an exception which we will
+              // catch down below to setup state
+              else
+              {
+                throw new IllegalStateException();
+              }
+            }
+        }
+
+        // strip of the extra parts of the content type so we return something
+        // like plain/text or html/text
+        int index = contentType.indexOf(';');
+        if (index != -1)
+          contentType = contentType.substring(0, index);
+      }
+      catch (Exception e)
+      {
+        content = "Could not display content";
+        count = 0;
+        contentType = _PLAIN_TEXT;
+      }
+      // always make sure to close the message in case there was an error.
+      finally
+      {
+        _message.getFolder().close(false);
+      }
+
+      _lineCount = count;
+      _contentType = contentType;
+      _content = content;
+    }
+  }
+   */
+
+  ////////////////////////////////////////////////////////////////////////////
+  // private variables
+  ////////////////////////////////////////////////////////////////////////////
+  private static final String _PLAIN_TEXT = "TEXT/PLAIN";
+  private static final String _HTML_TEXT = "TEXT/HTML";
+  private static final String _MULTIPART = "multipart";
+
+  private final Message _message;
+  private Object _content = null;
+  private String _contentType= null;
+  private int _lineCount = -1;
+  private int _size;
+  private boolean _isRead;
+  private boolean _isDeleted;
+  private List<BodyPart> _attachments;
+}
+



Mime
View raw message