You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2007/06/28 09:19:20 UTC
svn commit: r551482 [4/19] - in
/myfaces/trinidad/branches/matzew121core_release/trinidad-examples: ./
trinidad-demo/ trinidad-demo/src/ trinidad-demo/src/conf/
trinidad-demo/src/main/ trinidad-demo/src/main/java/
trinidad-demo/src/main/java/org/ trini...
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/PasswordValidator.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Password validator - this is an incredibly simple
+ * password validator that makes sure there's at least one number
+ * in the password.</p>
+ *
+ */
+public class PasswordValidator implements Validator, ClientValidator
+{
+ public static final String VALIDATOR_ID = "org.apache.myfaces.trinidaddemo.PasswordValidator";
+
+ public void validate(
+ FacesContext context,
+ UIComponent component,
+ Object value) throws ValidatorException
+ {
+
+ String password = "";
+
+ if ( value != null)
+ password = value.toString().trim();
+
+ for (int j = 0;j < password.length();j++)
+ {
+ if (Character.isDigit(password.charAt(j)))
+ {
+ return;
+ }
+ }
+
+ // Using the LabeledFacesMessage allows the <tr:messages> component to
+ // properly prepend the label as a link.
+ LabeledFacesMessage lfm =
+ new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Validation Error",
+ "The password must contain at least one number");
+ lfm.setLabel(_getLabel(component));
+ throw new ValidatorException(lfm);
+ }
+
+
+ public String getClientValidation(
+ FacesContext context,
+ UIComponent component)
+ {
+ return (_VALIDATOR_INSTANCE_STRING);
+ }
+
+
+ public Collection<String> getClientImportNames()
+ {
+ return null;
+ }
+
+ public String getClientLibrarySource(
+ FacesContext context)
+ {
+ return context.getExternalContext().getRequestContextPath() +
+ "/jsLibs/passwordValidator.js";
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public String getClientScript(
+ FacesContext context,
+ UIComponent component)
+ {
+ return null;
+ }
+
+ private static Object _getLabel(UIComponent component)
+ {
+ Object o = null;
+ if (component != null)
+ {
+ o = component.getAttributes().get("label");
+ if (o == null)
+ o = component.getValueBinding("label");
+ }
+ return o;
+ }
+
+ // in a real app the messages would be translated
+ // The fourth field marker gets the field label
+ private static final String _VALIDATOR_INSTANCE_STRING =
+ "new PasswordValidator({"
+ + "NS:'The password is invalid.',"
+ + "ND:'The password value must contain at least one number.'})";
+
+
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/SSNConverter.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import java.util.Collection;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.apache.myfaces.trinidad.convert.ClientConverter;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
+
+/**
+ * <p>Social Security number converter.</p>
+ *
+ */
+public class SSNConverter implements Converter, ClientConverter
+{
+ public static final String CONVERTER_ID = "org.apache.myfaces.trinidaddemo.SSN";
+
+ public Object getAsObject(
+ FacesContext context,
+ UIComponent component,
+ String value)
+ {
+ // In a real app all the error messages would be translated
+ if ( value == null || value.trim().length() == 0)
+ return null;
+
+ String tValue = value.trim();
+
+ int length = tValue.length();
+ if ( length < 9 )
+ {
+ throw new ConverterException(_getMessage(component, _SHORT_ERROR_TEXT));
+ }
+
+ if ( length > 11 )
+ {
+ throw new ConverterException(_getMessage(component, _LONG_ERROR_TEXT));
+ }
+
+ if (length == 9)
+ {
+ try
+ {
+ return Integer.valueOf(tValue);
+ }
+ catch(NumberFormatException nfe)
+ {
+ throw new ConverterException(_getMessage(component,
+ _INVALID_ERROR_TEXT));
+ }
+ }
+
+ if ( length == 11 &&
+ tValue.charAt(3) == '-' &&
+ tValue.charAt(6) == '-')
+ {
+ String v = tValue.substring(0,3) +
+ tValue.substring(4,6) +
+ tValue.substring(7);
+
+ try
+ {
+ return Integer.valueOf(v);
+ }
+ catch(NumberFormatException nfe)
+ {
+ throw new ConverterException(_getMessage(component,
+ _INVALID_ERROR_TEXT));
+ }
+
+ }
+ throw new ConverterException(_getMessage(component, _INVALID_ERROR_TEXT));
+ }
+
+ public String getAsString(
+ FacesContext context,
+ UIComponent component,
+ Object value)
+ {
+ if ( value == null || !(value instanceof Integer))
+ return null;
+
+ Integer integerValue = (Integer)value;
+
+ String valueString = integerValue.toString();
+
+ String ssn = valueString.substring(0,3) + '-' +
+ valueString.substring(3,5) + '-' +
+ valueString.substring(5,9);
+ return ssn;
+ }
+
+
+ public Collection<String> getClientImportNames()
+ {
+ return null;
+ }
+
+ public String getClientLibrarySource(
+ FacesContext context)
+ {
+ return context.getExternalContext().getRequestContextPath() +
+ "/jsLibs/ssnConverter.js";
+ }
+
+ public String getClientConversion(
+ FacesContext context,
+ UIComponent component)
+ {
+
+ // in a real app the messages would be translated
+ return ("new SSNConverter({"
+ + "SUM:'Invalid social security number.',"
+ + "S:'Value \"{1}\" is too short.',"
+ + "L:'Value \"{1}\" is too long.',"
+ + "N:'Value \"{1}\" is not a valid social security number.'})"
+ );
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getClientScript(
+ FacesContext context,
+ UIComponent component)
+ {
+ return null;
+ }
+
+ private LabeledFacesMessage _getMessage(
+ UIComponent component,
+ String text)
+ {
+ // Using the LabeledFacesMessage allows the <tr:messages> component to
+ // properly prepend the label as a link.
+ LabeledFacesMessage lfm =
+ new LabeledFacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Conversion Error", text);
+ if (component != null)
+ {
+ Object label = null;
+ label = component.getAttributes().get("label");
+ if (label == null)
+ label = component.getValueBinding("label");
+ if (label != null)
+ lfm.setLabel(label);
+ }
+ return lfm;
+ }
+
+ private static final String _SHORT_ERROR_TEXT
+ = "The value is too short to be a social security number";
+
+ private static final String _LONG_ERROR_TEXT
+ = "The value is too long to be a social security number";
+
+ private static final String _INVALID_ERROR_TEXT
+ = "The value is not a valid social security number";
+
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/convertValidate/ValidatePasswordTag.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.convertValidate;
+
+import javax.faces.validator.Validator;
+import javax.faces.webapp.ValidatorTag;
+import javax.servlet.jsp.JspException;
+
+
+public class ValidatePasswordTag extends ValidatorTag
+{
+
+ public ValidatePasswordTag()
+ {
+ }
+
+ @Override
+ public int doStartTag() throws JspException
+ {
+ super.setValidatorId(PasswordValidator.VALIDATOR_ID);
+ return super.doStartTag();
+ }
+
+ /**
+ *
+ */
+ @Override
+ protected Validator createValidator() throws JspException
+ {
+ PasswordValidator validator =
+ (PasswordValidator)super.createValidator();
+ return validator;
+ }
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/ChooseIntegerBean.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.dialog;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.event.ReturnEvent;
+
+public class ChooseIntegerBean
+{
+ public Integer getValue1()
+ {
+ return _value1;
+ }
+
+ public void setValue1(Integer value1)
+ {
+ _value1 = value1;
+ }
+
+ public Integer getValue2()
+ {
+ return _value2;
+ }
+
+ public void setValue2(Integer value2)
+ {
+ _value2 = value2;
+ }
+
+ public void sayHello(ReturnEvent event)
+ {
+ FacesMessage message = new FacesMessage("Hello!");
+ FacesContext.getCurrentInstance().addMessage(null, message);
+ }
+
+ private Integer _value1;
+ private Integer _value2;
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/LaunchDialogBean.java Thu Jun 28 00:19:04 2007
@@ -0,0 +1,152 @@
+/*
+ * 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.UIXCommand;
+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)
+ {
+ String dialogViewId;
+ if (event.getReturnValue() != null)
+ {
+ getInput().setSubmittedValue(null);
+ getInput().setValue(event.getReturnValue());
+
+ RequestContext afContext = RequestContext.getCurrentInstance();
+ afContext.addPartialTarget(getInput());
+ dialogViewId = "/demos/successDialog.jspx";
+ }
+ else
+ {
+ dialogViewId = "/demos/cancelledDialog.jspx";
+ }
+
+
+ // Launch a new, success dialog with a different width and height;
+ // this shows how to do so by queueing a LaunchEvent.
+ // (Here, we queue it to a dummy UIXCommand just so we don't
+ // get in a fun infinite loop of ReturnEvents!)
+ FacesContext context = FacesContext.getCurrentInstance();
+ UIViewRoot root = context.getApplication().getViewHandler().createView(
+ context, dialogViewId);
+ LaunchEvent launchEvent = new LaunchEvent(getDummyCommand(), root);
+ launchEvent.getWindowProperties().put("width", "200");
+ launchEvent.getWindowProperties().put("height", "100");
+ addParameter(launchEvent);
+ 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());
+ }
+ }
+
+
+ public UIXCommand getDummyCommand()
+ {
+ return _dummyCommand;
+ }
+
+ public void setDummyCommand(UIXCommand dummyCommand)
+ {
+ _dummyCommand = dummyCommand;
+ }
+
+ private UIXInput _input;
+ private UIXInput _tableInput;
+ private UIXCommand _dummyCommand;
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/dialog/PeriodicDialogBean.java Thu Jun 28 00:19:04 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();
+ Object rowKey = 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;
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/AccountData.java Thu Jun 28 00:19:04 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());
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/EmailDisplayConverter.java Thu Jun 28 00:19:04 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();
+ }
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/FolderData.java Thu Jun 28 00:19:04 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());
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageData.java Thu Jun 28 00:19:04 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;
+}
+
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageDataModel.java Thu Jun 28 00:19:04 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());
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessageUtils.java Thu Jun 28 00:19:04 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());
+}
Added: myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java?view=auto&rev=551482
==============================================================================
--- myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java (added)
+++ myfaces/trinidad/branches/matzew121core_release/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/MessagesBackingBean.java Thu Jun 28 00:19:04 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());
+}