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 [5/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
Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.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/MessageData.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/MessageDataModel.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/MessageDataModel.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/MessageDataModel.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,211 @@
+/*
+ *  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.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.model.DataModel;
+
+import javax.mail.FetchProfile;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+/**
+ * Implementation of DataModel that creates "MessageData" objects
+ * (cached MessageData instances).
+ * As we don't support sorting, and JavaMail only identifies
+ * messages by index, we only need to implement DataModel.
+ * @todo We don't currently deliver DataModelEvents.
+ */
+public class MessageDataModel extends DataModel
+{
+  public MessageDataModel(
+    Folder       folder,
+    FetchProfile fetchProfile,
+    int          blockSize)
+  {
+    setWrappedData(folder);
+    _blockSize = blockSize;
+    _fetchProfile   = fetchProfile;
+  }
+
+  @Override
+  public int getRowCount()
+  {
+    return _count;
+  }
+
+  @Override
+  public boolean isRowAvailable()
+  {
+    int index = getRowIndex();
+    return (index >= 0) && (index < getRowCount());
+  }
+
+  @Override
+  public Object getRowData()
+  {
+    if (!isRowAvailable())
+      return null;
+
+    int index = getRowIndex();
+    
+    // Flip the indices around
+    pageInRowIndex(index);
+    return _loaded[index];
+  }
+
+  @Override
+  public void setRowIndex(int index)
+  {
+    if (index < -1)
+      throw new IllegalArgumentException();
+
+    _rowIndex = index;
+  }
+
+  @Override
+  public int getRowIndex()
+  {
+    return _rowIndex;
+  }
+
+  @Override
+  public Object getWrappedData()
+  {
+    return _folder;
+  }
+
+  @Override
+  public void setWrappedData(Object data)
+  {
+    Folder newFolder = (Folder) data;
+    _folder = newFolder;
+    _rowIndex = -1;
+
+    if (newFolder != null)
+    {
+      try
+      {
+        _count = _folder.getMessageCount();
+      }
+      // Need to handle more cleanly
+      catch (MessagingException me)
+      {
+        _count = 0;
+        _LOG.log(Level.SEVERE, "Could not get message count",  me);
+      }
+    }
+    else
+    {
+      _count = 0;
+    }
+
+    _loaded = new MessageData[_count];
+  }
+
+  private int _getFlippedIndex(int index)
+  {
+    return getRowCount() - index - 1;
+  }
+
+  /**
+   * Pages in a row index, making sure that it (and all other
+   * messages in its block) are available.
+   */
+  public void pageInRowIndex(int index)
+  {
+    if (_loaded[index] == null)
+    {
+
+      try
+      {
+        if (_LOG.isLoggable(Level.FINEST))
+        {
+          _LOG.finest("total messages before open:"+_folder.getMessageCount());
+        }
+
+        _folder.open(Folder.READ_ONLY);
+        // after the folder is opened, the count may change:
+        _count = _folder.getMessageCount();
+
+        // Calculate "from" and "to", zero-indexed
+        // Round down to the start of the block
+        int fromIndex = (index / _blockSize) * _blockSize;
+        int toIndex = fromIndex + _blockSize - 1;
+        if (toIndex >= _count)
+          toIndex = _count - 1;
+
+        try
+        {
+          // Retrieve the messages from the one-indexed Javamail API
+          int jmFromIndex = _getFlippedIndex(toIndex) + 1;
+          int jmToIndex = _getFlippedIndex(fromIndex) + 1;
+          if (_LOG.isLoggable(Level.FINEST))
+            _LOG.finest("fetching messages from:"+jmFromIndex+
+                        " to:"+jmToIndex+
+                        " total:"+ getRowCount() +
+                        " actual total:"+_folder.getMessageCount());
+          Message[] messages = _folder.getMessages(
+                                  jmFromIndex,
+                                  jmToIndex);
+          _folder.fetch(messages, _fetchProfile);
+          for (int i = 0; i < messages.length; i++)
+          {
+            Message message = messages[messages.length - i - 1];
+            _loaded[i + fromIndex] = new MessageData(message);
+          }
+        }
+        finally
+        {
+          _folder.close(false);
+        }
+      }
+      // This is poor;  for starters, the page is likely
+      // already displaying, so it's too late to show an error message.
+      // We should try paging in rows up front via a RangeChangeListener to
+      // catch the earlier and provide useful errors.
+      catch (MessagingException me)
+      {
+        _LOG.log(Level.SEVERE, me.getMessage(), me);
+        FacesMessage errorMessage = new FacesMessage(
+                          FacesMessage.SEVERITY_ERROR,
+                          me.getMessage(),
+                          me.getStackTrace().toString());
+
+        FacesContext context = FacesContext.getCurrentInstance();
+        context.addMessage(null, errorMessage);
+      }
+    }
+  }
+
+  private Folder    _folder;
+  private int       _rowIndex;
+  private int       _count;
+  private int       _blockSize;
+  private MessageData[] _loaded;
+  private FetchProfile _fetchProfile;
+
+  static private final Logger _LOG =
+    Logger.getLogger(MessageDataModel.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.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/MessageDataModel.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/MessageUtils.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/MessageUtils.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/MessageUtils.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,112 @@
+/*
+ *  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.text.MessageFormat;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+public class MessageUtils
+{
+  static public FacesMessage getErrorMessage(
+    FacesContext          context,
+    String                key,
+    Object[]              params)
+  {
+    return getMessage(context, key, FacesMessage.SEVERITY_ERROR, params);
+  }
+
+  static public FacesMessage getMessage(
+    FacesContext          context,
+    String                key,
+    FacesMessage.Severity severity,
+    Object[]              params)
+  {
+    Locale locale = context.getViewRoot().getLocale();
+    ResourceBundle bundle = ResourceBundle.getBundle(
+        "org.apache.myfaces.trinidaddemo.email.resource.EmailDemoBundle",
+        locale,
+        Thread.currentThread().getContextClassLoader());
+
+    String summary;
+    String detail;
+
+    try
+    {
+      summary = bundle.getString(key);
+    }
+    catch (Exception e)
+    {
+      _LOG.log(Level.SEVERE, "Can't load key " + key, e);
+      summary = "???" + key + "???";
+    }
+
+    try
+    {
+      detail = bundle.getString(key + "_detail");
+    }
+    catch (Exception e)
+    {
+      detail = null;
+    }
+
+    summary = _format(summary, params);
+    detail = _format(detail, params);
+
+    return new FacesMessage(severity, summary, detail);
+  }
+
+  static public String getString(FacesContext context, String key)
+  {
+    try
+    {
+      Locale locale = context.getViewRoot().getLocale();
+      ResourceBundle bundle = ResourceBundle.getBundle(
+        "org.apache.myfaces.trinidaddemo.email.resource.EmailDemoBundle",
+        locale,
+        Thread.currentThread().getContextClassLoader());
+      return bundle.getString(key);
+    }
+    catch (Exception e)
+    {
+      _LOG.log(Level.SEVERE, "Can't load key " + key, e);
+      return "???" + key + "???";
+    }
+  }
+
+
+  static private String _format(String mask, Object[] params)
+  {
+    if ((mask == null) || (params == null))
+      return mask;
+
+    return MessageFormat.format(mask, params);
+  }
+
+  private MessageUtils()
+  {
+  }
+
+  static private final Logger _LOG =
+    Logger.getLogger(MessageUtils.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.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/MessageUtils.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/MessagesBackingBean.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/MessagesBackingBean.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/MessagesBackingBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,208 @@
+/*
+ *  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.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.myfaces.trinidad.component.UIXTable;
+import org.apache.myfaces.trinidad.event.RangeChangeEvent;
+
+/**
+ * Backing bean for the "messages" page.
+ */
+public class MessagesBackingBean
+{
+  public MessagesBackingBean()
+  {
+  }
+
+  public String compact() throws MessagingException
+  {
+    Folder folder = _folderData.getFolder();
+    
+    folder.open(Folder.READ_WRITE);
+    // It would be much more efficient to simply trim out
+    // the list of "expunged" messages from the data model;
+    // instead, we're refreshing the list.
+    folder.expunge();
+    folder.close(true);
+
+    return refresh();
+  }
+
+
+  public String refresh()
+  {
+    _folderData.flush();
+    first();
+    return null;
+  }
+
+
+  public void setFolder(FolderData folder)
+  {
+    _folderData = folder;
+  }
+
+  public FolderData getFolder()
+  {
+    return _folderData;
+  }
+
+  public void setMessagesTable(UIXTable table)
+  {
+    _messagesTable = table;
+  }
+
+  public UIXTable getMessagesTable()
+  {
+    return _messagesTable;
+  }
+
+  public boolean isFirstEnabled()
+  {
+    return _messagesTable.getFirst() > 0;
+  }
+
+  public boolean isLastEnabled()
+  {
+    return (_messagesTable.getFirst() + _messagesTable.getRows()) <  
+                _messagesTable.getRowCount();
+  }
+
+  public String first()
+  {
+    _messagesTable.setFirst(0);
+    return null;
+  }
+
+  public String last()
+  {
+    // The last row is the row count minus 1
+    int lastRow = _messagesTable.getRowCount() - 1;
+    if (lastRow >= 0)
+    {
+      int rows = _messagesTable.getRows();
+      _messagesTable.setFirst((lastRow / rows) * rows);
+    }
+
+    return null;
+  }
+
+  /**
+   * Remember the "first" row for the table.  If we didn't
+   * do this, there wouldn't be any issue as we page from
+   * row to row within this page.  The problem comes when
+   * we <em>return</em> to this folder (after showing a message,
+   * for example).  There ought to be a better solution to this
+   * problem.
+   */ 
+  public void saveFirst(RangeChangeEvent event)
+  {
+    _folderData.setStartIndex(event.getNewStart());
+  }
+
+  public void performDelete(ActionEvent event)
+  {
+    Iterator<?> selection = _messagesTable.getSelectedRowKeys().iterator();
+    // Nothing was selected
+    if (selection.hasNext())
+    {
+      try
+      {
+        // Save the old row key
+        Object oldRowKey = _messagesTable.getRowKey();
+
+        Folder folder = _folderData.getFolder();
+        folder.open(Folder.READ_WRITE);
+        List<Message> messageList = new ArrayList<Message>();
+        try
+        {
+          while (selection.hasNext())
+          {
+            String rowKey = (String) selection.next();
+            _messagesTable.setRowKey(rowKey);
+            MessageData message = (MessageData) _messagesTable.getRowData();
+            if (message == null)
+            {
+              _LOG.log(Level.WARNING, "Couldn't find message for row {0}",
+                       rowKey);
+            }
+            else
+            {
+              _LOG.log(Level.FINE, "Attempting to delete message {0}",
+                       message.getSubject());
+              // Get the actual Message object
+              messageList.add(message.getMessage());
+            }
+          }
+
+          Message[] messages = 
+            messageList.toArray(new Message[messageList.size()]);
+          folder.setFlags(messages, new Flags(Flags.Flag.DELETED), true);
+          // clear the selection:
+          _messagesTable.getSelectedRowKeys().clear();
+          // refresh the folder so that the little 'deleted' icons show up:
+          refresh();
+        }
+        finally
+        {
+          // Restore the old key
+          _messagesTable.setRowKey(oldRowKey);
+          folder.close(false);
+        }
+      }
+      catch (MessagingException me)
+      {
+        _LOG.log(Level.WARNING, "Couldn't delete", me);
+        FacesContext context = FacesContext.getCurrentInstance();
+        FacesMessage message =
+           MessageUtils.getErrorMessage(context,
+                                        "COULD_NOT_DELETE",
+                                        new Object[]{me.getMessage()});
+        context.addMessage(null, message);
+
+      }
+    }
+    else
+    {
+      _LOG.fine("No messages were selected.");
+    }
+  }
+
+  private UIXTable _messagesTable;
+  private FolderData _folderData;
+
+  static private final Logger _LOG =
+    Logger.getLogger(MessagesBackingBean.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.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/MessagesBackingBean.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/NewMessageBackingBean.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/NewMessageBackingBean.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/NewMessageBackingBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,435 @@
+/*
+ *  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.InputStream;
+import java.io.IOException;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+import javax.mail.BodyPart;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Multipart;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.Transport;
+
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.trinidad.model.UploadedFile;
+
+/**
+ * Backing bean for the "show message" page.  Provides some
+ * getters for things that aren't quite JavaBeans on the Message API.
+ */
+public class NewMessageBackingBean
+{
+  public NewMessageBackingBean()
+  {
+  }
+
+  public void setAccount(AccountData account)
+  {
+    _account = account;
+  }
+
+  public AccountData getAccount()
+  {
+    return _account;
+  }
+
+  public void validateEmailList(FacesContext context,
+                                UIComponent  component,
+                                Object       value) throws ValidatorException
+  {
+    if (value == null)
+      return;
+
+    try
+    {
+      _getEmailList(value.toString());
+    }
+    catch (AddressException ae)
+    {
+      throw new ValidatorException(
+       MessageUtils.getErrorMessage(context,
+                                    "EMAIL_LIST_ERROR",
+                                    new Object[]{ae.getRef()}));
+
+    }
+  }
+
+  public String getTo()
+  {
+    return _to;
+  }
+
+  public void setTo(String to)
+  {
+    _to = to;
+  }
+
+
+  public String getCc()
+  {
+    return _cc;
+  }
+
+  public void setCc(String cc)
+  {
+    _cc = cc;
+  }
+
+  public String getContent()
+  {
+    return _content;
+  }
+
+  public void setContent(String content)
+  {
+    _content = content;
+  }
+
+  public String getSubject()
+  {
+    return _subject;
+  }
+
+  public void setSubject(String subject)
+  {
+    _subject = subject;
+  }
+
+  public UploadedFile getAttachment1()
+  {
+    return _attachment1;
+  }
+
+  public void setAttachment1(UploadedFile attachment1)
+  {
+    _attachment1 = attachment1;
+  }
+
+  public UploadedFile getAttachment2()
+  {
+    return _attachment2;
+  }
+
+  public void setAttachment2(UploadedFile attachment2)
+  {
+    _attachment2 = attachment2;
+  }
+
+
+  public UploadedFile getAttachment3()
+  {
+    return _attachment3;
+  }
+
+  public void setAttachment3(UploadedFile attachment3)
+  {
+    _attachment3 = attachment3;
+  }
+
+  public String send()
+  {
+    Session session = _getSession();
+    Message msg = _setupMessage(new MimeMessage(session));
+    if (msg == null)
+    {
+      _LOG.info("Could not create Message object for " + getSubject());
+      return null;
+    }
+
+    try
+    {
+      Transport.send(msg);
+    }
+    catch (MessagingException me)
+    {
+      _showSendException(me);
+      return null;
+    }
+
+    _LOG.info("Sent succesfully");
+
+    try
+    {
+      Store store = _account.getStore();
+      // =-=AEW Hardcoding "Sent" as the folder to save "Sent" messages
+      Folder folder = store.getFolder("Sent");
+      if (folder == null)
+      {
+        // Can "folder" be null here?
+        throw new IllegalStateException("\"Sent\" folder was null");
+      }
+      else
+      {
+        if (!folder.exists())
+          folder.create(Folder.HOLDS_MESSAGES);
+
+        folder.appendMessages(new Message[]{msg});
+      }
+    }
+    // Need to do something better;  like a "Warning: message sent, but not
+    // saved" message for the user?
+    catch (Exception e)
+    {
+      _LOG.log(Level.WARNING, "Couldn't save message in \"Sent\" folder", e);
+    }
+
+    return "sentMessage";
+  }
+
+
+  private Session _getSession()
+  {
+    Properties props = new Properties(System.getProperties());
+    if (_account.getSmtpServer() != null)
+      props.put("mail.smtp.host", _account.getSmtpServer());
+    return Session.getInstance(props, null);
+  }
+
+  public String saveAsDraft()
+  {
+    _LOG.info("Beginning send of message " + getSubject());
+
+    Session session = _getSession();
+    Message msg = _setupMessage(new MimeMessage(session));
+    if (msg == null)
+    {
+      _LOG.info("Could not create Message object for " + getSubject());
+      return null;
+    }
+
+    try
+    {
+      Store store = _account.getStore();
+      // =-=AEW Hardcoding "Drafts" as the folder to save drafts
+      Folder folder = store.getFolder("Drafts");
+      if (folder == null)
+      {
+        // Can "folder" be null here?
+        throw new IllegalStateException("\"Drafts\" folder was null");
+      }
+      else
+      {
+        if (!folder.exists())
+          folder.create(Folder.HOLDS_MESSAGES);
+        
+        folder.appendMessages(new Message[]{msg});
+      }
+    }
+    // Need to do something better...
+    catch (Exception e)
+    {
+      _showSendException(e);
+      return null;
+    }
+    
+    // And go back to the current message folder
+    // =-=aew Should be a "popView" thing
+    return "messages";
+  }
+
+  /**
+   * Set up a new message.
+   */
+  private Message _setupMessage(Message msg)
+  {
+    try
+    {
+      String username = _account.getUsername();
+      String from = username + "@" + _account.getDomain();
+      List<InternetAddress> to = _getEmailList(getTo());
+      
+      List<InternetAddress> cc = null;
+      String ccString = getCc();
+      if(ccString != null) 
+      {
+        cc = _getEmailList(ccString);  
+      }
+      
+      msg.setFrom(new InternetAddress(from));
+      if ((to != null) && !to.isEmpty())
+        msg.setRecipients(Message.RecipientType.TO,
+                          to.toArray(new InternetAddress[0]));
+
+      if ((cc != null) && !cc.isEmpty())
+        msg.setRecipients(Message.RecipientType.CC,
+                          cc.toArray(new InternetAddress[0]));
+      msg.setSubject(_subject == null ? "" : _subject);
+      if ((_attachment1 == null) &&
+          (_attachment2 == null) &&
+          (_attachment3 == null))
+      {
+        msg.setText(_content == null ? "" : _content);
+      }
+      // Multipart.
+      else
+      {
+        // Create the message part
+        BodyPart messageBodyPart = new MimeBodyPart();
+
+        // Fill the message
+        messageBodyPart.setText(_content == null ? "" : _content);
+
+        Multipart multipart = new MimeMultipart();
+        multipart.addBodyPart(messageBodyPart);
+
+        if (_attachment1 != null)
+          _addAttachment(multipart, _attachment1);
+        if (_attachment2 != null)
+          _addAttachment(multipart, _attachment2);
+        if (_attachment3 != null)
+          _addAttachment(multipart, _attachment3);
+
+        // Put all the parts in the message
+        msg.setContent(multipart);
+      }
+
+      String mailer = "OracleAdfEmailDemo";
+      msg.setHeader("X-Mailer", mailer);
+      msg.setSentDate(new Date());
+
+      return msg;
+    }
+    catch(AddressException ae)
+    {
+       _showSendException(ae);
+    }
+    catch(MessagingException me)
+    {
+      _showSendException(me);
+    }
+    catch(Exception e)
+    {
+      _showSendException(e);
+    }
+
+    return null;
+  }
+
+  private void _showSendException(Exception e)
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    context.addMessage(null,
+                       new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                                        e.getMessage(), null));
+    _LOG.log(Level.WARNING, "Couldn't send message", e);
+  }
+
+  private void _addAttachment(Multipart multipart, UploadedFile file)
+    throws MessagingException
+  {
+    BodyPart messageBodyPart = new MimeBodyPart();
+    DataSource source = new UploadedFileDataSource(file);
+    messageBodyPart.setDataHandler(new DataHandler(source));
+    messageBodyPart.setFileName(file.getFilename());
+    multipart.addBodyPart(messageBodyPart);
+  }
+
+  static private List<InternetAddress> _getEmailList(String values)
+    throws AddressException
+  {
+    ArrayList<InternetAddress> list = new ArrayList<InternetAddress>();
+    StringTokenizer tokens = new StringTokenizer(values.toString(), ",");
+    while (tokens.hasMoreTokens())
+    {
+      String token = tokens.nextToken().trim();
+
+      InternetAddress address = new InternetAddress(token);
+
+      // JavaMail 1.3 API:
+      //InternetAddress address = new InternetAddress(token, false);
+      //address.validate();
+      
+      list.add(address);
+    }
+
+    return list;
+  }
+
+  private AccountData _account;
+
+  private String _subject;
+  private String _to;
+  private String _cc;
+  private String _content;
+  private UploadedFile _attachment1;
+  private UploadedFile _attachment2;
+  private UploadedFile _attachment3;
+
+  private static final class UploadedFileDataSource implements DataSource
+  {
+    public UploadedFileDataSource(UploadedFile file)
+    {
+      _file = file;
+      _LOG.info("Source for uploaded file " + file.getFilename() + " with " + file.getLength() + " bytes");
+    }
+
+    public String getContentType()
+    {
+      return _file.getContentType();
+    }
+
+    public InputStream getInputStream() throws IOException
+    {
+      return _file.getInputStream();
+    }
+
+    public String getName()
+    {
+      return _file.getFilename();
+    }
+
+    public java.io.OutputStream getOutputStream()
+    {
+      return null;
+    }
+
+    private final UploadedFile _file;
+  }
+
+
+  static private final Logger _LOG =
+    Logger.getLogger(ShowMessageBackingBean.class.getName());
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.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/NewMessageBackingBean.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/PreferencesData.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/PreferencesData.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/PreferencesData.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,270 @@
+/*
+ *  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.ArrayList;
+import java.util.List;
+import javax.faces.model.SelectItem;
+
+/**
+ * Bean which provides preferences data
+ *
+ * @version 1.0
+ */
+public class PreferencesData
+{
+  /**
+   * Branding type for "regular" branding, which includes the
+   * corporate brand, a large product brand, and global button
+   * icons.
+   */
+  public static String REGULAR_BRANDING = "regular";
+
+  /**
+   * Branding type for "medium" branding, which includes the
+   * corporate brand, a smaller product brand, and no global
+   * button icons
+   */
+  public static String MEDIUM_BRANDING = "medium";
+
+  /**
+   * Branding type for "small" branding, which includes the
+   * corporate brand, no product brand, and no global
+   * button icons
+   */
+  public static String SMALL_BRANDING = "small";
+
+  /**
+   * Creates a PreferencesData object with default preferences
+   */
+  public PreferencesData()
+  {
+    // need public accesibility mode constants declared in Trinidad!
+    _branding = REGULAR_BRANDING;
+    _rowsShown = _DEFAULT_ROWS_SHOWN;
+    _displayFolderTree = true;
+    _displaySenderColumn = true;
+    _displayDateColumn = true;
+    _displaySizeColumn = true;
+    _skinFamily = "oracle";
+    _accessibilityMode = "default";
+  }
+
+
+  /**
+   * @todo Provide internationalized list.
+   */
+  public List<SelectItem> getSkinFamilyItems()
+  {
+    return _SKIN_FAMILIES;
+  }
+
+
+  /**
+   * @todo Provide internationalized list.
+   */
+  public List<SelectItem> getAccessibilityModeItems()
+  {
+    return _ACCESSIBILITY_MODES;
+  }
+
+  /**
+   * Returns the skin-family for the application.
+   */
+  public String getSkinFamily()
+  {
+    return _skinFamily;
+  }
+
+
+  /**
+   * Returns the skin-family for the application.
+   */
+  public void setSkinFamily(String skinFamily)
+  {
+    _skinFamily = skinFamily;
+  }
+
+  /**
+   * Returns the AccessibilityMode for this user
+   */
+  public String getAccessibilityMode()
+  {
+    return _accessibilityMode;
+  }
+
+
+  /**
+   * Returns the branding type: REGULAR_BRANDING,
+   * MEDIUM_BRANDING or SMALL_BRANDING
+   */
+  public String getBranding()
+  {
+    return _branding;
+  }
+
+  /**
+   * Returns the numbers of rows to display in the messages table.
+   */
+  public int getRowsShown()
+  {
+    return _rowsShown;
+  }
+
+  /**
+   * Gets whether the SideBar with the folder tree is displayed
+   */
+  public boolean getDisplayFolderTree()
+  {
+    return _displayFolderTree;
+  }
+
+  /**
+   * Sets whether the SideBar with the folder tree is displayed
+   */
+  public void setDisplayFolderTree(boolean isDisplayed)
+  {
+    _displayFolderTree = isDisplayed;
+  }
+
+  /**
+   * Gets whether the sender column is displayed
+   */
+  public boolean getDisplaySenderColumn()
+  {
+    return _displaySenderColumn;
+  }
+
+  /**
+   * Sets whether the sender column is displayed
+   */
+  public void setDisplaySenderColumn(boolean isDisplayed)
+  {
+    _displaySenderColumn = isDisplayed;
+  }
+
+  /**
+   * Gets whether the date column is displayed
+   */
+  public boolean getDisplayDateColumn()
+  {
+    return _displayDateColumn;
+  }
+
+  /**
+   * Sets whether the date column is displayed
+   */
+  public void setDisplayDateColumn(boolean isDisplayed)
+  {
+    _displayDateColumn = isDisplayed;
+  }
+
+  /**
+   * Gets whether the size column is displayed
+   */
+  public boolean getDisplaySizeColumn()
+  {
+    return _displaySizeColumn;
+  }
+
+  /**
+   * Sets whether the size column is displayed
+   */
+  public void setDisplaySizeColumn(boolean isDisplayed)
+  {
+    _displaySizeColumn = isDisplayed;
+  }
+
+  /**
+   * Gets whether the user wants to preview the email message underneath
+   * the message list
+   */
+  public boolean isPreviewMessageMode()
+  {
+    return _isPreviewMessageMode;
+  }
+
+  /**
+   * Sets whether the user wants to preview the email message underneath
+   * the message list
+   */
+  public void setPreviewMessageMode(boolean enable)
+  {
+    _isPreviewMessageMode = enable;
+  }
+
+  /**
+   * Sets the AccessibilityMode for this user.
+   */
+  public void setAccessibilityMode(String accessibilityMode)
+  {
+    _accessibilityMode = accessibilityMode;
+  }
+
+  /**
+   * Sets the branding.  Must be one of: REGULAR_BRANDING,
+   * MEDIUM_BRANDING, or SMALL_BRANDING.
+   */
+  public void setBranding(String branding)
+  {
+    // assert (REGULAR_BRANDING.equals(branding) ||
+  //    MEDIUM_BRANDING.equals(branding)  ||
+  //    SMALL_BRANDING.equals(branding));
+
+    _branding = branding;
+  }
+
+  /**
+   * Sets the number of rows to show in the messages table.
+   */
+  public void setRowsShown(int rowsShown)
+  {
+    // assert rowsShown > 0;
+
+    if (rowsShown > 0)
+      _rowsShown = rowsShown;
+  }
+
+  private String  _accessibilityMode;  // The accessibility mode
+  private String  _branding;          // The branding type
+  private String  _skinFamily;          // The skin-family
+  private int     _rowsShown;         // How many rows to show
+  private boolean _displayFolderTree;
+  private boolean _displaySenderColumn;
+  private boolean _displayDateColumn;
+  private boolean _displaySizeColumn;
+  private boolean _isPreviewMessageMode = false;
+
+  private static final int _DEFAULT_ROWS_SHOWN = 25;
+
+  private static final List<SelectItem> _ACCESSIBILITY_MODES = new ArrayList<SelectItem>();
+  static
+  {
+    _ACCESSIBILITY_MODES.add(new SelectItem("default", "Default"));
+    _ACCESSIBILITY_MODES.add(new SelectItem("inaccessible", "None"));
+    _ACCESSIBILITY_MODES.add(new SelectItem("screenReader", "Screen Readers"));
+  }
+
+  private static final List<SelectItem> _SKIN_FAMILIES = new ArrayList<SelectItem>();
+  static
+  {
+    _SKIN_FAMILIES.add(new SelectItem("oracle", "Oracle"));
+    _SKIN_FAMILIES.add(new SelectItem("minimal", "Minimal"));
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.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/PreferencesData.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/RelativeDateConverter.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/RelativeDateConverter.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/RelativeDateConverter.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,98 @@
+/*
+ *  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.text.DateFormat;
+import java.text.MessageFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.faces.component.UIComponent;
+import javax.faces.convert.Converter;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+public class RelativeDateConverter implements Converter
+{
+  public RelativeDateConverter()
+  {
+  }
+
+  public String getAsString(FacesContext context, UIComponent component,
+                            Object value)
+  {
+    if (value == null)
+      return null;
+
+    if (!(value instanceof Date))
+      return value.toString();
+
+    Date date = (Date) value;
+
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    TimeZone tz = afContext.getTimeZone();
+    if (tz == null)
+      tz = TimeZone.getDefault();
+
+    Locale locale = context.getViewRoot().getLocale();
+    if (_isToday(date, tz, locale))
+    {
+      DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT,
+                                                     locale);
+      String dateString = format.format(date);
+      String todayMask = MessageUtils.getString(context, "TODAY_MASK");
+      return MessageFormat.format(todayMask, new Object[]{dateString});
+    }
+    else
+    {
+      DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT,
+                                                         DateFormat.SHORT,
+                                                         locale);
+      return format.format(date);
+    }
+  }
+
+  public Object getAsObject(FacesContext context, UIComponent component,
+                            String value)
+  {
+    throw new UnsupportedOperationException();
+  }
+
+  static private boolean _isToday(Date date, TimeZone tz, Locale locale)
+  {
+    Calendar calendar = Calendar.getInstance(tz, locale);
+    calendar.setTime(date);
+
+    int year = calendar.get(Calendar.YEAR);
+    int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
+
+    calendar.setTime(new Date());
+    if ((year == calendar.get(Calendar.YEAR)) &&
+        (dayOfYear == calendar.get(Calendar.DAY_OF_YEAR)))
+    {
+      return true;
+    }
+    else
+    {
+      return false;
+    }
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.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/RelativeDateConverter.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/ReplyToMessageBackingBean.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/ReplyToMessageBackingBean.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/ReplyToMessageBackingBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,116 @@
+/*
+ *  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.logging.Level;
+import java.util.logging.Logger;
+
+import javax.mail.Address;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+/**
+ * Backing bean for the "reply-to message" page.
+ * @todo For now, the original contents are not included in the reply
+ * We could add a preference so the user can choose to include
+ * the original contents in replies
+ */
+public class ReplyToMessageBackingBean extends NewMessageBackingBean
+{
+  public ReplyToMessageBackingBean()
+  {
+    // if the user pressed the Reply button, then the pageFlowScope's
+    // replyToAll value will be false. If the user pressed the
+    // Reply to All button, then the pageFlowScope's replyToAll value
+    // will be true. We set this in the showMessage.jspx page.
+    RequestContext afContext = RequestContext.getCurrentInstance();
+
+    Object replyToAll = afContext.getPageFlowScope().get("replyToAll");
+
+    _setUpReplyToMessage("true".equals(replyToAll));
+  }
+
+  private void _setUpReplyToMessage(boolean replyToAll)
+  {
+    RequestContext afContext = RequestContext.getCurrentInstance();
+
+    MessageData message =
+      (MessageData) afContext.getPageFlowScope().get("message");
+
+    if (message == null) return;
+    Message msg = message.getMessage();
+
+    try
+    {
+        msg.getFolder().open(Folder.READ_ONLY);
+        Message replyMessage = msg.reply(replyToAll);
+
+        setSubject(replyMessage.getSubject());
+        Address[] replyToAddresses = replyMessage.getAllRecipients();
+        setTo(_getAddressString(replyToAddresses));
+
+    }
+    catch (MessagingException e)
+    {
+      _LOG.log(Level.WARNING, "Couldn't create reply-to message", e);
+    }
+    finally
+    {
+
+        try
+        {
+          msg.getFolder().close(false);
+        }
+        catch (Exception e)
+        {
+
+        }
+
+    }
+  }
+
+  /**
+   * Given Address[], return a comma-separated string of the email addresses.
+   * @param replyToAddresses
+   * @return return a comma-separated string of the email addresses.
+   */
+  private String _getAddressString(Address[] replyToAddresses)
+  {
+
+    StringBuffer to = new StringBuffer(100);
+
+    for (int i = 0; i < replyToAddresses.length; i++)
+    {
+      if (i > 0)
+        to.append(",");
+      to.append(((InternetAddress)replyToAddresses[i]).getAddress());
+    }
+
+    return to.toString();
+
+  }
+
+  static private final Logger _LOG =
+    Logger.getLogger(ReplyToMessageBackingBean.class.getName());
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.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/ReplyToMessageBackingBean.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/ShowMessageBackingBean.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/ShowMessageBackingBean.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/ShowMessageBackingBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,161 @@
+/*
+ *  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.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Part;
+
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+/**
+ * Backing bean for the "show message" page. Provides support
+ * for downloading attachments, and hides the fact that the "message"
+ * comes in pageFlowScope from the actual page content.
+ */
+public class ShowMessageBackingBean
+{
+  public ShowMessageBackingBean()
+  {
+    // Code necessary because of:
+    //   https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=22
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    setMessage((MessageData) afContext.getPageFlowScope().get("message"));
+  }
+
+  public MessageData getMessage()
+  {
+    return _message;
+  }
+
+  public void setAttachmentToDownload(Part attachment)
+  {
+    _attachmentToDownload = attachment;
+  }
+
+
+  public Part getAttachmentToDownload()
+  {
+    return _attachmentToDownload;
+  }
+
+
+  public void setMessage(MessageData message)
+  {
+    try
+    {
+      _LOG.log(Level.INFO, "Displaying message {0}", message.getSubject());
+    }
+    catch (MessagingException me)
+    {
+      _LOG.log(Level.SEVERE, "Can't get the subject", me);
+    }
+
+    _message = message;
+  }
+
+  public String downloadAttachment() throws IOException, MessagingException
+  {
+    if (_attachmentToDownload == null)
+    {
+      _LOG.severe("No attachment available");
+      return null;
+    }
+
+    _message.getMessage().getFolder().open(Folder.READ_ONLY);
+
+    InputStream in = _attachmentToDownload.getInputStream();
+
+    FacesContext context = FacesContext.getCurrentInstance();
+    // Get the ServletResponse;  nothing on ExternalContext is sufficient
+    ServletResponse response = (ServletResponse)
+      context.getExternalContext().getResponse();
+    response.setContentType(_attachmentToDownload.getContentType());
+
+    // If the size of the attachment is known, pass that on.
+    int size = _attachmentToDownload.getSize();
+    if (size >= 0)
+    {
+      response.setContentLength(size);
+    }
+
+    if (_LOG.isLoggable(Level.INFO))
+      _LOG.info("Downloading content+ [size=" + size +",contentType=" +
+                _attachmentToDownload.getContentType() + "]");
+
+    if (response instanceof HttpServletResponse)
+    {
+      String filename = _attachmentToDownload.getFileName();
+      if (filename != null)
+      {
+        ((HttpServletResponse) response).setHeader(
+            "Content-disposition",
+            "attachment; filename=\"" + filename + "\"");
+      }
+    }
+
+    // Pass the text along, 128K at a time.
+    try
+    {
+      OutputStream out = response.getOutputStream();
+      try
+      {
+        byte[] buffer = new byte[131072];
+        while (true)
+        {
+          int count = in.read(buffer);
+          if (count < 0)
+            break;
+
+          out.write(buffer, 0, count);
+        }
+      }
+      // Close up the response
+      finally
+      {
+        // And tell JSF that we handled everything
+        context.responseComplete();
+        out.close();
+      }
+    }
+    // And make sure the folder got closed
+    finally
+    {
+      _message.getMessage().getFolder().close(false);
+    }
+
+    return null;
+  }
+
+  private MessageData _message;
+  private Part        _attachmentToDownload;
+
+  static private final Logger _LOG =
+    Logger.getLogger(ShowMessageBackingBean.class.getName());
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.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/ShowMessageBackingBean.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/resource/EmailDemoBundle.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/resource/EmailDemoBundle.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/resource/EmailDemoBundle.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,44 @@
+/*
+ *  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.resource;
+
+import java.util.ListResourceBundle;
+
+public class EmailDemoBundle extends ListResourceBundle
+{
+  @Override
+  public Object[][] getContents()
+  {
+    return _CONTENTS;
+  }
+
+  static private final Object[][] _CONTENTS =
+  {
+    {"TODAY_MASK", "Today, {0}"},
+    {"EMAIL_LIST_ERROR", "Illegal email address."},
+    {"EMAIL_LIST_ERROR_detail", "{0} is not a legal email address."},
+    {"MESSAGE_SENT", "The message was sent successfully."},
+    {"COULD_NOT_DELETE", "Deletion failed."},
+    {"COULD_NOT_DELETE_detail", "The server returned an error: {0}."},
+    {"EMAIL_DEMO_TITLE", "Trinidad Email Demo"},   
+
+    
+  };
+}
+

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.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/resource/EmailDemoBundle.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/nav/DemoNavigationItem.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/nav/DemoNavigationItem.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,106 @@
+/*
+ *  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.nav;
+
+import java.io.Serializable;
+import java.util.List;
+
+
+public class DemoNavigationItem implements Serializable
+{
+  public DemoNavigationItem()
+  {}
+
+
+  public void setLabel(String label)
+  {
+    _label = label;
+  }
+
+  public String getLabel()
+  {
+    return _label;
+  }
+
+  public void setOutcome(String outcome)
+  {
+    _outcome = outcome;
+  }
+
+  public String getOutcome()
+  {
+    return _outcome;
+  }
+
+  public void setViewId(String viewId)
+  {
+    _viewId = viewId;
+  }
+
+  public String getViewId()
+  {
+    return _viewId;
+  }
+
+  // calling this 'ico' instead of 'icon' due to tree bug
+  public void setIco(String icon)
+  {
+    _icon = icon;
+  }
+
+  // calling this 'ico' instead of 'icon' due to tree bug
+  public String getIco()
+  {
+    return _icon;
+  }
+
+
+  public void setDestination(String destination)
+  {
+    _destination = destination;
+  }
+
+  public String getDestination()
+  {
+    return _destination;
+  }
+
+  public List<?> getChildren()
+  {
+    return _children;
+  }
+
+  public void setChildren(List<?> children)
+  {
+    _children = children;
+  }
+
+
+
+
+  private String  _label       = null;
+  private String  _outcome     = null;
+  private String  _viewId      = null;
+  private String  _destination = null;
+  private String  _icon        = null;
+  private List<?> _children    = null;
+
+
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.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/nav/DemoNavigationItem.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/nav/MenuModelAdapter.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/nav/MenuModelAdapter.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,85 @@
+/*
+ *  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.nav;
+
+import java.util.List;
+
+import org.apache.myfaces.trinidad.model.ViewIdPropertyMenuModel;
+
+/**
+ * This class facilitates calling ViewIdPropertyMenuModel.addViewId via
+ * an "aliasList".
+ */
+public class MenuModelAdapter implements java.io.Serializable
+{
+  public MenuModelAdapter()
+  {
+  }
+
+  private ViewIdPropertyMenuModel _model = null;
+  private List<Object> _aliasList = null;
+  private boolean _aliasListAdded = false;
+
+  /**
+   *
+   * @param model an instance of ViewIdPropertyMenuModel
+   */
+  public void setModel(ViewIdPropertyMenuModel model)
+  {
+    _model = model;
+    _aliasListAdded = false;
+
+  }
+
+  public ViewIdPropertyMenuModel getModel()
+  {
+    if (_model != null && !_aliasListAdded)
+    {
+      _aliasListAdded = true;
+      if(_aliasList != null && !_aliasList.isEmpty())
+      {
+        int size = _aliasList.size();
+        if (size % 2 == 1)
+          size = size - 1;
+
+        for ( int i = 0; i < size; i=i+2)
+        {
+          _model.addViewId(_aliasList.get(i).toString(),
+                         _aliasList.get(i+1).toString());
+        }
+      }
+    }
+    return _model;
+  }
+
+  public List<Object> getAliasList()
+  {
+    return _aliasList;
+  }
+
+  /**
+   * aliasList is just a list of viewId strings grouped into pairs.
+   * We iterate over the list like so:
+   * ViewIdPropertyMenuModel.addViewId(aliasList.get(i), aliasList.get(i+1))
+   */
+  public void setAliasList(List<Object> aliasList)
+  {
+    _aliasList = aliasList;
+  }
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.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/nav/MenuModelAdapter.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/resource/SkinBundle.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/resource/SkinBundle.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,37 @@
+/*
+ *  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.resource;
+
+import java.util.ListResourceBundle;
+
+public class SkinBundle extends ListResourceBundle
+{
+  @Override
+  public Object[][] getContents()
+  {
+    return _CONTENTS;
+  }
+
+  static private final Object[][] _CONTENTS =
+  {
+    {"af_tableSelectMany.SELECT_COLUMN_HEADER", "Select A Lot"},
+    {"af_tableSelectOne.SELECT_COLUMN_HEADER", "Select Just One"},
+  };
+}
+

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.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/resource/SkinBundle.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/survey/AnswerValidator.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/survey/AnswerValidator.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,183 @@
+/*
+ *  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.survey;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.application.FacesMessage;
+import javax.faces.validator.Validator;
+
+public class AnswerValidator implements Validator, StateHolder
+{
+
+  public void setQuestionIndex(String index) 
+  {
+    _questionIndex = index;
+  }
+
+  public String getQuestionIndex()
+  {
+    return _questionIndex;
+  }
+
+  public void validate(FacesContext context, UIComponent component, Object value) {
+
+   String userResponse = (String.valueOf(value)).toUpperCase();
+   String correctResponse = lookupAnswer().toUpperCase();
+
+   if(!userResponse.equals(correctResponse))
+   {
+        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+                                            "Incorrect Response",
+                                            lookupCorrectAnswerMsg());
+
+        context.addMessage(component.getClientId(context), msg);
+   }
+   else
+   {
+      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
+                                            "Correct Response",
+                                            "CORRECT!");
+        context.addMessage(component.getClientId(context), msg);
+   }
+ } // end validate()
+
+ // -------------------------------------------------------- Private Methods
+ private String lookupCorrectAnswerMsg()
+  {
+    // based on the current question index
+    // get the answer message from the appropriate question bean
+
+    if (_questionIndex.equals("0"))
+    {
+      return _surveyBean.getQ0().getCorrectAnswerMessage();
+    }
+    else if (_questionIndex.equals("1"))
+    {
+      return _surveyBean.getQ1().getCorrectAnswerMessage();
+    }
+    else if (_questionIndex.equals("2"))
+    {
+      return _surveyBean.getQ2().getCorrectAnswerMessage();
+    }
+    else if (_questionIndex.equals("3A"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(0));
+    }
+    else if (_questionIndex.equals("3B"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(1));
+    }
+    else if (_questionIndex.equals("3C"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(2));
+    }
+    else if (_questionIndex.equals("3D"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(3));
+    }
+    else if (_questionIndex.equals("4"))
+    {
+      return _surveyBean.getQ4().getCorrectAnswerMessage();
+    }
+    else
+    {
+      return ""; // error: passed in incorrect questionindex
+    }
+  } // end getCorrectAnswerMsg()
+
+  private String lookupAnswer()
+  {
+
+    // based on the current question index
+    // get the answer string from the appropriate question bean
+
+    if (_questionIndex.equals("0"))
+    {
+      return String.valueOf(_surveyBean.getQ0().getCorrectIndex());
+    }
+    else if (_questionIndex.equals("1"))
+    {
+      return _surveyBean.getQ1().getCorrectAnswer();
+    }
+    else if (_questionIndex.equals("2"))
+    {
+      return String.valueOf(_surveyBean.getQ2().getCorrectIndex());
+    }
+    else if (_questionIndex.equals("3A"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCheckbox0());
+    }
+    else if (_questionIndex.equals("3B"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCheckbox1());
+    }
+    else if (_questionIndex.equals("3C"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCheckbox2());
+    }
+    else if (_questionIndex.equals("3D"))
+    {
+      return String.valueOf(_surveyBean.getQ3().getCheckbox3());
+    }
+    else if (_questionIndex.equals("4"))
+    {
+      return String.valueOf(_surveyBean.getQ4().getCorrectIndex());
+    }
+    else
+    {
+      return ""; // error: passed in incorrect questionindex
+    }
+  } // end loookupAnswer()
+
+
+  //-------------------------------------------------  StateHolder Methods
+
+  public Object saveState(FacesContext context)
+  {
+    Object values[] = new Object[1];
+    values[0] = _questionIndex;
+    return (values);
+  }
+
+
+  public void restoreState(FacesContext context, Object state)
+  {
+    Object values[] = (Object[]) state;
+    _questionIndex = (String) values[0];
+  }
+
+   public boolean isTransient()
+  {
+    return (_transientValue);
+  }
+
+  public void setTransient(boolean transientValue)
+  {
+    _transientValue = transientValue;
+  }
+
+  
+
+  private String      _questionIndex =  "";
+  private SurveyBean  _surveyBean = new SurveyBean();
+  private boolean     _transientValue = false;
+  
+} // end class AnswerValidator

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.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/survey/AnswerValidator.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/survey/AnswerValidatorTag.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/survey/AnswerValidatorTag.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,59 @@
+/*
+ *  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.survey;
+
+import javax.faces.webapp.ValidatorTag;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+
+public class AnswerValidatorTag extends ValidatorTag
+{
+
+  private String _questionIndex = "";
+  private final String ID = "survey answer validator";
+
+  public AnswerValidatorTag()
+  {
+      super();
+      super.setValidatorId(ID);
+  }
+
+  public void setQuestionIndex(String index)
+  {
+    _questionIndex = index;
+  }
+
+  public String getQuestionIndex()
+  {
+    return _questionIndex;
+  }
+
+  @Override
+  protected Validator createValidator() throws JspException {
+
+      AnswerValidator validator = (AnswerValidator)super.createValidator();
+      validator.setQuestionIndex(_questionIndex);
+
+      //System.out.println("just instantiated " + validator + " with: " + validator.getQuestionIndex());
+      return validator;
+
+  }
+
+
+} // end AnswerValidatorTag

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.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/survey/AnswerValidatorTag.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/survey/CheckboxQuestionBean.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/survey/CheckboxQuestionBean.java?view=auto&rev=515587
==============================================================================
--- incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java (added)
+++ incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java Wed Mar  7 06:44:35 2007
@@ -0,0 +1,253 @@
+/*
+ *  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.survey;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+/***
+ *  class CheckboxQuestionBean
+ *
+ * This bean represents a single multiple-answer checkbox style question.
+ * It has fields for the question prompt, a list of choices, and all the
+ * correct checkboxes in the answer.
+ *
+ * [Note: Due to a lack of support for dynamically iterating through data in
+ * early releases of Trinidad, this bean contains special get methods that help
+ * iterate through the list of choices for printing out on the screen.]
+ *
+ * ***/
+
+public class CheckboxQuestionBean implements QuestionBean, Serializable
+{
+
+ /** The question prompt as a String object */
+ private String   _prompt;
+
+ /** arbitrary number of possible answer choices (Strings) */
+ private ArrayList<String>  _choices;
+
+
+  /** An integer that represents the correct checkbox choices */
+  private int   _correctAnswer;
+
+  /** the booleans to represent the correct choices */
+  private boolean   _checkbox0;
+  private boolean   _checkbox1;
+  private boolean   _checkbox2;
+  private boolean   _checkbox3;
+
+  // a debug flag
+  private boolean debug = false;
+
+
+
+  /**
+    *  Class constructor (no arguments).
+    */
+  public CheckboxQuestionBean()
+  {
+  }
+
+    /**
+     *  Class constructor.
+     */
+    public CheckboxQuestionBean(
+        String prompt,
+        ArrayList<String> choices,
+        int correctAnswer,
+        boolean checkbox0,
+        boolean checkbox1,
+        boolean checkbox2,
+        boolean checkbox3)
+    {
+      _prompt = prompt;
+      _choices = choices;
+      _correctAnswer = correctAnswer;
+
+      _checkbox0 = checkbox0;
+      _checkbox1 = checkbox1;
+      _checkbox2 = checkbox2;
+      _checkbox3 = checkbox3;
+    }
+
+
+  /*** Accessors ***/
+
+ /**
+   *  returns the question prompt.
+   *
+   *  @return the question prompt
+   */
+ public String getPrompt()
+ {
+    // after getting the prompt, we want to initialize the iterator index
+    // for the answers
+  return _prompt;
+ }
+
+
+  public String getText1()
+  {
+    return _choices.get(0);
+  }
+  
+  public String getText2()
+  {
+    return _choices.get(1);
+  }
+  
+  public String getText3()
+  {
+    return _choices.get(2);
+  }
+  
+  public String getText4()
+  {
+    return _choices.get(3);
+  }
+
+  /*** util functions ***/
+
+ 
+  /**
+   * typical toString method
+   *
+   * @return a String representation of a QuestionBean
+   */
+  @Override
+  public String toString()
+  {
+    String str = _prompt + "; " + _choices.toString();
+    return str;
+  }
+
+
+  /**
+   * returns a message describing the correct answer choices.
+   *
+   * @return a message describing the correct answer choices
+   */
+ public String getCorrectAnswerMessage()
+ {
+    String message = "The correct answer is: ";
+    String bitMap = Integer.toBinaryString(_correctAnswer);
+    int i,j;
+    boolean atLeastOneSelected = false;
+
+    // since toBinaryString() library method does not put in leading zeros,
+    // we need to make sure bitMap is as long as NUMBER_OF_ANSWER_CHOICES
+    while (bitMap.length() < SurveyBean.NUMBER_OF_ANSWER_CHOICES)
+    {
+      // prepend leading zeros
+      bitMap = '0' + bitMap;
+    }
+
+    // beginning with the NUMBER_OF_ANSWER_CHOICES-th bit from the right
+    // check until the end of the string
+    for (i=bitMap.length()-SurveyBean.NUMBER_OF_ANSWER_CHOICES, j=0;
+          i<bitMap.length() && j<_choices.size();
+          i++, j++)
+    {
+      // if the considered bit is 1
+      if (debug)
+      {
+        System.out.println("in cbqb, bitMap is: " + bitMap + ", getting " + i + "th char, which is: " + bitMap.charAt(i));
+      }
+      if( bitMap.charAt(i) == '1')
+      {
+         // it's a correct solution
+         message = message + _choices.get(j) + " & ";
+         atLeastOneSelected = true;
+      }
+    } //end for loop
+
+    if (atLeastOneSelected)
+    {
+      // remove extra " & " from end of message
+      message = message.substring(0, message.length()-3);
+    }
+
+    return message;
+ }
+
+
+  /**
+   * Returns a message describing the correct answer for a particular checkbox.
+   *
+   * @param   checkboxNum the index of the checkbox
+   *
+   * @return a message describing the correct answer choices
+   */
+ public String getCorrectAnswerMessage(int checkboxNum)
+ {
+    String message = "INCORRECT";
+//    String message = "The correct answer is: ";
+//
+//    switch (checkboxNum)
+//    {
+//      case(0):
+//        message = message + getCheckbox0();
+//        break;
+//      case(1):
+//        message = message + getCheckbox1();
+//        break;
+//      case(2):
+//        message = message + getCheckbox2();
+//        break;
+//      case(3):
+//        message = message + getCheckbox3();
+//        break;
+//    }
+
+    return message;
+ }
+
+/*** IDE generated accessors ***/
+
+  public boolean getCheckbox0()
+  {
+    return _checkbox0;
+  }
+
+
+  public boolean getCheckbox1()
+  {
+    return _checkbox1;
+  }
+
+
+  public boolean getCheckbox2()
+  {
+    return _checkbox2;
+  }
+
+
+  public boolean getCheckbox3()
+  {
+    return _checkbox3;
+  }
+
+
+  public int getCorrectAnswer()
+  {
+    return _correctAnswer;
+  }
+
+}

Propchange: incubator/adffaces/branches/matzew-core-1.0.0-incubation/examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.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/survey/CheckboxQuestionBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message