myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r546977 [5/19] - in /myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo: ./ src/ src/conf/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/myfaces/ src/main/java/...
Date Wed, 13 Jun 2007 17:53:08 GMT
Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java Wed Jun 13 10:52:53 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());
+
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java Wed Jun 13 10:52:53 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"));
+  }
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java Wed Jun 13 10:52:53 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;
+    }
+  }
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java Wed Jun 13 10:52:53 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());
+
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java Wed Jun 13 10:52:53 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());
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java Wed Jun 13 10:52:53 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"},   
+
+    
+  };
+}
+

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java Wed Jun 13 10:52:53 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;
+
+
+
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java Wed Jun 13 10:52:53 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;
+  }
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java Wed Jun 13 10:52:53 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"},
+  };
+}
+

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java Wed Jun 13 10:52:53 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

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java Wed Jun 13 10:52:53 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

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java Wed Jun 13 10:52:53 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;
+  }
+
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java Wed Jun 13 10:52:53 2007
@@ -0,0 +1,123 @@
+/*
+ *  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.List;
+
+/***
+ *  class MultChoiceQuestionBean
+ *
+ * This bean represents a single multiple choice questions.  It has fields for
+ * the question prompt, a list of choices, and the correct answer.
+ *
+ ***/
+
+
+public class MultChoiceQuestionBean implements QuestionBean, Serializable
+{
+  
+  /** Constructors **/
+  
+  /**
+   *  Class constructor (no arguments).
+   */
+  public MultChoiceQuestionBean()
+  {
+  }
+  
+  /**
+   *  Class constructor.
+   */
+  public MultChoiceQuestionBean(String prompt,
+                                List<String> choices,
+                                int correctIndex)
+  {
+    _prompt = prompt;
+    _choices = choices;
+    _correctIndex = correctIndex;
+  }
+
+
+  /*** Accessors ***/
+  /**
+   *  returns the question prompt.
+   *
+   *  @return the question prompt
+   */
+  public String getPrompt()
+  {
+    return _prompt;
+  }
+
+
+  /**
+    *  returns the list of answer strings.
+    */
+  public List<String> getAnswerStrings()
+  {
+    return _choices;
+  }
+
+
+  /**
+   * typical toString method
+   *
+   * @return a String representation of a MultChoiceQuestionBean
+   */
+  @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()
+  {
+    return "The correct answer is: " + _choices.get(_correctIndex);
+  }
+
+  /**
+   * returns the index of the correct answer
+   *
+   * @return the index of the correct answer
+   */
+  public int getCorrectIndex()
+  {
+    return _correctIndex;
+  }
+
+  /* The question as a String object */
+  private String   _prompt;
+  
+  /* arbitrary number of possible answer choices (Strings) */
+  private List<String>  _choices;
+
+  /* The index of the correct answer */
+  private int     _correctIndex;
+
+
+} //end QuestionBean

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java Wed Jun 13 10:52:53 2007
@@ -0,0 +1,38 @@
+/*
+ *  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;
+
+/**
+ */
+public interface QuestionBean
+{
+  /**
+   * returns a message describing the correct answer choices.
+   *
+   * @return a message describing the correct answer choices
+   */
+  public String getCorrectAnswerMessage();
+  
+  /**
+   *  returns the question prompt.
+   *
+   *  @return the question prompt
+   */
+  public String getPrompt();
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java Wed Jun 13 10:52:53 2007
@@ -0,0 +1,582 @@
+/*
+ *  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;
+import java.util.List;
+
+/***
+ *  class SurveyBean
+ *
+ * This is the main backing bean for the Survey Demo project.
+ *  It represents a multiple-choice survey.  It contains state about
+ *  the list of questions to ask in the survey and the user's responses to
+ *  these questions.  It also has methods that help with application
+ *  navigation.
+ *
+ * ***/
+
+public class SurveyBean extends Object implements Serializable
+{
+
+  /** A List of QuestionBean objects */
+  private ArrayList<QuestionBean> _questions = new ArrayList<QuestionBean>();
+
+  /** The index of the (current) question displayed */
+  private int               _currentIndex;
+
+  /** A List of QuestionBean objects */
+  private ArrayList<String> _userAnswers = new ArrayList<String>();
+
+  /** number of choices */
+  static final int NUMBER_OF_ANSWER_CHOICES = 4;
+
+  /** debug flag */
+  private boolean     debug = false;
+
+  /** beans for each question in the survey */
+  MultChoiceQuestionBean _q0;
+
+  TextQuestionBean _q1; // insert a text field question here
+
+  MultChoiceQuestionBean _q2;
+
+  CheckboxQuestionBean _q3; // this is a checkbox question
+
+  MultChoiceQuestionBean _q4;
+
+  /** a String for each user response in the survey */
+  String _a0;   //response for a multiple choice (normal) question
+  String _a1;   //response for TextQuestion
+  String _a2;   //response for a multiple choice (normal) question
+
+  String _a3;   //special case: responses for CheckboxQuestion
+  boolean _a30;   // these booleans represent the user's choices for the
+  boolean _a31;   // checkbox question
+  boolean _a32;
+  boolean _a33;
+
+  String _a4;   //response for a multiple choice (normal) question
+
+  /** A List of SurveyPage objects for use with the processTrain component */
+  private List<SurveyPage> _pages;
+  /**
+   *  Class constructor (no arguments).
+   */
+  public SurveyBean()
+  {
+    init("survey.bundles.california");
+  }
+
+  /**
+   *  Class constructor.
+   *
+   *  @param  bundleName  the path of a bundle file
+   */
+  public SurveyBean(String bundleName)
+  {
+    init(bundleName);
+  }
+
+  /**
+   *  Initializes survey application.
+   *
+   *  @param  bundleName  the path of a bundle file
+   */
+  private void init(String bundleName)
+  {
+    //TODO
+    /*FacesContext context = FacesContext.getCurrentInstance();
+     *   ResourceBundle data = null;
+     *data = ResourceBundle.getBundle(bundleName);
+     */
+
+    // load in the questions
+    loadQuestions();
+
+    // initialize other state for each survey session
+    initSurveyState();
+  }
+
+    /**
+     *  Loads the questions into survey application.
+     */
+  private void loadQuestions()
+  {
+    // notice there are redundant data structures
+    // the QuestionBeans are both stored in instance fields, which are linked
+    // together in an Array List
+
+    // question 0, for surveyPage1
+    ArrayList<String> choices = new ArrayList<String>();
+    choices.add("A. Loading zone for freight or passengers.");
+    choices.add("B. Loading zone for passengers or mail only.");
+    choices.add("C. Loading zone for freight only.");
+    choices.add("D. They ran out of red paint.");
+    _q0 = new MultChoiceQuestionBean("A white painted curb means ", choices, 1);
+    _questions.add(_q0);
+
+    // question 1, for surveyPage2
+    _q1 = new TextQuestionBean("The color of a typical stop sign is ", "RED");
+    _questions.add(_q1);
+
+    // question 2, for surveyPage3
+    ArrayList<String> choices2 = new ArrayList<String>();
+    choices2.add("A. If the shoulder is wide enough to accommodate your vehicle.");
+    choices2.add("B. If the vehicle ahead of you is turning left.");
+    choices2.add("C. Under no circumstances.");
+    choices2.add("D. If you are driving a Hummer.");
+    _q2 = new MultChoiceQuestionBean("You may drive off of the paved roadway to pass another vehicle ", choices2, 2);
+    _questions.add(_q2);
+
+    // question 3, for surveyPage4
+    ArrayList<String> choices3 = new ArrayList<String>();
+    choices3.add("A. In a crosswalk.");
+    choices3.add("B. Within 10 feet of a fire hydrant.");
+    choices3.add("C. Next to a red painted curb.");
+    choices3.add("D. If you are driving a Hummer.");
+    _q3 = new CheckboxQuestionBean("It is illegal to park your vehicle (check all that apply) ", choices3, 14, true, true, true, false);
+    _questions.add(_q3);
+
+    // question 4, for surveyPage5
+    ArrayList<String> choices4 = new ArrayList<String>();
+    choices4.add("A. Stop, then proceed when you think all of the children have exited the bus.");
+    choices4.add("B. Slow to 25 MPH and pass cautiously.");
+    choices4.add("C. Stop as long as the red lights are flashing. ");
+    choices4.add("D. Grab your sack lunch and jump onboard so you're not late for homeroom like yesterday.");
+    _q4 = new MultChoiceQuestionBean("A school bus ahead of you in your lane is stopped with red lights flashing. You should ", choices4, 2);
+    _questions.add(_q4);
+
+    if (debug)
+    {
+      System.out.println("init() printing out the list of questions:\n" + _questions);
+      System.out.println("length of list of questions: " + _questions.size());
+    }
+
+  }  //end loadQuestions()
+
+  /**
+   *  Initializes various survey state.  Should be called for each new sesion
+   *  through the survey.
+   */
+  public void initSurveyState()
+  {
+    /* start with the first(0th) question */
+    _currentIndex = 0;
+
+    /* holders for user responses are initialized to "no selection" */
+    _a0 = null;
+    _a1 = "";   //response for a TextQuestion
+    _a2 = null;
+
+    _a3 = "0"; //response for a CheckboxQuestion
+    _a30 = false;
+    _a31 = false;
+    _a32 = false;
+    _a33 = false;
+
+    _a4 = null;
+
+    /* add initialized responses into array */
+    _userAnswers.add(_a0);
+    _userAnswers.add(_a1);
+    _userAnswers.add(_a2);
+    _userAnswers.add(_a3);
+    _userAnswers.add(_a4);
+
+  } //end initSurveyState()
+
+
+
+  /*** navigation methods ***/
+
+  /**
+   * advances the survey to the next question.
+   *
+   * @return a String object, "next"
+   */
+  public String next()
+  {
+    advanceToNextQuestion();
+    if (debug)
+    {
+      System.out.println("the currentIndex is:" + _currentIndex);
+      System.out.println("next() is finished");
+    }
+
+    return "next";
+  }
+  /**
+   * moves the survey to the previous question.
+   *
+   * @return a String object, "back"
+   */
+  public String back()
+  {
+    goToPreviousQuestion();
+    if (debug)
+    {
+      System.out.println("the currentIndex is:" + _currentIndex);
+      System.out.println("next() is finished");
+    }
+    return "back";
+  }
+
+  /**
+   * called when the first run through the survey is completed.
+   *
+   * @return a String object, "finish"
+   */
+ public String finish()
+  {
+    return "finish";
+  }
+
+  /**
+   * called to advance to the results page.
+   *
+   * @return a String object, "check"
+   */
+  public String check()
+  {
+    return "check";
+  }
+
+  /**
+   * called to go back to beginning of survey and clears all previous responses.
+   *
+   * @return a String object, "start"
+   */
+  public String start()
+  {
+    initSurveyState();
+    return "start";
+  }
+
+
+  /*** Accessors ***/
+
+  /**
+   * advances the survey to the next question.
+   *
+   * @return  a String object representing the number of questions in the survey
+   */
+  public String getNumQuestions()
+  {
+    return ( String.valueOf(_questions.size()) );
+  }
+
+  /**
+   * determines whether we have reached the end of the survey
+   *
+   * @return  a boolean that is true if we have reached the end of the survey
+   */
+  public boolean getDone()
+  {
+    // when we've reached the last question in the list
+    return ( _currentIndex == _questions.size()-1 );
+  }
+
+  /**
+   * determines the number of the current question in the survey.
+   *
+   * @return  a String that represents the number of the current question
+   */
+  public String getCurrentQuestionNumber()
+  {
+    // the question number is index+1 since the index starts at 0
+    int i = _currentIndex + 1 ;
+    return String.valueOf(i);
+  }
+
+  /*** Utils ***/
+
+
+  /**
+   * increments question index to next question.
+   */
+  public void advanceToNextQuestion()
+  {
+    _currentIndex++;
+  }
+
+  /**
+   * decrements question index to previous question.
+   */
+  public void goToPreviousQuestion()
+  {
+    _currentIndex--;
+  }
+
+  /**
+   * a hack to return the String "error" inside a binding using EL
+   *
+   * @return  the literal String, "error"
+   */
+  public String getError()
+  {
+    return "error";
+  }
+
+  /**
+   * a hack to return the String "none" inside a binding using EL
+   *
+   * @return  the literal String, "none"
+   */
+  public String getNone()
+    // a hack to return a String inside a binding using EL
+  {
+    return "none";
+  }
+
+  /**
+   * a hack to return the empty String "" inside a binding using EL
+   *
+   * @return  the empty String, ""
+   */
+  public String getEmptyString()
+    // a hack to return a String inside a binding using EL
+  {
+    return "";
+  }
+
+ /**
+   * a hack to return the String "correct" inside a binding using EL
+   *
+   * @return  the literal String, "correct"
+   */
+  public String getCorrect()
+    // a hack to return a String inside a binding using EL
+  {
+    return "correct";
+  }
+
+
+  /**
+   * a hack to return the String "incorrect" inside a binding using EL
+   *
+   * @return  the literal String, "incorrect"
+   */
+  public String getIncorrect()
+    // a hack to return a String inside a binding using EL
+  {
+    return "incorrect";
+  }
+
+
+  /**
+   * stores whether a checkbox is checked.  This app uses a simple bit mapping
+   * to represent the "checked" state of the checkboxes.  For example, assume the
+   * number of checkboxes is 4. If all four checkboxes were checked, then
+   * the representation is "1111", which is equivalent to the number 15 in
+   * base 10.  Likewise, if only the first and third checkboxes are selected,
+   * then the representation is "1010", which is the number 10 in base 10.
+   * This method turns the bits on/off according to whether the "index"-th
+   * checkbox is "checked".
+   *
+   * @param checked             whether this checkbox is checked
+   * @param index               the index of the checkbox
+   * @param storageDestination  the String of the integer representation of the selection state
+   *
+   * @return  a String that represents the current selections (an integer)
+   */
+  private String storeCheckSelection (boolean checked, int index,
+                                      String storageDestination)
+  {
+    // extract an integer from the string
+    int storageInt = Integer.parseInt(storageDestination);
+    if (checked)
+    {
+      // if checked, then turn on index-th bit
+      storageInt = storageInt | 1<<(NUMBER_OF_ANSWER_CHOICES-index-1);
+    }
+    else
+    {
+      // if not checked, then turn off index-th bit
+      storageInt = storageInt & ~(1<<(NUMBER_OF_ANSWER_CHOICES-index-1));
+    }
+
+   if (debug)
+   {
+    System.out.println("checked is: " + checked + ", index is: " + index + ", storageInt is:" + storageInt);
+   }
+
+   // store the integer as a string
+   return String.valueOf(storageInt);
+
+  } // end storeCheckSelection
+
+
+ /*** IDE generated accessors ***/
+
+  public MultChoiceQuestionBean getQ0()
+  {
+    return _q0;
+  }
+
+  public TextQuestionBean getQ1()
+  {
+    return _q1;
+  }
+
+  public MultChoiceQuestionBean getQ2()
+  {
+    return _q2;
+  }
+
+  public CheckboxQuestionBean getQ3()
+  {
+    return _q3;
+  }
+
+  public MultChoiceQuestionBean getQ4()
+  {
+    return _q4;
+  }
+
+
+  public void setA0(String a0)
+  {
+    _a0 = a0;
+  }
+
+
+  public String getA0()
+  {
+    return _a0;
+  }
+
+
+  public void setA1(String a1)
+  {
+  // special set method to trim and convert response from text input
+    _a1 = a1.trim().toUpperCase();
+  }
+
+
+  public String getA1()
+  {
+    return _a1;
+  }
+
+
+  public void setA2(String a2)
+  {
+    _a2 = a2;
+  }
+
+
+  public String getA2()
+  {
+    return _a2;
+  }
+
+
+  public void setA3(String a3)
+  {
+    _a3 = a3;
+  }
+
+
+  public String getA3()
+  {
+    return _a3;
+  }
+
+
+  public void setA4(String a4)
+  {
+    _a4 = a4;
+  }
+
+
+  public String getA4()
+  {
+    return _a4;
+  }
+
+
+  public void setA30(boolean a30)
+  {
+    _a30 = a30;
+    _a3 = storeCheckSelection(a30, 0, _a3);
+
+  }
+
+
+  public boolean getA30()
+  {
+    return _a30;
+  }
+
+
+  public void setA31(boolean a31)
+  {
+    _a31 = a31;
+    _a3 = storeCheckSelection(a31, 1, _a3);
+  }
+
+
+  public boolean getA31()
+  {
+    return _a31;
+  }
+
+
+  public void setA32(boolean a32)
+  {
+    _a32 = a32;
+    _a3 = storeCheckSelection(a32, 2, _a3);
+  }
+
+
+  public boolean getA32()
+  {
+    return _a32;
+  }
+
+
+  public void setA33(boolean a33)
+  {
+    _a33 = a33;
+    _a3 = storeCheckSelection(a33, 3, _a3);
+  }
+
+
+  public boolean getA33()
+  {
+    return _a33;
+  }
+
+  public List<SurveyPage> getPages()
+  {
+    if (_pages == null)
+    {
+      _pages = new ArrayList<SurveyPage>();
+      _pages.add(new SurveyPage("/surveydemo/surveyPage1.jspx", "Step1"));
+      _pages.add(new SurveyPage("/surveydemo/surveyPage2.jspx", "Step2"));
+      _pages.add(new SurveyPage("/surveydemo/surveyPage3.jspx", "Step3"));
+      _pages.add(new SurveyPage("/surveydemo/surveyPage4.jspx", "Step4"));
+      _pages.add(new SurveyPage("/surveydemo/surveyPage5.jspx", "Step5"));
+    }
+    return _pages;
+  }
+
+} //end SurveyBean class

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java Wed Jun 13 10:52:53 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.survey;
+
+public class SurveyPage implements java.io.Serializable
+{
+  public SurveyPage()
+  {
+  }
+  
+  public SurveyPage(String viewId, String label)
+  {
+    setViewId(viewId);
+    setLabel(label);
+    setDisabled(false);
+  }
+
+  public void setViewId(String viewId)
+  {
+    _viewId = viewId;
+  }
+
+
+  public String getViewId()
+  {
+    return _viewId;
+  }
+
+  public void setOutcome(String outcome)
+  {
+    _outcome = outcome;
+  }
+
+
+  public String getOutcome()
+  {
+    return _outcome;
+  }
+
+  public void setLabel(String label)
+  {
+    _label = label;
+  }
+
+
+  public String getLabel()
+  {
+    return _label;
+  } 
+
+
+  public void setDisabled(boolean disabled)
+  {
+    _disabled = disabled;
+  }
+
+
+  public boolean isDisabled()
+  {
+    return _disabled;
+  } 
+  
+  private String _viewId;
+  private String _outcome;
+  private String _label;
+  private boolean _disabled;
+
+
+}

Added: myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java?view=auto&rev=546977
==============================================================================
--- myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java (added)
+++ myfaces/trinidad/branches/matzew-core-101-release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java Wed Jun 13 10:52:53 2007
@@ -0,0 +1,82 @@
+/*
+ *  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;
+
+/***
+ *  class TextQuestionBean
+ *
+ * This bean represents a single question with a text field as its answer form.
+ * It has fields for the question prompt and the correct answer.
+ *
+ * ***/
+
+
+public class TextQuestionBean implements QuestionBean, Serializable
+{
+  /** The question as a String object. */
+  private String    _prompt;
+
+  /** The correct answer. */
+  private String    _correctAnswer;
+
+ /**
+  *  Class constructor (no arguments).
+  */
+  public TextQuestionBean()
+  {
+    _prompt = "";
+    _correctAnswer = "";
+  }
+
+ /**
+  *  Class constructor.
+  */
+  public TextQuestionBean(String prompt, String correctAnswer)
+  {
+    _prompt = prompt;
+    _correctAnswer = correctAnswer;
+  }
+
+
+  /*** JDev generated accessors ***/
+
+  public void setPrompt(String prompt)
+  {
+    _prompt = prompt;
+  }
+
+  public String getPrompt()
+  {
+    return _prompt;
+  }
+
+  public String getCorrectAnswer()
+  {
+    return _correctAnswer;
+  }
+
+  public String getCorrectAnswerMessage()
+  {
+    return "The correct answer is: " + _correctAnswer;
+  }
+
+
+}



Mime
View raw message