You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2007/03/29 07:51:08 UTC

svn commit: r523607 [5/14] - in /incubator/adffaces/trunk/trinidad: trinidad-assembly/ trinidad-assembly/src/ trinidad-assembly/src/main/ trinidad-assembly/src/main/assembly/ trinidad-assembly/src/main/resources/ trinidad-examples/ trinidad-examples/bl...

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import java.util.Date;
+import java.util.Map;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.component.UIXInput;
+import org.apache.myfaces.trinidad.context.RequestContext;
+import org.apache.myfaces.trinidad.event.ReturnEvent;
+import org.apache.myfaces.trinidad.event.LaunchEvent;
+import org.apache.myfaces.trinidad.event.PollEvent;
+
+public class LaunchDialogBean
+{
+  public UIXInput getInput()
+  {
+    return _input;
+  }
+
+  public void setInput(UIXInput input)
+  {
+    _input = input;
+  }
+
+  public void addParameter(LaunchEvent event)
+  {
+    // Pass an integer into the dialog.  Some automatic
+    // coercion would really help here (coming in JSF 1.2?)
+    Object value = getInput().getValue();
+    if (value != null)
+    {
+      try
+      {
+        Integer i = Integer.valueOf(value.toString());
+        event.getDialogParameters().put("value", i);
+      }
+      catch (Exception e)
+      {
+      }
+    }
+  }
+
+  public String doLaunch()
+  {
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    Map<String, Object> process = afContext.getPageFlowScope();
+    process.put("lastLaunch", new Date());
+
+    return "dialog:chooseInteger";
+  }
+
+  public void returned(ReturnEvent event)
+  {
+    if (event.getReturnValue() != null)
+    {
+      getInput().setSubmittedValue(null);
+      getInput().setValue(event.getReturnValue());
+
+      RequestContext afContext = RequestContext.getCurrentInstance();
+      afContext.addPartialTarget(getInput());
+
+      FacesContext context = FacesContext.getCurrentInstance();
+      UIViewRoot root = context.getApplication().getViewHandler().createView(
+                           context, "/demos/successDialog.jspx");
+      // Launch a new, success dialog with a different width and height;
+      // this shows how to do so by queueing a LaunchEvent.
+      LaunchEvent launchEvent = new LaunchEvent(event.getComponent(), root);
+      launchEvent.getWindowProperties().put("width", "200");
+      launchEvent.getWindowProperties().put("height", "100");
+      launchEvent.queue();
+    }
+  }
+
+
+  public void poll(PollEvent event)
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    UIViewRoot root = context.getApplication().getViewHandler().createView(
+                           context, "/demos/simpleDialog.jspx");
+
+    // Launch a dialog with a call to RequestContext
+    RequestContext afContext = RequestContext.getCurrentInstance();
+    afContext.launchDialog(root, null, event.getComponent(), true, null);
+    // Stop the poll from running
+    event.getComponent().setRendered(false);
+  }
+
+  public UIXInput getTableInput()
+  {
+    return _tableInput;
+  }
+
+  public void setTableInput(UIXInput tableInput)
+  {
+    _tableInput = tableInput;
+  }
+
+  public void tableReturned(ReturnEvent event)
+  {
+    if (event.getReturnValue() != null)
+    {
+      getTableInput().setValue(event.getReturnValue());
+      RequestContext afContext = RequestContext.getCurrentInstance();
+      afContext.addPartialTarget(getTableInput());
+    }
+  }
+
+  private UIXInput _input;
+  private UIXInput _tableInput;
+}

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

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

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,68 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import java.util.Iterator;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.trinidad.component.UIXTable;
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+public class PeriodicDialogBean
+{
+  public UIXTable getTable()
+  {
+    return _table;
+  }
+
+  public void setTable(UIXTable table)
+  {
+    _table = table;
+  }
+
+  public String cancel()
+  {
+    RequestContext.getCurrentInstance().returnFromDialog(null, null);
+    return null;
+  }
+
+  @SuppressWarnings("unchecked")
+  public String select()
+  {
+    FacesContext context = FacesContext.getCurrentInstance();
+    // The tableSelectOne is marked as required; so there'd better
+    // be a selected row - an exception will result here if there
+    // isn't.  Is there some better code?
+    Iterator<Object> iterator = _table.getSelectedRowKeys().iterator();
+    String rowKey = (String) iterator.next();
+    Object oldRowKey = _table.getRowKey();
+    _table.setRowKey(rowKey);
+    ValueBinding binding = context.getApplication().
+      createValueBinding("#{row.symbol}");
+    Object value = binding.getValue(context);
+    RequestContext.getCurrentInstance().returnFromDialog(value, null);
+    _table.setRowKey(oldRowKey);
+
+    return null;
+  }
+
+  private UIXTable _table;
+}

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

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

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

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

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

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,54 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import javax.faces.component.UIComponent;
+import javax.faces.convert.Converter;
+import javax.faces.context.FacesContext;
+
+/**
+ * Converter that displays just the name, or the full
+ * e-mail address if the name is not available.
+ */
+public class EmailDisplayConverter implements Converter
+{
+  public EmailDisplayConverter()
+  {
+  }
+
+  public String getAsString(FacesContext context, UIComponent component,
+                            Object value)
+  {
+    if (value == null)
+      return null;
+
+    String val = value.toString();
+    int lessThanIndex = val.indexOf('<');
+    if (lessThanIndex < 0)
+      return val;
+
+    return val.substring(0, lessThanIndex).trim();
+  }
+
+  public Object getAsObject(FacesContext context, UIComponent component,
+                            String value)
+  {
+    throw new UnsupportedOperationException();
+  }
+}

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

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

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,247 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.model.DataModel;
+
+import javax.mail.Folder;
+import javax.mail.FetchProfile;
+import javax.mail.MessagingException;
+
+/**
+ * Reflects the folder information provided by javaMail folder
+ * @version 1.0
+ */
+public class FolderData
+{
+
+  /**
+   * @param data the user who owns this folder
+   * @param folder the folder being reflected
+   */
+  public FolderData(AccountData data, Folder folder) throws MessagingException
+  {
+    _folder = folder;
+    _accountData = data;
+    _holdsMessages  = (_folder.getType() & Folder.HOLDS_MESSAGES) > 0;
+  }
+
+
+  public void flush()
+  {
+    _messageListModel = null;
+  }
+
+  
+  /**
+   * Returns true if the folder can hold messages.
+   */
+  public boolean isHoldsMessages()
+  {
+    return _holdsMessages;
+  }
+
+  /**
+   * @return the number of messages in this folder
+   */
+  public int getMessageCount() throws MessagingException
+  {
+    // remember, we can only get messages if the type of this folder is
+    // Folder.HOLDS_MESSAGES
+    if (_holdsMessages)
+      return _folder.getMessageCount();
+
+    return 0;
+  }
+
+  /**
+   * @return the number of unread messages in this folder
+   */
+  public int getUnreadMessageCount() throws MessagingException
+  {
+    // remember, we can only get messages if the type of this folder is
+    // Folder.HOLDS_MESSAGES
+    if (_holdsMessages)
+      return _folder.getUnreadMessageCount();
+
+    return 0;
+  }
+
+  /**
+   * @return the index into the list of messages that was last
+   *  used by the messages table.  Stored here to keep it
+   *  scoped to the folder, instead of the session.
+   */
+  public int getStartIndex()
+  {
+    return _startIndex;
+  }
+  
+  /**
+   * Store the index into the list of messages.
+   */
+  public void setStartIndex(int startIndex)
+  {
+    _startIndex = startIndex;
+  }
+
+  /**
+   * gets the name of this folder
+   */
+  public String getName()
+  {
+    return _folder.getName();
+  }
+
+  /**
+   * gets the full name of this folder. This reflects the hierarchy of this
+   * folder.
+   */
+  public String getFullName()
+  {
+    return _folder.getFullName();
+  }
+
+  /**
+   * @return true if this folder is currently selected
+   */
+  /* =-=AEW Not used
+  public boolean isSelected()
+  {
+    return _folder.getFullName().equals
+      (_accountData.getCurrentFolder()._folder.getFullName());
+  }
+  */
+
+  /**
+   * gets this folder's subfolders
+   * @todo Why does this code return "null" instead of the empty list???
+   */
+  @SuppressWarnings("unchecked")
+  public synchronized List<Object> getSubFolders() throws MessagingException
+  {
+    if (_subFolders == Collections.EMPTY_LIST)
+    {
+      return null;
+    }
+    else if (_subFolders == null)
+    {
+      FolderData[] folders = toFolderData(_accountData, _folder.list());
+      if (folders == null)
+      {
+        _subFolders = Collections.EMPTY_LIST;
+        return null;
+      }
+      else
+      {
+        _subFolders = Arrays.asList((Object[]) folders);
+      }
+    }
+
+    return _subFolders;
+  }
+
+  /**
+   * Get the model for the messages in this folder.
+   */
+  public Object getMessageListModel()
+  {
+    if (_holdsMessages)
+    {
+      if (_messageListModel == null)
+      {
+        FetchProfile fetchProfile = new FetchProfile();
+        fetchProfile.add(FetchProfile.Item.ENVELOPE);
+        fetchProfile.add(FetchProfile.Item.FLAGS);
+        _messageListModel = new MessageDataModel(_folder,
+                                                 fetchProfile,
+                                                 _MESSAGE_LOAD_BLOCK_SIZE);
+      }
+
+      return _messageListModel;
+    }
+    else
+    {
+      return null;
+    }
+  }
+
+  /**
+   * converts {@link Folder}s to {@link FolderData}s.
+   */
+  public static FolderData[] toFolderData(AccountData data, Folder[] folders)
+    throws MessagingException
+  {
+    int sz = folders.length;
+    if (sz > 0)
+    {
+      FolderData[] subs = new FolderData[sz];
+      for(int i=0; i<sz; i++)
+      {
+        Folder f = folders[i];
+        subs[i] = new FolderData(data, f);
+      }
+
+      return subs;
+    }
+
+    return null;
+  }
+
+  /**
+   * Get the underlying Folder object.
+   */
+  public Folder getFolder()
+  {
+    return _folder;
+  }
+
+  /**
+   * Action for viewing the messages in this folder.
+   */
+  public String viewMessages()
+  {
+    // update the currentFolder on the account to point to this folder
+    _accountData.setCurrentFolder(this);
+	
+    _LOG.log(Level.FINE, 
+             "Showing messages for folder named {0} ", getName());
+  
+    return "messages";
+  }
+
+  private List<Object>      _subFolders = null;
+  private DataModel         _messageListModel = null;
+  private final Folder      _folder;
+  private final AccountData _accountData;
+  private final boolean     _holdsMessages;
+  private       int         _startIndex;
+  // Load 100 messages at a time (obviously, should be tuneable)
+  private static final int _MESSAGE_LOAD_BLOCK_SIZE = 100;
+
+  static private final Logger _LOG =
+    Logger.getLogger(FolderData.class.getName());
+}

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

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

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

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java Thu Mar 29 00:50:53 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/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java Thu Mar 29 00:50:53 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/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java Thu Mar 29 00:50:53 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/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java Thu Mar 29 00:50: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());
+
+}

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/NewMessageBackingBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java Thu Mar 29 00:50: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"));
+  }
+}

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/PreferencesData.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java Thu Mar 29 00:50: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;
+    }
+  }
+}