### Eclipse Workspace Patch 1.0 #P OpenCms Index: test/org/opencms/test/AllTests.java =================================================================== RCS file: /usr/local/cvs/opencms/test/org/opencms/test/AllTests.java,v retrieving revision 1.35 diff -u -r1.35 AllTests.java --- test/org/opencms/test/AllTests.java 11 Jun 2008 09:00:26 -0000 1.35 +++ test/org/opencms/test/AllTests.java 10 Sep 2008 12:53:36 -0000 @@ -103,6 +103,7 @@ suite.addTest(org.opencms.jsp.decorator.AllTests.suite()); suite.addTest(org.opencms.jsp.util.AllTests.suite()); suite.addTest(org.opencms.loader.AllTests.suite()); + suite.addTest(org.opencms.mail.AllTests.suite()); suite.addTest(org.opencms.main.AllTests.suite()); suite.addTest(org.opencms.module.AllTests.suite()); suite.addTest(org.opencms.monitor.AllTests.suite()); Index: src/org/opencms/mail/CmsSimpleMail.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/CmsSimpleMail.java,v retrieving revision 1.12 diff -u -r1.12 CmsSimpleMail.java --- src/org/opencms/mail/CmsSimpleMail.java 27 Feb 2008 12:05:41 -0000 1.12 +++ src/org/opencms/mail/CmsSimpleMail.java 10 Sep 2008 12:53:35 -0000 @@ -31,107 +31,131 @@ package org.opencms.mail; -import org.opencms.main.CmsLog; -import org.opencms.main.CmsRuntimeException; -import org.opencms.main.OpenCms; -import org.opencms.util.CmsStringUtil; - import javax.mail.AuthenticationFailedException; import javax.mail.MessagingException; import javax.mail.SendFailedException; import org.apache.commons.logging.Log; +import org.apache.commons.mail.EmailException; import org.apache.commons.mail.SimpleEmail; +import org.opencms.main.CmsLog; +import org.opencms.main.CmsRuntimeException; +import org.opencms.main.OpenCms; +import org.opencms.util.CmsStringUtil; /** * This class is used to send simple text internet email messages without - * attachments.
- * - * It uses the Apache Commons Email API and extends the provided classes - * to conveniently generate emails using the OpenCms configuration.
- * - * @author Andreas Zahner + * attachments. + *
* - * @version $Revision: 1.12 $ + * It uses the Apache Commons Email API and extends the provided classes to + * conveniently generate emails using the OpenCms configuration. + *
* - * @since 6.0.0 + * @author Andreas Zahner + * + * @version $Revision: 1.12 $ + * + * @since 6.0.0 */ public class CmsSimpleMail extends SimpleEmail { - /** The log object for this class. */ - private static final Log LOG = CmsLog.getLog(CmsSimpleMail.class); - - /** - * Default constructor of a CmsSimpleMail.
- * - * The mail host name and the mail from address are set to the OpenCms - * default values of the configuration.
- * - */ - public CmsSimpleMail() { - - // call super constructor - super(); - // set the host to the default mail host - CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost(); - setHostName(host.getHostname()); - - // check if username and password are provided - String userName = host.getUsername(); - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(userName)) { - // authentication needed, set user name and password - setAuthentication(userName, host.getPassword()); - } - try { - // set default mail from address - setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault()); - } catch (MessagingException e) { - // default email address is not valid, log error - LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e); - } - } - - /** - * Overrides to add a layer for localization of exception / logging.
- *
- * Please note that in case of a {@link SendFailedException}
- * the cause of this message will contain a {@link CmsRuntimeException}
- * as cause. The information of the SendFaileException
should be used outside
- * to remove recipients (e.g. from the beans that store them) in order to avoid duplicate
- * sending of emails. The internal cause then just should be rethrown to allow localized
- * output about the cause.
- * - * - * @see org.apache.commons.mail.Email#send() - * - * @throws MessagingException if something goes wrong - * @throws SendFailedException if sending failed, please look at the possibility to use this type to remove - * recepients from a mass mail where sending suceeded. - */ - public void send() throws MessagingException, SendFailedException { - - try { - super.send(); - } catch (SendFailedException sf) { - // The specialized exception types (authentication, wrong host) are wrapped in this type: - MessagingException me = (MessagingException)sf.getNextException(); - CmsMailHost host = OpenCms.getSystemInfo().getMailSettings().getDefaultMailHost(); - if (me instanceof AuthenticationFailedException) { - // wrong user credentials in opencms-system.xml - CmsRuntimeException rte = new CmsRuntimeException(Messages.get().container( - Messages.ERR_SEND_EMAIL_AUTHENTICATE_2, - host.getUsername(), - host.getHostname())); - sf.initCause(rte); - throw sf; - } - // wrong hostname in opencms-system.xml - CmsRuntimeException rte = new CmsRuntimeException(Messages.get().container( - Messages.ERR_SEND_EMAIL_HOSTNAME_1, - host.getHostname()), me); - sf.initCause(rte); - throw sf; + /** The log object for this class. */ + private static final Log LOG = CmsLog.getLog(CmsSimpleMail.class); - } - } + /** + * Default constructor of a CmsSimpleMail. + *
+ * + * The mail host name and the mail from address are set to the OpenCms + * default values of the configuration. + *
+ * + */ + public CmsSimpleMail() { + + // call super constructor + super(); + // set the host to the default mail host + CmsMailHost host = OpenCms.getSystemInfo().getMailSettings() + .getDefaultMailHost(); + setHostName(host.getHostname()); + + // check if username and password are provided + String userName = host.getUsername(); + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(userName)) { + // authentication needed, set user name and password + setAuthentication(userName, host.getPassword()); + } + try { + // set default mail from address + setFrom(OpenCms.getSystemInfo().getMailSettings() + .getMailFromDefault()); + } catch (EmailException e) { + // default email address is not valid, log error + LOG.error(Messages.get().getBundle().key( + Messages.LOG_INVALID_SENDER_ADDRESS_0), e); + } + } + + /** + * Overrides to add a layer for localization of exception / logging. + *
+ *
+ * Please note that in case of a {@link SendFailedException}
+ * the cause of this message will contain a
+ * {@link CmsRuntimeException}
as cause. The information of
+ * the SendFaileException
should be used outside to remove
+ * recipients (e.g. from the beans that store them) in order to avoid
+ * duplicate sending of emails. The internal cause then just should be
+ * rethrown to allow localized output about the cause.
+ *
+ * + * + * @see org.apache.commons.mail.Email#send() + * + * @throws MessagingException + * if something goes wrong + * @throws SendFailedException + * if sending failed, please look at the possibility to use this + * type to remove recepients from a mass mail where sending + * suceeded. + */ + public String send() throws EmailException { + String messageID = null; + try { + super.send(); + messageID = this.getMimeMessage().getMessageID(); + } catch (EmailException e) { + // check if original Exception is of type SendFailedException which + // should have been thrown by javax.mail.Transport.send() + if (e.getCause() instanceof SendFailedException) { + SendFailedException sfe = (SendFailedException)e.getCause(); + // The specialized exception types (authentication, wrong host) are + // wrapped in this type: + MessagingException me = (MessagingException) sfe + .getNextException(); + CmsMailHost host = OpenCms.getSystemInfo().getMailSettings() + .getDefaultMailHost(); + if (me instanceof AuthenticationFailedException) { + // wrong user credentials in opencms-system.xml + CmsRuntimeException rte = new CmsRuntimeException(Messages + .get().container( + Messages.ERR_SEND_EMAIL_AUTHENTICATE_2, + host.getUsername(), host.getHostname())); + sfe.initCause(rte); + throw new EmailException(sfe); + } + // wrong hostname in opencms-system.xml + CmsRuntimeException rte = new CmsRuntimeException(Messages + .get().container(Messages.ERR_SEND_EMAIL_HOSTNAME_1, + host.getHostname()), me); + sfe.initCause(rte); + throw new EmailException(sfe); + } + } catch (MessagingException e) { + LOG.error(Messages.get().getBundle().key(Messages.LOG_MESSAGE_ID_ERR_0), e); + } + return messageID; + } } Index: src/org/opencms/mail/messages.properties =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/messages.properties,v retrieving revision 1.4 diff -u -r1.4 messages.properties --- src/org/opencms/mail/messages.properties 3 Jul 2005 09:41:53 -0000 1.4 +++ src/org/opencms/mail/messages.properties 10 Sep 2008 12:53:35 -0000 @@ -3,6 +3,7 @@ LOG_EMPTY_CONSTRUCTOR_CALLED_1 =Empty constructor called on {0}. LOG_INVALID_SENDER_ADDRESS_0 =The default email address is not valid. LOG_SEND_MAIL_ERR_0 =Error sending email. - +LOG_COMPOSE_MAIL_ERR_0 =Error composing email. +LOG_MESSAGE_ID_ERR_0 =Error retrieving message ID out of MIME message. ERR_SEND_EMAIL_AUTHENTICATE_2 =The mail server configuration in WEB-INF/config/opencms-system.xml has wrong authentication settings. User {0} was not accepted by the mail server {1}. ERR_SEND_EMAIL_HOSTNAME_1 =The mail server configuration in WEB-INF/config/opencms-system.xml contains an invalid mail server {0}. Index: src/org/opencms/mail/CmsMultiPartMail.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMultiPartMail.java,v retrieving revision 1.10 diff -u -r1.10 CmsMultiPartMail.java --- src/org/opencms/mail/CmsMultiPartMail.java 27 Feb 2008 12:05:41 -0000 1.10 +++ src/org/opencms/mail/CmsMultiPartMail.java 10 Sep 2008 12:53:35 -0000 @@ -31,15 +31,13 @@ package org.opencms.mail; +import org.apache.commons.logging.Log; +import org.apache.commons.mail.EmailException; +import org.apache.commons.mail.MultiPartEmail; import org.opencms.main.CmsLog; import org.opencms.main.OpenCms; import org.opencms.util.CmsStringUtil; -import javax.mail.MessagingException; - -import org.apache.commons.logging.Log; -import org.apache.commons.mail.MultiPartEmail; - /** * This class is used to send multi-part internet email like * messages with attachments.
@@ -82,7 +80,7 @@ try { // set default mail from address setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault()); - } catch (MessagingException e) { + } catch (EmailException e) { // default email address is not valid, log error LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e); } Index: src/org/opencms/mail/CmsHtmlMail.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/CmsHtmlMail.java,v retrieving revision 1.10 diff -u -r1.10 CmsHtmlMail.java --- src/org/opencms/mail/CmsHtmlMail.java 27 Feb 2008 12:05:41 -0000 1.10 +++ src/org/opencms/mail/CmsHtmlMail.java 10 Sep 2008 12:53:35 -0000 @@ -31,15 +31,13 @@ package org.opencms.mail; +import org.apache.commons.logging.Log; +import org.apache.commons.mail.EmailException; +import org.apache.commons.mail.HtmlEmail; import org.opencms.main.CmsLog; import org.opencms.main.OpenCms; import org.opencms.util.CmsStringUtil; -import javax.mail.MessagingException; - -import org.apache.commons.logging.Log; -import org.apache.commons.mail.HtmlEmail; - /** * This class is used to send an HTML formatted email with optional attachments.
* @@ -84,7 +82,7 @@ try { // set default mail from address setFrom(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault()); - } catch (MessagingException e) { + } catch (EmailException e) { // default email address is not valid, log error LOG.error(Messages.get().getBundle().key(Messages.LOG_INVALID_SENDER_ADDRESS_0), e); } Index: src/org/opencms/mail/Messages.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/Messages.java,v retrieving revision 1.8 diff -u -r1.8 Messages.java --- src/org/opencms/mail/Messages.java 27 Feb 2008 12:05:41 -0000 1.8 +++ src/org/opencms/mail/Messages.java 10 Sep 2008 12:53:35 -0000 @@ -61,6 +61,12 @@ public static final String LOG_EMPTY_CONSTRUCTOR_CALLED_1 = "LOG_EMPTY_CONSTRUCTOR_CALLED_1"; /** Message constant for key in the resource bundle. */ + public static final String LOG_COMPOSE_MAIL_ERR_0 = "LOG_COMPOSE_MAIL_ERR_0"; + + /** Message constant for key in the resource bundle. */ + public static final String LOG_MESSAGE_ID_ERR_0 = "LOG_MESSAGE_ID_ERR_0"; + + /** Message constant for key in the resource bundle. */ public static final String LOG_INVALID_SENDER_ADDRESS_0 = "LOG_INVALID_SENDER_ADDRESS_0"; /** Message constant for key in the resource bundle. */ Index: src/org/opencms/mail/CmsMailTransport.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/mail/CmsMailTransport.java,v retrieving revision 1.10 diff -u -r1.10 CmsMailTransport.java --- src/org/opencms/mail/CmsMailTransport.java 27 Feb 2008 12:05:41 -0000 1.10 +++ src/org/opencms/mail/CmsMailTransport.java 10 Sep 2008 12:53:35 -0000 @@ -31,12 +31,10 @@ package org.opencms.mail; -import org.opencms.main.CmsLog; - -import javax.mail.MessagingException; - import org.apache.commons.logging.Log; import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; +import org.opencms.main.CmsLog; /** * Sends an email using a Thread, so that the application can @@ -73,7 +71,7 @@ try { m_email.send(); - } catch (MessagingException e) { + } catch (EmailException e) { if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_ERR_0), e); } Index: src/org/opencms/newsletter/CmsNewsletter.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/newsletter/CmsNewsletter.java,v retrieving revision 1.6 diff -u -r1.6 CmsNewsletter.java --- src/org/opencms/newsletter/CmsNewsletter.java 27 Feb 2008 12:05:33 -0000 1.6 +++ src/org/opencms/newsletter/CmsNewsletter.java 10 Sep 2008 12:53:35 -0000 @@ -31,16 +31,6 @@ package org.opencms.newsletter; -import org.opencms.file.CmsObject; -import org.opencms.file.CmsPropertyDefinition; -import org.opencms.file.CmsResource; -import org.opencms.mail.CmsHtmlMail; -import org.opencms.mail.CmsSimpleMail; -import org.opencms.mail.CmsVfsDataSource; -import org.opencms.main.CmsException; -import org.opencms.util.CmsMacroResolver; -import org.opencms.util.CmsStringUtil; - import java.text.DateFormat; import java.util.ArrayList; import java.util.Date; @@ -49,141 +39,190 @@ import javax.mail.MessagingException; +import org.apache.commons.logging.Log; import org.apache.commons.mail.Email; +import org.apache.commons.mail.EmailException; +import org.opencms.file.CmsObject; +import org.opencms.file.CmsPropertyDefinition; +import org.opencms.file.CmsResource; +import org.opencms.mail.CmsHtmlMail; +import org.opencms.mail.CmsSimpleMail; +import org.opencms.mail.CmsVfsDataSource; +import org.opencms.mail.Messages; +import org.opencms.main.CmsException; +import org.opencms.main.CmsLog; +import org.opencms.util.CmsMacroResolver; +import org.opencms.util.CmsStringUtil; -/** - * Basic implementation of the interface {@link I_CmsNewsletter}.
+/** + * Basic implementation of the interface {@link I_CmsNewsletter}. + *
* * @author Jan Baudisch */ public class CmsNewsletter implements I_CmsNewsletter { - - /** The attachments, a list of {@link org.opencms.file.CmsResource} objects.
*/ - private List m_attachments; - - /** The contents, a list of {@link CmsNewsletterContent} objects.
*/ - private List m_contents; - - /** The subject of the newsletter.
*/ - private String m_subject; - - /** Creates a new newsletter instance.
*/ - public CmsNewsletter() { - - m_contents = new ArrayList(); - m_attachments = new ArrayList(); - } - - /** - * - * @see org.opencms.newsletter.I_CmsNewsletter#addAttachment(org.opencms.file.CmsObject, org.opencms.file.CmsResource) - */ - public void addAttachment(CmsObject cms, CmsResource resource) { - - m_attachments.add(resource); - } - - /** - * - * @see org.opencms.newsletter.I_CmsNewsletter#addContent(org.opencms.newsletter.I_CmsNewsletterContent) - */ - public void addContent(I_CmsNewsletterContent content) { - - m_contents.add(content); - } - - /** - * Returns the e-mail for the newsletter.
- * - * @param recipient the recipient to whom the newsletter is sent - * @param cms the CmsObject - * - * @return the e-mail for the newsletter - * - * @throws CmsException if something goes wrong - * @throws MessagingException if there is an error attaching resources - */ - public Email getEmail(CmsObject cms, I_CmsNewsletterRecipient recipient) throws MessagingException, CmsException { - - StringBuffer htmlMsg = new StringBuffer(1024); - StringBuffer txtMsg = new StringBuffer(1024); - Iterator contents = m_contents.iterator(); - while (contents.hasNext()) { - I_CmsNewsletterContent content = (I_CmsNewsletterContent)contents.next(); - if (recipient.isSubscriber(content)) { - if (content.getType().equals(CmsNewsletterContentType.TYPE_HTML)) { - htmlMsg.append(content.getContent()); - } else { - txtMsg.append(content.getContent()); - } - } - } - Email email; - if ((htmlMsg.length() > 0) || !m_attachments.isEmpty()) { - // we need to create a HTML mail - CmsHtmlMail htmlMail = new CmsHtmlMail(); - htmlMail.setHtmlMsg(replaceMacros(htmlMsg.toString(), recipient)); - Iterator attachments = m_attachments.iterator(); - while (attachments.hasNext()) { - CmsResource resource = (CmsResource)attachments.next(); - // set the description of the attachment either to the property description, if it is set, or - // to the property title - String description = ""; - String propertyDescription = cms.readPropertyObject( - cms.getSitePath(resource), - CmsPropertyDefinition.PROPERTY_DESCRIPTION, - true).getValue(); - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(propertyDescription)) { - description = propertyDescription; - } else { - String propertyTitle = cms.readPropertyObject( - cms.getSitePath(resource), - CmsPropertyDefinition.PROPERTY_TITLE, - true).getValue(); - description = propertyTitle; - } - htmlMail.attach(new CmsVfsDataSource(cms, resource), resource.getName(), description); - } - htmlMail.setTextMsg(replaceMacros(txtMsg.toString(), recipient)); - email = htmlMail; - } else { - // only text content, return text mail - CmsSimpleMail textMail = new CmsSimpleMail(); - textMail.setMsg(replaceMacros(txtMsg.toString(), recipient)); - email = textMail; - } - email.addTo(recipient.getEmail()); - email.setSubject(m_subject); - return email; - } - - /** - * - * @see org.opencms.newsletter.I_CmsNewsletter#setSubject(java.lang.String) - */ - public void setSubject(String subject) { - - m_subject = subject; - } - - /** - * Replaces the macros in the given message.
- * - * @param msg the message in which the macros are replaced - * @param recipient the recipient in the message - * - * @return the message with the macros replaced - */ - private String replaceMacros(String msg, I_CmsNewsletterRecipient recipient) { - - CmsMacroResolver resolver = CmsMacroResolver.newInstance(); - resolver.addMacro(MACRO_USER_FIRSTNAME, recipient.getFirstname()); - resolver.addMacro(MACRO_USER_LASTNAME, recipient.getLastname()); - resolver.addMacro(MACRO_USER_FULLNAME, recipient.getFullName()); - resolver.addMacro(MACRO_USER_EMAIL, recipient.getEmail()); - resolver.addMacro( - MACRO_SEND_DATE, - DateFormat.getDateTimeInstance().format(new Date(System.currentTimeMillis()))); - return resolver.resolveMacros(msg); - } + + /** The log object for this class. */ + private static final Log LOG = CmsLog.getLog(CmsNewsletter.class); + + /** + * The attachments, a list of {@link org.opencms.file.CmsResource} objects. + *
+ */ + private List m_attachments; + + /** + * The contents, a list of {@link CmsNewsletterContent} objects. + *
+ */ + private List m_contents; + + /** + * The subject of the newsletter. + *
+ */ + private String m_subject; + + /** + * Creates a new newsletter instance. + *
+ */ + public CmsNewsletter() { + + m_contents = new ArrayList(); + m_attachments = new ArrayList(); + } + + /** + * + * @see org.opencms.newsletter.I_CmsNewsletter#addAttachment(org.opencms.file.CmsObject, + * org.opencms.file.CmsResource) + */ + public void addAttachment(CmsObject cms, CmsResource resource) { + + m_attachments.add(resource); + } + + /** + * + * @see org.opencms.newsletter.I_CmsNewsletter#addContent(org.opencms.newsletter.I_CmsNewsletterContent) + */ + public void addContent(I_CmsNewsletterContent content) { + + m_contents.add(content); + } + + /** + * Returns the e-mail for the newsletter. + *
+ * + * @param recipient + * the recipient to whom the newsletter is sent + * @param cms + * the CmsObject + * + * @return the e-mail for the newsletter + * + * @throws CmsException + * if something goes wrong + * @throws MessagingException + * if there is an error attaching resources + */ + public Email getEmail(CmsObject cms, I_CmsNewsletterRecipient recipient) + throws MessagingException, CmsException { + + StringBuffer htmlMsg = new StringBuffer(1024); + StringBuffer txtMsg = new StringBuffer(1024); + Iterator contents = m_contents.iterator(); + while (contents.hasNext()) { + I_CmsNewsletterContent content = (I_CmsNewsletterContent) contents + .next(); + if (recipient.isSubscriber(content)) { + if (content.getType() + .equals(CmsNewsletterContentType.TYPE_HTML)) { + htmlMsg.append(content.getContent()); + } else { + txtMsg.append(content.getContent()); + } + } + } + Email email = null; + try { + if ((htmlMsg.length() > 0) || !m_attachments.isEmpty()) { + // we need to create a HTML mail + CmsHtmlMail htmlMail = new CmsHtmlMail(); + htmlMail + .setHtmlMsg(replaceMacros(htmlMsg.toString(), recipient)); + Iterator attachments = m_attachments.iterator(); + while (attachments.hasNext()) { + CmsResource resource = (CmsResource) attachments.next(); + // set the description of the attachment either to the + // property description, if it is set, or + // to the property title + String description = ""; + String propertyDescription = cms.readPropertyObject( + cms.getSitePath(resource), + CmsPropertyDefinition.PROPERTY_DESCRIPTION, true) + .getValue(); + if (CmsStringUtil + .isNotEmptyOrWhitespaceOnly(propertyDescription)) { + description = propertyDescription; + } else { + String propertyTitle = cms.readPropertyObject( + cms.getSitePath(resource), + CmsPropertyDefinition.PROPERTY_TITLE, true) + .getValue(); + description = propertyTitle; + } + htmlMail.attach(new CmsVfsDataSource(cms, resource), + resource.getName(), description); + } + htmlMail + .setTextMsg(replaceMacros(txtMsg.toString(), recipient)); + email = htmlMail; + } else { + // only text content, return text mail + CmsSimpleMail textMail = new CmsSimpleMail(); + textMail.setMsg(replaceMacros(txtMsg.toString(), recipient)); + email = textMail; + } + email.addTo(recipient.getEmail()); + email.setSubject(m_subject); + } catch (EmailException e) { + LOG.error(Messages.get().getBundle().key(Messages.LOG_COMPOSE_MAIL_ERR_0), e); + } + return email; + } + + /** + * + * @see org.opencms.newsletter.I_CmsNewsletter#setSubject(java.lang.String) + */ + public void setSubject(String subject) { + + m_subject = subject; + } + + /** + * Replaces the macros in the given message. + *
+ * + * @param msg + * the message in which the macros are replaced + * @param recipient + * the recipient in the message + * + * @return the message with the macros replaced + */ + private String replaceMacros(String msg, I_CmsNewsletterRecipient recipient) { + + CmsMacroResolver resolver = CmsMacroResolver.newInstance(); + resolver.addMacro(MACRO_USER_FIRSTNAME, recipient.getFirstname()); + resolver.addMacro(MACRO_USER_LASTNAME, recipient.getLastname()); + resolver.addMacro(MACRO_USER_FULLNAME, recipient.getFullName()); + resolver.addMacro(MACRO_USER_EMAIL, recipient.getEmail()); + resolver.addMacro(MACRO_SEND_DATE, DateFormat.getDateTimeInstance() + .format(new Date(System.currentTimeMillis()))); + return resolver.resolveMacros(msg); + } } \ No newline at end of file Index: src/org/opencms/notification/A_CmsNotification.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/notification/A_CmsNotification.java,v retrieving revision 1.7 diff -u -r1.7 A_CmsNotification.java --- src/org/opencms/notification/A_CmsNotification.java 27 Feb 2008 12:05:49 -0000 1.7 +++ src/org/opencms/notification/A_CmsNotification.java 10 Sep 2008 12:53:35 -0000 @@ -31,6 +31,13 @@ package org.opencms.notification; +import java.util.List; +import java.util.Locale; + +import javax.mail.MessagingException; + +import org.apache.commons.logging.Log; +import org.apache.commons.mail.EmailException; import org.opencms.db.CmsUserSettings; import org.opencms.file.CmsObject; import org.opencms.file.CmsUser; @@ -43,13 +50,6 @@ import org.opencms.xml.content.CmsXmlContent; import org.opencms.xml.content.CmsXmlContentFactory; -import java.util.List; -import java.util.Locale; - -import javax.mail.MessagingException; - -import org.apache.commons.logging.Log; - /** * Abstract class to create a notfication which will be send as a html mail to * a user in OpenCms. @@ -139,13 +139,13 @@ /** * @see org.apache.commons.mail.Email#send() */ - public void send() throws MessagingException { - + public String send() throws EmailException { + String messageID = null; try { // check if user is valid and has a mail address specified if (CmsStringUtil.isEmpty(m_receiver.getEmail())) { LOG.error(Messages.get().getBundle().key(Messages.LOG_NOTIFICATION_NO_ADDRESS_1, m_receiver.getName())); - return; + return null; } if (LOG.isInfoEnabled()) { @@ -205,9 +205,17 @@ // send mail super.send(); + + // get MIME message ID + messageID = this.getMimeMessage().getMessageID(); + } catch (CmsException e) { LOG.error(Messages.get().getBundle().key(Messages.LOG_NOTIFICATION_SEND_ERROR_0), e); } + catch (MessagingException e) { + LOG.error(Messages.get().getBundle().key(Messages.LOG_NOTIFICATION_SEND_ERROR_0), e); + } + return messageID; } /** Index: src/org/opencms/notification/CmsNotificationCandidates.java =================================================================== RCS file: /usr/local/cvs/opencms/src/org/opencms/notification/CmsNotificationCandidates.java,v retrieving revision 1.6 diff -u -r1.6 CmsNotificationCandidates.java --- src/org/opencms/notification/CmsNotificationCandidates.java 27 Feb 2008 12:05:49 -0000 1.6 +++ src/org/opencms/notification/CmsNotificationCandidates.java 10 Sep 2008 12:53:36 -0000 @@ -31,19 +31,6 @@ package org.opencms.notification; -import org.opencms.db.CmsDbEntryNotFoundException; -import org.opencms.db.CmsUserSettings; -import org.opencms.file.CmsObject; -import org.opencms.file.CmsPropertyDefinition; -import org.opencms.file.CmsResource; -import org.opencms.file.CmsResourceFilter; -import org.opencms.file.CmsUser; -import org.opencms.i18n.CmsLocaleManager; -import org.opencms.main.CmsException; -import org.opencms.main.CmsLog; -import org.opencms.main.OpenCms; -import org.opencms.util.CmsStringUtil; - import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; @@ -55,9 +42,20 @@ import java.util.Map; import java.util.TimeZone; -import javax.mail.MessagingException; - import org.apache.commons.logging.Log; +import org.apache.commons.mail.EmailException; +import org.opencms.db.CmsDbEntryNotFoundException; +import org.opencms.db.CmsUserSettings; +import org.opencms.file.CmsObject; +import org.opencms.file.CmsPropertyDefinition; +import org.opencms.file.CmsResource; +import org.opencms.file.CmsResourceFilter; +import org.opencms.file.CmsUser; +import org.opencms.i18n.CmsLocaleManager; +import org.opencms.main.CmsException; +import org.opencms.main.CmsLog; +import org.opencms.main.OpenCms; +import org.opencms.util.CmsStringUtil; /** * The basic class for the content notification feature in OpenCms. Collects all resources that require a notification, @@ -190,7 +188,7 @@ } try { contentNotification.send(); - } catch (MessagingException e) { + } catch (EmailException e) { LOG.error(e.getLocalizedMessage(), e); } } Index: src-modules/org/opencms/frontend/templateone/CmsTemplateFormRecommend.java =================================================================== RCS file: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/CmsTemplateFormRecommend.java,v retrieving revision 1.16 diff -u -r1.16 CmsTemplateFormRecommend.java --- src-modules/org/opencms/frontend/templateone/CmsTemplateFormRecommend.java 27 Feb 2008 12:05:27 -0000 1.16 +++ src-modules/org/opencms/frontend/templateone/CmsTemplateFormRecommend.java 10 Sep 2008 12:53:34 -0000 @@ -31,13 +31,6 @@ package org.opencms.frontend.templateone; -import org.opencms.mail.CmsHtmlMail; -import org.opencms.main.CmsException; -import org.opencms.main.CmsLog; -import org.opencms.main.OpenCms; -import org.opencms.util.CmsStringUtil; -import org.opencms.workplace.CmsWorkplace; - import java.util.HashMap; import javax.servlet.http.HttpServletRequest; @@ -45,247 +38,298 @@ import javax.servlet.jsp.PageContext; import org.apache.commons.logging.Log; +import org.opencms.mail.CmsHtmlMail; +import org.opencms.main.CmsException; +import org.opencms.main.CmsLog; +import org.opencms.main.OpenCms; +import org.opencms.util.CmsStringUtil; +import org.opencms.workplace.CmsWorkplace; /** - * Provides methods to build the page recommendation form.
+ * Provides methods to build the page recommendation form. + *
* - * @author Andreas Zahner + * @author Andreas Zahner * - * @version $Revision: 1.16 $ + * @version $Revision: 1.16 $ * - * @since 6.0.0 + * @since 6.0.0 */ public class CmsTemplateFormRecommend extends CmsTemplateForm { - /** The log object for this class. */ - private static final Log LOG = CmsLog.getLog(CmsTemplateFormRecommend.class); - - /** Stores the send copy to sender flag.
*/ - private String m_copy; - /** Stores the email recipient address.
*/ - private String m_emailRecipient; - /** Stores the email sender address.
*/ - private String m_emailSender; - /** Stores the message for the recipient.
*/ - private String m_message; - - /** - * Empty constructor, required for every JavaBean.
- */ - public CmsTemplateFormRecommend() { - - super(); - // set the members to empty Strings - m_emailRecipient = ""; - m_emailSender = ""; - m_message = ""; - m_copy = ""; - } - - /** - * Constructor, with parameters.
- * - * Use this constructor for the template.
- * - * @param context the JSP page context object - * @param req the JSP request - * @param res the JSP response - */ - public CmsTemplateFormRecommend(PageContext context, HttpServletRequest req, HttpServletResponse res) { - - super(); - super.init(context, req, res); - } - - /** - * Returns the send copy to sender flag.
- * - * @return the send copy to sender flag - */ - public String getCopy() { - - return m_copy; - } - - /** - * Returns the email recipient address.
- * - * @return the email recipient address - */ - public String getEmailRecipient() { - - return m_emailRecipient; - } - - /** - * Returns the email sender address.
- * - * @return the email sender address - */ - public String getEmailSender() { - - return m_emailSender; - } - - /** - * Returns the message for the recipient.
- * - * @return the message for the recipient - */ - public String getMessage() { - - return m_message; - } - - /** - * Examines the value of the send copy checkbox and returns the "checked" attribute.
- * - * @return the "checked" attribute or an empty String - */ - public String isCopyChecked() { - - return isChecked(getCopy()); - } - - /** - * Sends the recommendation email(s) to the recipient and/or the sender.
- * - * @return true if the emails were successfully sent, otherwise false; - */ - public boolean sendMail() { - - // create the new mail message - CmsHtmlMail theMail = new CmsHtmlMail(); - theMail.setSubject(key("recommend.mail.subject.prefix") + getPageTitle()); - theMail.setCharset(getRequestContext().getEncoding()); - theMail.setHtmlMsg(getContent("recommend_mail.html", "html", getRequestContext().getLocale())); - theMail.setTextMsg(getContent("recommend_mail.html", "text", getRequestContext().getLocale())); - try { - // set the recipient and the reply to address - theMail.addTo(getEmailRecipient()); - String sender = OpenCms.getSystemInfo().getMailSettings().getMailFromDefault(); - String replyTo = getEmailSender(); - if (CmsStringUtil.isEmptyOrWhitespaceOnly(replyTo)) { - replyTo = sender; - } - theMail.setFrom(sender); - theMail.addReplyTo(replyTo); - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { - // send a copy of the mail to the sender - theMail.addCc(replyTo); - } - // send the mail - theMail.send(); - } catch (Exception e) { - if (LOG.isWarnEnabled()) { - LOG.warn(e); - } else if (LOG.isErrorEnabled()) { - LOG.error(Messages.get().getBundle().key( - Messages.LOG_SEND_MAIL_RECOMMENDPAGE_1, - getRequestContext().getUri())); - } - return false; - } - return true; - } - - /** - * Sets the send copy to sender flag.
- * - * @param copy the send copy to sender flag - */ - public void setCopy(String copy) { - - m_copy = copy; - } - - /** - * Sets the email recipient address.
- * - * @param emailRecipient email recipient address - */ - public void setEmailRecipient(String emailRecipient) { - - m_emailRecipient = emailRecipient; - } - - /** - * Sets the email sender address.
- * - * @param emailSender the email sender address - */ - public void setEmailSender(String emailSender) { - - m_emailSender = emailSender; - } - - /** - * Sets the message for the recipient.
- * - * @param message the message for the recipient - */ - public void setMessage(String message) { - - m_message = message; - } - - /** - * Validates the values of the input fields and creates error messages, if necessary.
- * - * @return true if all checked input values are valid, otherwise false - */ - public boolean validate() { - - boolean allOk = true; - setErrors(new HashMap()); - - // check email recipient - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getEmailRecipient())) { - // recipient is empty - getErrors().put("recipient", key("recommend.error.recipient.empty")); - allOk = false; - } else if (!isValidEmailAddress(getEmailRecipient())) { - // recipient is not valid - getErrors().put("recipient", key("recommend.error.recipient.wrong")); - allOk = false; - } - // check message - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) { - getErrors().put("message", key("recommend.error.message.empty")); - allOk = false; - } - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { - // send copy to sender is checked, check sender address - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getEmailSender())) { - // sender is empty - getErrors().put("sender", key("recommend.error.sender.empty")); - allOk = false; - } - } - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getEmailSender()) && !isValidEmailAddress(getEmailSender())) { - // sender is not valid - getErrors().put("sender", key("recommend.error.sender.wrong")); - allOk = false; - } - return allOk; - } - - /** - * @see org.opencms.frontend.templateone.CmsTemplateForm#checkTextsUri() - */ - protected String checkTextsUri() { - - String fileUri = getConfigurationValue("page.form.recommend", null); - if (fileUri != null) { - fileUri = getRequestContext().removeSiteRoot(fileUri); - try { - getCmsObject().readResource(fileUri); - return fileUri; - } catch (CmsException e) { - // file not found, use default texts page file - } - } - return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/pages/recommend_content.html"; - } + /** The log object for this class. */ + private static final Log LOG = CmsLog + .getLog(CmsTemplateFormRecommend.class); + + /** + * Stores the send copy to sender flag. + *
+ */ + private String m_copy; + /** + * Stores the email recipient address. + *
+ */ + private String m_emailRecipient; + /** + * Stores the email sender address. + *
+ */ + private String m_emailSender; + /** + * Stores the message for the recipient. + *
+ */ + private String m_message; + + /** + * Empty constructor, required for every JavaBean. + *
+ */ + public CmsTemplateFormRecommend() { + + super(); + // set the members to empty Strings + m_emailRecipient = ""; + m_emailSender = ""; + m_message = ""; + m_copy = ""; + } + + /** + * Constructor, with parameters. + *
+ * + * Use this constructor for the template. + *
+ * + * @param context + * the JSP page context object + * @param req + * the JSP request + * @param res + * the JSP response + */ + public CmsTemplateFormRecommend(PageContext context, + HttpServletRequest req, HttpServletResponse res) { + + super(); + super.init(context, req, res); + } + + /** + * Returns the send copy to sender flag. + *
+ * + * @return the send copy to sender flag + */ + public String getCopy() { + + return m_copy; + } + + /** + * Returns the email recipient address. + *
+ * + * @return the email recipient address + */ + public String getEmailRecipient() { + + return m_emailRecipient; + } + + /** + * Returns the email sender address. + *
+ * + * @return the email sender address + */ + public String getEmailSender() { + + return m_emailSender; + } + + /** + * Returns the message for the recipient. + *
+ * + * @return the message for the recipient + */ + public String getMessage() { + + return m_message; + } + + /** + * Examines the value of the send copy checkbox and returns the "checked" + * attribute. + *
+ * + * @return the "checked" attribute or an empty String + */ + public String isCopyChecked() { + + return isChecked(getCopy()); + } + + /** + * Sends the recommendation email(s) to the recipient and/or the sender. + *
+ * + * @return true if the emails were successfully sent, otherwise false; + */ + public boolean sendMail() { + try { + // create the new mail message + CmsHtmlMail theMail = new CmsHtmlMail(); + theMail.setSubject(key("recommend.mail.subject.prefix") + + getPageTitle()); + theMail.setCharset(getRequestContext().getEncoding()); + theMail.setHtmlMsg(getContent("recommend_mail.html", "html", + getRequestContext().getLocale())); + theMail.setTextMsg(getContent("recommend_mail.html", "text", + getRequestContext().getLocale())); + // set the recipient and the reply to address + theMail.addTo(getEmailRecipient()); + String sender = OpenCms.getSystemInfo().getMailSettings() + .getMailFromDefault(); + String replyTo = getEmailSender(); + if (CmsStringUtil.isEmptyOrWhitespaceOnly(replyTo)) { + replyTo = sender; + } + theMail.setFrom(sender); + theMail.addReplyTo(replyTo); + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { + // send a copy of the mail to the sender + theMail.addCc(replyTo); + } + // send the mail + theMail.send(); + } catch (Exception e) { + if (LOG.isWarnEnabled()) { + LOG.warn(e); + } else if (LOG.isErrorEnabled()) { + LOG.error(Messages.get().getBundle().key( + Messages.LOG_SEND_MAIL_RECOMMENDPAGE_1, + getRequestContext().getUri())); + } + return false; + } + return true; + } + + /** + * Sets the send copy to sender flag. + *
+ * + * @param copy + * the send copy to sender flag + */ + public void setCopy(String copy) { + + m_copy = copy; + } + + /** + * Sets the email recipient address. + *
+ * + * @param emailRecipient + * email recipient address + */ + public void setEmailRecipient(String emailRecipient) { + + m_emailRecipient = emailRecipient; + } + + /** + * Sets the email sender address. + *
+ * + * @param emailSender + * the email sender address + */ + public void setEmailSender(String emailSender) { + + m_emailSender = emailSender; + } + + /** + * Sets the message for the recipient. + *
+ * + * @param message + * the message for the recipient + */ + public void setMessage(String message) { + + m_message = message; + } + + /** + * Validates the values of the input fields and creates error messages, if + * necessary. + *
+ * + * @return true if all checked input values are valid, otherwise false + */ + public boolean validate() { + + boolean allOk = true; + setErrors(new HashMap()); + + // check email recipient + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getEmailRecipient())) { + // recipient is empty + getErrors() + .put("recipient", key("recommend.error.recipient.empty")); + allOk = false; + } else if (!isValidEmailAddress(getEmailRecipient())) { + // recipient is not valid + getErrors() + .put("recipient", key("recommend.error.recipient.wrong")); + allOk = false; + } + // check message + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) { + getErrors().put("message", key("recommend.error.message.empty")); + allOk = false; + } + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { + // send copy to sender is checked, check sender address + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getEmailSender())) { + // sender is empty + getErrors().put("sender", key("recommend.error.sender.empty")); + allOk = false; + } + } + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getEmailSender()) + && !isValidEmailAddress(getEmailSender())) { + // sender is not valid + getErrors().put("sender", key("recommend.error.sender.wrong")); + allOk = false; + } + return allOk; + } + + /** + * @see org.opencms.frontend.templateone.CmsTemplateForm#checkTextsUri() + */ + protected String checkTextsUri() { + + String fileUri = getConfigurationValue("page.form.recommend", null); + if (fileUri != null) { + fileUri = getRequestContext().removeSiteRoot(fileUri); + try { + getCmsObject().readResource(fileUri); + return fileUri; + } catch (CmsException e) { + // file not found, use default texts page file + } + } + return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + + "/pages/recommend_content.html"; + } } Index: src-modules/org/opencms/frontend/templateone/CmsTemplateFormLetter.java =================================================================== RCS file: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/CmsTemplateFormLetter.java,v retrieving revision 1.16 diff -u -r1.16 CmsTemplateFormLetter.java --- src-modules/org/opencms/frontend/templateone/CmsTemplateFormLetter.java 27 Feb 2008 12:05:27 -0000 1.16 +++ src-modules/org/opencms/frontend/templateone/CmsTemplateFormLetter.java 10 Sep 2008 12:53:34 -0000 @@ -31,13 +31,6 @@ package org.opencms.frontend.templateone; -import org.opencms.mail.CmsHtmlMail; -import org.opencms.main.CmsException; -import org.opencms.main.CmsLog; -import org.opencms.main.OpenCms; -import org.opencms.util.CmsStringUtil; -import org.opencms.workplace.CmsWorkplace; - import java.util.HashMap; import javax.servlet.http.HttpServletRequest; @@ -45,542 +38,669 @@ import javax.servlet.jsp.PageContext; import org.apache.commons.logging.Log; +import org.opencms.mail.CmsHtmlMail; +import org.opencms.main.CmsException; +import org.opencms.main.CmsLog; +import org.opencms.main.OpenCms; +import org.opencms.util.CmsStringUtil; +import org.opencms.workplace.CmsWorkplace; /** - * Provides methods to build the page "letter to the editor" form.
+ * Provides methods to build the page "letter to the editor" form. + *
* - * @author Andreas Zahner + * @author Andreas Zahner * - * @version $Revision: 1.16 $ + * @version $Revision: 1.16 $ * - * @since 6.0.0 + * @since 6.0.0 */ public class CmsTemplateFormLetter extends CmsTemplateForm { - /** The log object for this class. */ - private static final Log LOG = CmsLog.getLog(CmsTemplateFormLetter.class); + /** The log object for this class. */ + private static final Log LOG = CmsLog.getLog(CmsTemplateFormLetter.class); - /** Stores the type of concern.
*/ - private String m_concern; - /** Stores the details of the concern.
*/ - private String m_concernDetail; - /** Stores the contact city.
*/ - private String m_contactCity; - /** Stores the contact country.
*/ - private String m_contactCountry; - /** Stores the contact email address.
*/ - private String m_contactEmail; - /** Stores the contacts first name.
*/ - private String m_contactFirstName; - /** Stores the contacts last name.
*/ - private String m_contactLastName; - /** Stores the contact street number.
*/ - private String m_contactNumber; - /** Stores the contact phone number.
*/ - private String m_contactPhone; - /** Stores the contact salutation.
*/ - private String m_contactSalutation; - /** Stores the contact street.
*/ - private String m_contactStreet; - /** Stores the contact title.
*/ - private String m_contactTitle; - /** Stores the contact zip code.
*/ - private String m_contactZip; - /** Stores the send copy to sender flag.
*/ - private String m_copy; - /** Stores the message for the recipient.
*/ - private String m_message; - - /** - * Empty constructor, required for every JavaBean.
- */ - public CmsTemplateFormLetter() { - - super(); - // set the members to empty Strings - m_concern = ""; - m_concernDetail = ""; - m_contactCity = ""; - m_contactCountry = ""; - m_contactEmail = ""; - m_contactFirstName = ""; - m_contactLastName = ""; - m_contactNumber = ""; - m_contactPhone = ""; - m_contactSalutation = ""; - m_contactStreet = ""; - m_contactTitle = ""; - m_contactZip = ""; - m_copy = ""; - m_message = ""; - - } - - /** - * Constructor, with parameters.
- * - * Use this constructor for the template.
- * - * @param context the JSP page context object - * @param req the JSP request - * @param res the JSP response - */ - public CmsTemplateFormLetter(PageContext context, HttpServletRequest req, HttpServletResponse res) { - - super(); - super.init(context, req, res); - } - - /** - * Returns the concern of contact.
- * - * @return the concern of contact - */ - public String getConcern() { - - return m_concern; - } - - /** - * Returns the concern details if specified.
- * - * @return the concern details if specified - */ - public String getConcernDetail() { - - return m_concernDetail; - } - - /** - * Returns the contact city.
- * - * @return the contact city - */ - public String getContactCity() { - - return m_contactCity; - } - - /** - * Returns the contact country.
- * - * @return the contact country - */ - public String getContactCountry() { - - return m_contactCountry; - } - - /** - * Returns the contact email address.
- * - * @return the contact email address - */ - public String getContactEmail() { - - return m_contactEmail; - } - - /** - * Returns the contact first name.
- * - * @return the contact first name - */ - public String getContactFirstName() { - - return m_contactFirstName; - } - - /** - * Returns the contact last name.
- * - * @return the contact last name - */ - public String getContactLastName() { - - return m_contactLastName; - } - - /** - * Returns the contact street number.
- * - * @return the contact street number - */ - public String getContactNumber() { - - return m_contactNumber; - } - - /** - * Returns the contact phone number.
- * - * @return the contact phone number - */ - public String getContactPhone() { - - return m_contactPhone; - } - - /** - * Returns the contact salutation.
- * - * @return the contact salutation - */ - public String getContactSalutation() { - - return m_contactSalutation; - } - - /** - * Returns the contact street.
- * - * @return the contact street - */ - public String getContactStreet() { - - return m_contactStreet; - } - - /** - * Returns the contact title.
- * - * @return the contact title - */ - public String getContactTitle() { - - return m_contactTitle; - } - - /** - * Returns the contact zip code.
- * - * @return the contact zip code - */ - public String getContactZip() { - - return m_contactZip; - } - - /** - * Returns the send copy to sender flag.
- * - * @return the send copy to sender flag - */ - public String getCopy() { - - return m_copy; - } - - /** - * Returns the message for the recipient.
- * - * @return the message for the recipient - */ - public String getMessage() { - - return m_message; - } - - /** - * Returns the "checked" attribute if the current "concern" radio button is checked.
- * - * @param currentValue the value of the current radio button to check - * @return the "checked" attribute if the current "concern" radio button is checked - */ - public String isConcernChecked(String currentValue) { - - if (isSelected(currentValue, getConcern())) { - return " checked=\"checked\""; - } - return ""; - } - - /** - * Examines the value of the send copy checkbox and returns the "checked" attribute.
- * - * @return the "checked" attribute or an empty String - */ - public String isCopyChecked() { - - return isChecked(getCopy()); - } - - /** - * Returns the "selected" attribute if the current "contact option" is selected.
- * - * @param currentValue the value of the current radio button to check - * @return the "selected" attribute if the current "contact option" is selected - */ - public String isSalutationSelected(String currentValue) { - - if (isSelected(currentValue, getContactSalutation())) { - return " selected=\"selected\""; - } - return ""; - } - - /** - * Sends the recommendation email(s) to the recipient and/or the sender.
- * - * @return true if the emails were successfully sent, otherwise false; - */ - public boolean sendMail() { - - // create the new mail message - CmsHtmlMail theMail = new CmsHtmlMail(); - theMail.setSubject(key("letter.mail.subject.prefix") + getPageTitle()); - theMail.setCharset(getRequestContext().getEncoding()); - theMail.setHtmlMsg(getContent("letter_mail.html", "html", getRequestContext().getLocale())); - theMail.setTextMsg(getContent("letter_mail.html", "text", getRequestContext().getLocale())); - try { - // store the uri - String uri = getRequestContext().getUri(); - // set the recipient from imprint information - try { - // create an instance of imprint bean - CmsTemplateImprint imprint = new CmsTemplateImprint(getJspContext(), getRequest(), getResponse()); - // get the author email address - String receiver = imprint.getEmail(null); - theMail.addTo(receiver); - } finally { - // set request context uri back because this is changed in imprint bean - getRequestContext().setUri(uri); - } - // set the recipient and the reply to address - String sender = OpenCms.getSystemInfo().getMailSettings().getMailFromDefault(); - String contactMail = getContactEmail(); - if (CmsStringUtil.isEmptyOrWhitespaceOnly(contactMail)) { - contactMail = sender; - } - theMail.setFrom(sender); - theMail.addReplyTo(contactMail); - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { - // send a copy of the mail to the sender - theMail.addCc(contactMail); - } - // send the mail - theMail.send(); - } catch (Exception e) { - if (LOG.isWarnEnabled()) { - LOG.warn(e); - } else if (LOG.isErrorEnabled()) { - LOG.error(Messages.get().getBundle().key(Messages.LOG_SEND_MAIL_CONTACT_1)); - } - return false; - } - return true; - } - - /** - * Sets the concern of contact.
- * - * @param concern the concern of contact - */ - public void setConcern(String concern) { - - m_concern = concern; - } - - /** - * Sets the concern details if specified.
- * - * @param concernDetail the concern details if specified - */ - public void setConcernDetail(String concernDetail) { - - m_concernDetail = concernDetail; - } - - /** - * Sets the contact city.
- * - * @param contactCity the contact city - */ - public void setContactCity(String contactCity) { - - m_contactCity = contactCity; - } - - /** - * Sets the contact country.
- * - * @param contactCountry the contact country - */ - public void setContactCountry(String contactCountry) { - - m_contactCountry = contactCountry; - } - - /** - * Sets the contact email address.
- * - * @param email the contact email address - */ - public void setContactEmail(String email) { - - m_contactEmail = email; - } - - /** - * Sets the contact first name.
- * - * @param contactFirstName the contact first name - */ - public void setContactFirstName(String contactFirstName) { - - m_contactFirstName = contactFirstName; - } - - /** - * Sets the contact last name.
- * - * @param contactLastName the contact last name - */ - public void setContactLastName(String contactLastName) { - - m_contactLastName = contactLastName; - } - - /** - * Sets the contact street number.
- * - * @param contactNumber the contact street number - */ - public void setContactNumber(String contactNumber) { - - m_contactNumber = contactNumber; - } - - /** - * Sets the contact phone number.
- * - * @param contactPhone the contact phone number - */ - public void setContactPhone(String contactPhone) { - - m_contactPhone = contactPhone; - } - - /** - * Sets the contact salutation.
- * - * @param contactSalutation the contact salutation - */ - public void setContactSalutation(String contactSalutation) { - - m_contactSalutation = contactSalutation; - } - - /** - * Sets the contact street.
- * - * @param contactStreet the contact street - */ - public void setContactStreet(String contactStreet) { - - m_contactStreet = contactStreet; - } - - /** - * Sets the contact title.
- * - * @param contactTitle the contact title - */ - public void setContactTitle(String contactTitle) { - - m_contactTitle = contactTitle; - } - - /** - * Sets the contact zip code.
- * - * @param contactZip the contact zip code - */ - public void setContactZip(String contactZip) { - - m_contactZip = contactZip; - } - - /** - * Sets the send copy to sender flag.
- * - * @param copy the send copy to sender flag - */ - public void setCopy(String copy) { - - m_copy = copy; - } - - /** - * Sets the message for the recipient.
- * - * @param message the message for the recipient - */ - public void setMessage(String message) { - - m_message = message; - } - - /** - * Validates the values of the input fields and creates error messages, if necessary.
- * - * @return true if all checked input values are valid, otherwise false - */ - public boolean validate() { - - boolean allOk = true; - setErrors(new HashMap()); - // check concern - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcern())) { - getErrors().put("concern", key("letter.error.concern.empty")); - allOk = false; - } else { - // concern given, check if "other" is selected - if ("other".equals(getConcern())) { - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcernDetail())) { - // details not given - getErrors().put("concern", key("letter.error.concerndetails.empty")); - allOk = false; - } - } - } - // check message - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) { - getErrors().put("message", key("letter.error.message.empty")); - allOk = false; - } - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { - // send copy to sender is checked, check email address - if (CmsStringUtil.isEmptyOrWhitespaceOnly(getContactEmail())) { - // email address is empty - getErrors().put("email", key("letter.error.email.empty")); - allOk = false; - } - } - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getContactEmail()) && !isValidEmailAddress(getContactEmail())) { - // email address is not valid - getErrors().put("email", key("letter.error.email.wrong")); - allOk = false; - } - return allOk; - } - - /** - * @see org.opencms.frontend.templateone.CmsTemplateForm#checkTextsUri() - */ - protected String checkTextsUri() { - - String fileUri = getConfigurationValue("page.form.letter", null); - if (fileUri != null) { - fileUri = getRequestContext().removeSiteRoot(fileUri); - try { - getCmsObject().readResource(fileUri); - return fileUri; - } catch (CmsException e) { - // file not found, use default texts page file - } - } - return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + "/pages/letter_content.html"; - } + /** + * Stores the type of concern. + *
+ */ + private String m_concern; + /** + * Stores the details of the concern. + *
+ */ + private String m_concernDetail; + /** + * Stores the contact city. + *
+ */ + private String m_contactCity; + /** + * Stores the contact country. + *
+ */ + private String m_contactCountry; + /** + * Stores the contact email address. + *
+ */ + private String m_contactEmail; + /** + * Stores the contacts first name. + *
+ */ + private String m_contactFirstName; + /** + * Stores the contacts last name. + *
+ */ + private String m_contactLastName; + /** + * Stores the contact street number. + *
+ */ + private String m_contactNumber; + /** + * Stores the contact phone number. + *
+ */ + private String m_contactPhone; + /** + * Stores the contact salutation. + *
+ */ + private String m_contactSalutation; + /** + * Stores the contact street. + *
+ */ + private String m_contactStreet; + /** + * Stores the contact title. + *
+ */ + private String m_contactTitle; + /** + * Stores the contact zip code. + *
+ */ + private String m_contactZip; + /** + * Stores the send copy to sender flag. + *
+ */ + private String m_copy; + /** + * Stores the message for the recipient. + *
+ */ + private String m_message; + + /** + * Empty constructor, required for every JavaBean. + *
+ */ + public CmsTemplateFormLetter() { + + super(); + // set the members to empty Strings + m_concern = ""; + m_concernDetail = ""; + m_contactCity = ""; + m_contactCountry = ""; + m_contactEmail = ""; + m_contactFirstName = ""; + m_contactLastName = ""; + m_contactNumber = ""; + m_contactPhone = ""; + m_contactSalutation = ""; + m_contactStreet = ""; + m_contactTitle = ""; + m_contactZip = ""; + m_copy = ""; + m_message = ""; + + } + + /** + * Constructor, with parameters. + *
+ * + * Use this constructor for the template. + *
+ * + * @param context + * the JSP page context object + * @param req + * the JSP request + * @param res + * the JSP response + */ + public CmsTemplateFormLetter(PageContext context, HttpServletRequest req, + HttpServletResponse res) { + + super(); + super.init(context, req, res); + } + + /** + * Returns the concern of contact. + *
+ * + * @return the concern of contact + */ + public String getConcern() { + + return m_concern; + } + + /** + * Returns the concern details if specified. + *
+ * + * @return the concern details if specified + */ + public String getConcernDetail() { + + return m_concernDetail; + } + + /** + * Returns the contact city. + *
+ * + * @return the contact city + */ + public String getContactCity() { + + return m_contactCity; + } + + /** + * Returns the contact country. + *
+ * + * @return the contact country + */ + public String getContactCountry() { + + return m_contactCountry; + } + + /** + * Returns the contact email address. + *
+ * + * @return the contact email address + */ + public String getContactEmail() { + + return m_contactEmail; + } + + /** + * Returns the contact first name. + *
+ * + * @return the contact first name + */ + public String getContactFirstName() { + + return m_contactFirstName; + } + + /** + * Returns the contact last name. + *
+ * + * @return the contact last name + */ + public String getContactLastName() { + + return m_contactLastName; + } + + /** + * Returns the contact street number. + *
+ * + * @return the contact street number + */ + public String getContactNumber() { + + return m_contactNumber; + } + + /** + * Returns the contact phone number. + *
+ * + * @return the contact phone number + */ + public String getContactPhone() { + + return m_contactPhone; + } + + /** + * Returns the contact salutation. + *
+ * + * @return the contact salutation + */ + public String getContactSalutation() { + + return m_contactSalutation; + } + + /** + * Returns the contact street. + *
+ * + * @return the contact street + */ + public String getContactStreet() { + + return m_contactStreet; + } + + /** + * Returns the contact title. + *
+ * + * @return the contact title + */ + public String getContactTitle() { + + return m_contactTitle; + } + + /** + * Returns the contact zip code. + *
+ * + * @return the contact zip code + */ + public String getContactZip() { + + return m_contactZip; + } + + /** + * Returns the send copy to sender flag. + *
+ * + * @return the send copy to sender flag + */ + public String getCopy() { + + return m_copy; + } + + /** + * Returns the message for the recipient. + *
+ * + * @return the message for the recipient + */ + public String getMessage() { + + return m_message; + } + + /** + * Returns the "checked" attribute if the current "concern" radio button is + * checked. + *
+ * + * @param currentValue + * the value of the current radio button to check + * @return the "checked" attribute if the current "concern" radio button is + * checked + */ + public String isConcernChecked(String currentValue) { + + if (isSelected(currentValue, getConcern())) { + return " checked=\"checked\""; + } + return ""; + } + + /** + * Examines the value of the send copy checkbox and returns the "checked" + * attribute. + *
+ * + * @return the "checked" attribute or an empty String + */ + public String isCopyChecked() { + + return isChecked(getCopy()); + } + + /** + * Returns the "selected" attribute if the current "contact option" is + * selected. + *
+ * + * @param currentValue + * the value of the current radio button to check + * @return the "selected" attribute if the current "contact option" is + * selected + */ + public String isSalutationSelected(String currentValue) { + + if (isSelected(currentValue, getContactSalutation())) { + return " selected=\"selected\""; + } + return ""; + } + + /** + * Sends the recommendation email(s) to the recipient and/or the sender. + *
+ * + * @return true if the emails were successfully sent, otherwise false; + */ + public boolean sendMail() { + + try { + // create the new mail message + CmsHtmlMail theMail = new CmsHtmlMail(); + theMail.setSubject(key("letter.mail.subject.prefix") + + getPageTitle()); + theMail.setCharset(getRequestContext().getEncoding()); + theMail.setHtmlMsg(getContent("letter_mail.html", "html", + getRequestContext().getLocale())); + theMail.setTextMsg(getContent("letter_mail.html", "text", + getRequestContext().getLocale())); + // store the uri + String uri = getRequestContext().getUri(); + // set the recipient from imprint information + try { + // create an instance of imprint bean + CmsTemplateImprint imprint = new CmsTemplateImprint( + getJspContext(), getRequest(), getResponse()); + // get the author email address + String receiver = imprint.getEmail(null); + theMail.addTo(receiver); + } finally { + // set request context uri back because this is changed in + // imprint bean + getRequestContext().setUri(uri); + } + // set the recipient and the reply to address + String sender = OpenCms.getSystemInfo().getMailSettings() + .getMailFromDefault(); + String contactMail = getContactEmail(); + if (CmsStringUtil.isEmptyOrWhitespaceOnly(contactMail)) { + contactMail = sender; + } + theMail.setFrom(sender); + theMail.addReplyTo(contactMail); + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { + // send a copy of the mail to the sender + theMail.addCc(contactMail); + } + // send the mail + theMail.send(); + } catch (Exception e) { + if (LOG.isWarnEnabled()) { + LOG.warn(e); + } else if (LOG.isErrorEnabled()) { + LOG.error(Messages.get().getBundle().key( + Messages.LOG_SEND_MAIL_CONTACT_1)); + } + return false; + } + return true; + } + + /** + * Sets the concern of contact. + *
+ * + * @param concern + * the concern of contact + */ + public void setConcern(String concern) { + + m_concern = concern; + } + + /** + * Sets the concern details if specified. + *
+ * + * @param concernDetail + * the concern details if specified + */ + public void setConcernDetail(String concernDetail) { + + m_concernDetail = concernDetail; + } + + /** + * Sets the contact city. + *
+ * + * @param contactCity + * the contact city + */ + public void setContactCity(String contactCity) { + + m_contactCity = contactCity; + } + + /** + * Sets the contact country. + *
+ * + * @param contactCountry + * the contact country + */ + public void setContactCountry(String contactCountry) { + + m_contactCountry = contactCountry; + } + + /** + * Sets the contact email address. + *
+ * + * @param email + * the contact email address + */ + public void setContactEmail(String email) { + + m_contactEmail = email; + } + + /** + * Sets the contact first name. + *
+ * + * @param contactFirstName + * the contact first name + */ + public void setContactFirstName(String contactFirstName) { + + m_contactFirstName = contactFirstName; + } + + /** + * Sets the contact last name. + *
+ * + * @param contactLastName + * the contact last name + */ + public void setContactLastName(String contactLastName) { + + m_contactLastName = contactLastName; + } + + /** + * Sets the contact street number. + *
+ * + * @param contactNumber + * the contact street number + */ + public void setContactNumber(String contactNumber) { + + m_contactNumber = contactNumber; + } + + /** + * Sets the contact phone number. + *
+ * + * @param contactPhone + * the contact phone number + */ + public void setContactPhone(String contactPhone) { + + m_contactPhone = contactPhone; + } + + /** + * Sets the contact salutation. + *
+ * + * @param contactSalutation + * the contact salutation + */ + public void setContactSalutation(String contactSalutation) { + + m_contactSalutation = contactSalutation; + } + + /** + * Sets the contact street. + *
+ * + * @param contactStreet + * the contact street + */ + public void setContactStreet(String contactStreet) { + + m_contactStreet = contactStreet; + } + + /** + * Sets the contact title. + *
+ * + * @param contactTitle + * the contact title + */ + public void setContactTitle(String contactTitle) { + + m_contactTitle = contactTitle; + } + + /** + * Sets the contact zip code. + *
+ * + * @param contactZip + * the contact zip code + */ + public void setContactZip(String contactZip) { + + m_contactZip = contactZip; + } + + /** + * Sets the send copy to sender flag. + *
+ * + * @param copy + * the send copy to sender flag + */ + public void setCopy(String copy) { + + m_copy = copy; + } + + /** + * Sets the message for the recipient. + *
+ * + * @param message + * the message for the recipient + */ + public void setMessage(String message) { + + m_message = message; + } + + /** + * Validates the values of the input fields and creates error messages, if + * necessary. + *
+ * + * @return true if all checked input values are valid, otherwise false + */ + public boolean validate() { + + boolean allOk = true; + setErrors(new HashMap()); + // check concern + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcern())) { + getErrors().put("concern", key("letter.error.concern.empty")); + allOk = false; + } else { + // concern given, check if "other" is selected + if ("other".equals(getConcern())) { + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getConcernDetail())) { + // details not given + getErrors().put("concern", + key("letter.error.concerndetails.empty")); + allOk = false; + } + } + } + // check message + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getMessage())) { + getErrors().put("message", key("letter.error.message.empty")); + allOk = false; + } + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCopy())) { + // send copy to sender is checked, check email address + if (CmsStringUtil.isEmptyOrWhitespaceOnly(getContactEmail())) { + // email address is empty + getErrors().put("email", key("letter.error.email.empty")); + allOk = false; + } + } + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getContactEmail()) + && !isValidEmailAddress(getContactEmail())) { + // email address is not valid + getErrors().put("email", key("letter.error.email.wrong")); + allOk = false; + } + return allOk; + } + + /** + * @see org.opencms.frontend.templateone.CmsTemplateForm#checkTextsUri() + */ + protected String checkTextsUri() { + + String fileUri = getConfigurationValue("page.form.letter", null); + if (fileUri != null) { + fileUri = getRequestContext().removeSiteRoot(fileUri); + try { + getCmsObject().readResource(fileUri); + return fileUri; + } catch (CmsException e) { + // file not found, use default texts page file + } + } + return CmsWorkplace.VFS_PATH_MODULES + MODULE_NAME + + "/pages/letter_content.html"; + } } Index: src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsMessageInfo.java =================================================================== RCS file: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsMessageInfo.java,v retrieving revision 1.14 diff -u -r1.14 CmsMessageInfo.java --- src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsMessageInfo.java 27 Feb 2008 12:05:53 -0000 1.14 +++ src-modules/org/opencms/workplace/tools/workplace/broadcast/CmsMessageInfo.java 10 Sep 2008 12:53:35 -0000 @@ -31,12 +31,6 @@ package org.opencms.workplace.tools.workplace.broadcast; -import org.opencms.file.CmsObject; -import org.opencms.mail.CmsSimpleMail; -import org.opencms.main.CmsIllegalArgumentException; -import org.opencms.main.OpenCms; -import org.opencms.util.CmsStringUtil; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -47,227 +41,273 @@ import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; +import org.apache.commons.mail.EmailException; +import org.opencms.file.CmsObject; +import org.opencms.mail.CmsSimpleMail; +import org.opencms.main.CmsIllegalArgumentException; +import org.opencms.main.OpenCms; +import org.opencms.util.CmsStringUtil; + /** - * Bean class for message information.
+ * Bean class for message information. + *
* - * @author Michael Moossen + * @author Michael Moossen * - * @version $Revision: 1.14 $ + * @version $Revision: 1.14 $ * - * @since 6.0.0 + * @since 6.0.0 */ public class CmsMessageInfo { - /** Cc header string. */ - private String m_cc = ""; + /** Cc header string. */ + private String m_cc = ""; - /** From header string. */ - private String m_from = ""; + /** From header string. */ + private String m_from = ""; - /** Message string. */ - private String m_msg = ""; + /** Message string. */ + private String m_msg = ""; - /** Subject header string. */ - private String m_subject = ""; - - /** To header string. */ - private String m_to = ""; - - /** - * Default Constructor.
- */ - public CmsMessageInfo() { - - // noop - } - - /** - * Returns the cc string.
- * - * @return the cc string - */ - public String getCc() { - - return m_cc; - } - - /** - * Returns the from string.
- * - * @return the from string - */ - public String getFrom() { - - return m_from; - } - - /** - * Returns the message string.
- * - * @return the message string - */ - public String getMsg() { - - return m_msg; - } - - /** - * Returns the subject string.
- * - * @return the subject string - */ - public String getSubject() { - - return m_subject; - } - - /** - * Returns the to string.
- * - * @return the to string - */ - public String getTo() { - - return m_to; - } - - /** - * Sends the given message to the given addresses.
- * - * @param cms the cms context - * - * @throws Exception if something goes wrong - */ - public void sendEmail(CmsObject cms) throws Exception { - - // create a plain text email - CmsSimpleMail theMail = new CmsSimpleMail(); - theMail.setCharset(cms.getRequestContext().getEncoding()); - theMail.setFrom(cms.getRequestContext().currentUser().getEmail(), getFrom()); - theMail.setTo(createInternetAddresses(getTo())); - if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCc())) { - theMail.setCc(createInternetAddresses(getCc())); - } - theMail.setSubject("[" + OpenCms.getSystemInfo().getServerName() + "] " + getSubject()); - theMail.setMsg(getMsg()); - // send the mail - try { - theMail.send(); - } catch (SendFailedException sf) { - // don't try to resend to successful Addresses: construct a new string with all unsent - StringBuffer newTo = new StringBuffer(); - Address[] unsent = sf.getValidUnsentAddresses(); - if (unsent != null) { - for (int i = unsent.length - 1; i >= 0; i--) { - newTo.append(unsent[i].toString()).append(';'); - } - } - if (unsent != null) { - unsent = sf.getInvalidAddresses(); - for (int i = unsent.length - 1; i >= 0; i--) { - newTo.append(unsent[i].toString()).append(';'); - } - } - - setTo(newTo.toString()); - // use the message of the internal cause: this is a localizes CmsRuntimeException - throw (Exception)sf.getCause(); - - } - } - - /** - * Sets the cc string.
- * - * @param cc the cc string - */ - public void setCc(String cc) { - - if (!CmsStringUtil.isEmptyOrWhitespaceOnly(cc)) { - m_cc = cc; - } - } - - /** - * Sets the from string.
- * - * @param from the from string - */ - public void setFrom(String from) { - - checkString(from); - m_from = from; - } - - /** - * Sets the message string.
- * - * @param msg the message string - */ - public void setMsg(String msg) { - - checkString(msg); - m_msg = msg; - } - - /** - * Sets the subject string.
- * - * @param subject the subject string - */ - public void setSubject(String subject) { - - checkString(subject); - m_subject = subject; - } - - /** - * Sets the to string.
- * - * This has to be a ';' separated string of email-addresses.
- * - * - * @param to the to string - */ - public void setTo(String to) { - - m_to = to; - } - - /** - * Throws a runtime exception if the string is null, empty or contains JavaScript.
- * - * @param string the string to check - */ - private void checkString(String string) { - - if (CmsStringUtil.isEmptyOrWhitespaceOnly(string)) { - throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_EMPTY_STRING_0)); - } - } - - /** - * Creates a list of internet addresses (email) from a semicolon separated String.
- * - * @param mailAddresses a semicolon separated String with email addresses - * @return list of internet addresses (email) - * @throws AddressException if an email address is not correct - */ - private List createInternetAddresses(String mailAddresses) throws AddressException { - - if (CmsStringUtil.isNotEmpty(mailAddresses)) { - // at least one email address is present, generate list - StringTokenizer T = new StringTokenizer(mailAddresses, ";"); - List addresses = new ArrayList(T.countTokens()); - while (T.hasMoreTokens()) { - InternetAddress address = new InternetAddress(T.nextToken().trim()); - addresses.add(address); - } - return addresses; - } else { - // no address given, return empty list - return Collections.EMPTY_LIST; - } - } + /** Subject header string. */ + private String m_subject = ""; + + /** To header string. */ + private String m_to = ""; + + /** + * Default Constructor. + *
+ */ + public CmsMessageInfo() { + + // noop + } + + /** + * Returns the cc string. + *
+ * + * @return the cc string + */ + public String getCc() { + + return m_cc; + } + + /** + * Returns the from string. + *
+ * + * @return the from string + */ + public String getFrom() { + + return m_from; + } + + /** + * Returns the message string. + *
+ * + * @return the message string + */ + public String getMsg() { + + return m_msg; + } + + /** + * Returns the subject string. + *
+ * + * @return the subject string + */ + public String getSubject() { + + return m_subject; + } + + /** + * Returns the to string. + *
+ * + * @return the to string + */ + public String getTo() { + + return m_to; + } + + /** + * Sends the given message to the given addresses. + *
+ * + * @param cms + * the cms context + * + * @throws Exception + * if something goes wrong + */ + public void sendEmail(CmsObject cms) throws Exception { + + // create a plain text email + CmsSimpleMail theMail = new CmsSimpleMail(); + theMail.setCharset(cms.getRequestContext().getEncoding()); + theMail.setFrom(cms.getRequestContext().currentUser().getEmail(), + getFrom()); + theMail.setTo(createInternetAddresses(getTo())); + if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCc())) { + theMail.setCc(createInternetAddresses(getCc())); + } + theMail.setSubject("[" + OpenCms.getSystemInfo().getServerName() + "] " + + getSubject()); + theMail.setMsg(getMsg()); + // send the mail + try { + theMail.send(); + } catch (EmailException e) { + // check if original Exception is of type SendFailedException which + // should have been thrown by javax.mail.Transport.send() + if (e.getCause() instanceof SendFailedException) { + SendFailedException sfe = (SendFailedException)e.getCause(); + // don't try to resend to successful Addresses: construct a new + // string with all unsent + StringBuffer newTo = new StringBuffer(); + Address[] unsent = sfe.getValidUnsentAddresses(); + if (unsent != null) { + for (int i = unsent.length - 1; i >= 0; i--) { + newTo.append(unsent[i].toString()).append(';'); + } + } + if (unsent != null) { + unsent = sfe.getInvalidAddresses(); + for (int i = unsent.length - 1; i >= 0; i--) { + newTo.append(unsent[i].toString()).append(';'); + } + } + + setTo(newTo.toString()); + // use the message of the internal cause: this is a localizes + // CmsRuntimeException + throw (Exception) sfe.getCause(); + } + } + } + + /** + * Sets the cc string. + *
+ * + * @param cc + * the cc string + */ + public void setCc(String cc) { + + if (!CmsStringUtil.isEmptyOrWhitespaceOnly(cc)) { + m_cc = cc; + } + } + + /** + * Sets the from string. + *
+ * + * @param from + * the from string + */ + public void setFrom(String from) { + + checkString(from); + m_from = from; + } + + /** + * Sets the message string. + *
+ * + * @param msg + * the message string + */ + public void setMsg(String msg) { + + checkString(msg); + m_msg = msg; + } + + /** + * Sets the subject string. + *
+ * + * @param subject + * the subject string + */ + public void setSubject(String subject) { + + checkString(subject); + m_subject = subject; + } + + /** + * Sets the to string. + *
+ * + * This has to be a ';' separated string of email-addresses. + *
+ * + * + * @param to + * the to string + */ + public void setTo(String to) { + + m_to = to; + } + + /** + * Throws a runtime exception if the string is null, empty or contains + * JavaScript. + *
+ * + * @param string + * the string to check + */ + private void checkString(String string) { + + if (CmsStringUtil.isEmptyOrWhitespaceOnly(string)) { + throw new CmsIllegalArgumentException(Messages.get().container( + Messages.ERR_EMPTY_STRING_0)); + } + } + + /** + * Creates a list of internet addresses (email) from a semicolon separated + * String. + *
+ *
+ * @param mailAddresses
+ * a semicolon separated String with email addresses
+ * @return list of internet addresses (email)
+ * @throws AddressException
+ * if an email address is not correct
+ */
+ private List createInternetAddresses(String mailAddresses)
+ throws AddressException {
+
+ if (CmsStringUtil.isNotEmpty(mailAddresses)) {
+ // at least one email address is present, generate list
+ StringTokenizer T = new StringTokenizer(mailAddresses, ";");
+ List addresses = new ArrayList(T.countTokens());
+ while (T.hasMoreTokens()) {
+ InternetAddress address = new InternetAddress(T.nextToken()
+ .trim());
+ addresses.add(address);
+ }
+ return addresses;
+ } else {
+ // no address given, return empty list
+ return Collections.EMPTY_LIST;
+ }
+ }
}
Index: src/org/opencms/scheduler/CmsSchedulerThreadPool.java
===================================================================
RCS file: /usr/local/cvs/opencms/src/org/opencms/scheduler/CmsSchedulerThreadPool.java,v
retrieving revision 1.15
diff -u -r1.15 CmsSchedulerThreadPool.java
--- src/org/opencms/scheduler/CmsSchedulerThreadPool.java 27 Feb 2008 12:05:33 -0000 1.15
+++ src/org/opencms/scheduler/CmsSchedulerThreadPool.java 10 Sep 2008 12:53:36 -0000
@@ -149,10 +149,20 @@
m_maxThreadCount = maxThreadCount;
m_threadPriority = threadPriority;
}
+
+ /**
+ *
+ * @see org.quartz.spi.ThreadPool#blockForAvailableThreads()
+ */
+ public int blockForAvailableThreads() {
+ // Waiting will be done in runInThread so we always return 1
+ return 1;
+ }
+
/**
- * @see org.quartz.spi.ThreadPool#getPoolSize()
- */
+ * @see org.quartz.spi.ThreadPool#getPoolSize()
+ */
public int getPoolSize() {
return m_currentThreadCount;
Index: src/org/opencms/configuration/CmsSetNextRule.java
===================================================================
RCS file: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsSetNextRule.java,v
retrieving revision 1.11
diff -u -r1.11 CmsSetNextRule.java
--- src/org/opencms/configuration/CmsSetNextRule.java 27 Feb 2008 12:05:48 -0000 1.11
+++ src/org/opencms/configuration/CmsSetNextRule.java 10 Sep 2008 12:53:35 -0000
@@ -61,28 +61,35 @@
import org.xml.sax.Attributes;
/**
- * Rule implementation that invokes a method on the (top-1) (parent) object,
- * passing as implicit first argument of type {@link org.opencms.file.CmsObject}
- * and as a further argument the top stack instance.
+ * Rule implementation that invokes a method on the (top-1) (parent) object,
+ * passing as implicit first argument of type
+ * {@link org.opencms.file.CmsObject}
and as a further argument
+ * the top stack instance.
+ *
*
- * If no subsequent CallParamRule
are matched for CmsObject
- * which is the case in the OpenCms usage the first argument CmsObject
- * will be null at method invocation time.
-
- * This is an alternative for {@link org.apache.commons.digester.SetNextRule}
- * if a parent to child-property configuration has been done but the setter for that
- * property requires additional arguments that are only available at real runtime
- * of the application.
+ * If no subsequent CallParamRule
are matched for
+ * CmsObject
which is the case in the OpenCms usage the first
+ * argument CmsObject
will be null at method invocation time.
+ *
*
- * The top stack element (child) that has to be set is matched against the constructor
- * given {@link java.lang.Class}[]
: It is used as argument on the position
- * where the Class[]
has an instance of the same type as it's own Class
.
+ * This is an alternative for
+ * {@link org.apache.commons.digester.SetNextRule}
if a parent to
+ * child-property configuration has been done but the setter for that property
+ * requires additional arguments that are only available at real runtime of the
+ * application.
+ *
+ *
+ * The top stack element (child) that has to be set is matched against the
+ * constructor given {@link java.lang.Class}[]
: It is used as
+ * argument on the position where the Class[]
has an instance of
+ * the same type as it's own Class
.
+ *
*
* @see org.apache.commons.digester.CallMethodRule
* @see org.apache.commons.digester.SetNextRule
*
- * @author Craig McClanahan
- * @author Achim Westermann
+ * @author Craig McClanahan
+ * @author Achim Westermann
*
* @version $Revision: 1.11 $
*
@@ -91,364 +98,428 @@
public class CmsSetNextRule extends Rule {
- /** The log object of this class. */
- private static final Log LOG = CmsLog.getLog(CmsSetNextRule.class);
- /**
- * The body text collected from this element.
- */
- protected String m_bodyText;
-
- /**
- * The method name to call on the parent object.
- */
- protected String m_methodName;
-
- /**
- * The number of parameters to collect from MethodParam
rules.
- * If this value is zero, a single parameter will be collected from the
- * body of this element.
- */
- protected int m_paramCount;
-
- /**
- * The parameter types of the parameters to be collected.
- */
- protected Class[] m_paramTypes;
-
- /**
- * Should MethodUtils.invokeExactMethod
be used for reflection.
- */
- protected boolean m_useExactMatch;
-
- /**
- * location of the target object for the call, relative to the
- * top of the digester object stack. The default value of zero
- * means the target object is the one on top of the stack.
- */
- private int m_targetOffset;
-
- /**
- * Construct a "call method" rule with the specified method name.
- *
- *
- * The 1st argument of the method will be of type {@link CmsObject}
.
- * It's value will remain null (except subsequent
- * {@link org.apache.commons.digester.CallParamRule}
would put a value
- * which currently is impossible at initialization time within OpenCms).
- *
- * The 2nd argument will be the top-stack element at digestion time.
- * That instance has to be of the same type as the clazz
argument to succeed.
- * - * - * @param methodName Method name of the parent method to call - * @param clazz The class of the top-stack element (child) that will be present at digestion-time - */ - public CmsSetNextRule(String methodName, Class clazz) { - - this(methodName, new Class[] {clazz}); - } - - /** - * Construct a "call method" rule with the specified method name - * and additional parameters.
- *
- *
- * The 1st argument of the method will be of type {@link CmsObject}
.
- * It's value will remain null (except subsequent
- * {@link org.apache.commons.digester.CallParamRule}
would put a value
- * which currently is impossible at initialization time within OpenCms).
- *
- * The further arguments will be filled by the subsequent {@link org.apache.commons.digester.CallParamRule}
- * matches. If the first Class
in the given array matches the top stack element
- * (child) that value will be used. If at digestion time no parameters are found for the given
- * types their values for invocation of the method remain null.
- * - * - * @param methodName Method name of the parent method to call - * @param clazzes an array with all parameter types for the method to invoke at digestion time - */ - public CmsSetNextRule(String methodName, Class[] clazzes) { - - m_targetOffset = 0; - m_methodName = methodName; - m_paramCount = clazzes.length + 1; - m_paramTypes = new Class[m_paramCount]; - m_paramTypes[0] = CmsObject.class; - System.arraycopy(clazzes, 0, m_paramTypes, 1, clazzes.length); - } - - /** - * Process the start of this element. - * - * @param attributes The attribute list for this element - * @param namespace the namespace URI of the matching element, or an empty string if the parser is not namespace - * aware or the element has no namespace - * @param name the local name if the parser is namespace aware, or just the element name otherwise - * @throws Exception if something goes wrong - */ - public void begin(java.lang.String namespace, java.lang.String name, Attributes attributes) throws Exception { - - // not now: 6.0.0 - //digester.setLogger(CmsLog.getLog(digester.getClass())); - - // Push an array to capture the parameter values if necessary - if (m_paramCount > 0) { - Object[] parameters = new Object[m_paramCount]; - for (int i = 0; i < parameters.length; i++) { - parameters[i] = null; - } - digester.pushParams(parameters); - } - } - - /** - * Process the body text of this element.
- * - * @param bodyText The body text of this element - * @param namespace the namespace URI of the matching element, or an empty string if the parser is not namespace - * aware or the element has no namespace - * @param name the local name if the parser is namespace aware, or just the element name otherwise - * @throws Exception if something goes wrong - */ - public void body(java.lang.String namespace, java.lang.String name, String bodyText) throws Exception { - - if (m_paramCount == 0) { - m_bodyText = bodyText.trim(); - } - } - - /** - * Process the end of this element.
- * - * @param namespace the namespace URI of the matching element, or an empty string if the parser is not namespace - * aware or the element has no namespace - * @param name the local name if the parser is namespace aware, or just the element name otherwise - * @throws Exception if something goes wrong - */ - public void end(java.lang.String namespace, java.lang.String name) throws Exception { - - // Determine the target object for the method call: the parent object - Object parent = digester.peek(1); - Object child = digester.peek(0); - - // Retrieve or construct the parameter values array - Object[] parameters = null; - if (m_paramCount > 0) { - parameters = (Object[])digester.popParams(); - if (LOG.isTraceEnabled()) { - for (int i = 0, size = parameters.length; i < size; i++) { - LOG.trace("[SetNextRuleWithParams](" + i + ")" + parameters[i]); - } - } - - // In the case where the target method takes a single parameter - // and that parameter does not exist (the CallParamRule never - // executed or the CallParamRule was intended to set the parameter - // from an attribute but the attribute wasn't present etc) then - // skip the method call. - // - // This is useful when a class has a "default" value that should - // only be overridden if data is present in the XML. I don't - // know why this should only apply to methods taking *one* - // parameter, but it always has been so we can't change it now. - if ((m_paramCount == 1) && (parameters[0] == null)) { - return; - } - - } else if (m_paramTypes.length != 0) { - // Having paramCount == 0 and paramTypes.length == 1 indicates - // that we have the special case where the target method has one - // parameter being the body text of the current element. - - // There is no body text included in the source XML file, - // so skip the method call - if (m_bodyText == null) { - return; - } - - parameters = new Object[1]; - parameters[0] = m_bodyText; - if (m_paramTypes.length == 0) { - m_paramTypes = new Class[1]; - m_paramTypes[0] = String.class; - } - - } else { - // When paramCount is zero and paramTypes.length is zero it - // means that we truly are calling a method with no parameters. - // Nothing special needs to be done here. - parameters = new Object[0]; - } - - // Construct the parameter values array we will need - // We only do the conversion if the param value is a String and - // the specified paramType is not String. - Object[] paramValues = new Object[m_paramTypes.length]; - - Class propertyClass = child.getClass(); - for (int i = 0; i < m_paramTypes.length; i++) { - if (m_paramTypes[i] == propertyClass) { - // implant the original child to set if Class matches: - paramValues[i] = child; - } else if ((parameters[i] == null) - || ((parameters[i] instanceof String) && !String.class.isAssignableFrom(m_paramTypes[i]))) { - // convert nulls and convert stringy parameters - // for non-stringy param types - paramValues[i] = ConvertUtils.convert((String)parameters[i], m_paramTypes[i]); - } else { - paramValues[i] = parameters[i]; - } - } - - if (parent == null) { - StringBuffer sb = new StringBuffer(); - sb.append("[SetNextRuleWithParams]{"); - sb.append(digester.getMatch()); - sb.append("} Call target is null ("); - sb.append("targetOffset="); - sb.append(m_targetOffset); - sb.append(",stackdepth="); - sb.append(digester.getCount()); - sb.append(")"); - throw new org.xml.sax.SAXException(sb.toString()); - } - - // Invoke the required method on the top object - if (LOG.isDebugEnabled()) { - StringBuffer sb = new StringBuffer("[SetNextRuleWithParams]{"); - sb.append(digester.getMatch()); - sb.append("} Call "); - sb.append(parent.getClass().getName()); - sb.append("."); - sb.append(m_methodName); - sb.append("("); - for (int i = 0; i < paramValues.length; i++) { - if (i > 0) { - sb.append(","); - } - if (paramValues[i] == null) { - sb.append("null"); - } else { - sb.append(paramValues[i].toString()); - } - sb.append("/"); - if (m_paramTypes[i] == null) { - sb.append("null"); - } else { - sb.append(m_paramTypes[i].getName()); - } - } - sb.append(")"); - LOG.debug(sb.toString()); - } - - Object result = null; - if (m_useExactMatch) { - // invoke using exact match - result = MethodUtils.invokeExactMethod(parent, m_methodName, paramValues, m_paramTypes); - - } else { - // invoke using fuzzier match - result = MethodUtils.invokeMethod(parent, m_methodName, paramValues, m_paramTypes); - } - - processMethodCallResult(result); - } - - /** - * Clean up after parsing is complete.
- *
- * @param namespace the namespace URI of the matching element, or an empty string if the parser is not namespace
- * aware or the element has no namespace
- * @param name the local name if the parser is namespace aware, or just the element name otherwise
- * @throws Exception if something goes wrong
- */
- public void finish(String namespace, String name) throws Exception {
-
- String dummy = name;
- dummy = namespace;
- dummy = null;
- m_bodyText = dummy;
- }
-
- /**
- * Returns true if MethodUtils.invokeExactMethod
- * shall be used for the reflection.
- *
- * @return true if MethodUtils.invokeExactMethod
- * shall be used for the reflection.
- */
- public boolean getUseExactMatch() {
-
- return m_useExactMatch;
- }
-
- /**
- * Set the associated digester.
- * - * The digester gets assigned to use the OpenCms conform logging - * - * If needed, this class loads the parameter classes from their names.
- *
- * @param aDigester the associated digester to set
- */
- public void setDigester(Digester aDigester) {
-
- aDigester.setLogger(CmsLog.getLog(aDigester.getClass()));
- // call superclass
- super.setDigester(aDigester);
- }
-
- /**
- * Set the value to use for MethodUtils.invokeExactMethod
- * to use.
- *
- * @param useExactMatch the value to use for MethodUtils.invokeExactMethod
- * to use
- */
- public void setUseExactMatch(boolean useExactMatch) {
-
- m_useExactMatch = useExactMatch;
- }
-
- /**
- * Returns a printable version of this Rule.
- *
- * @return a printable version of this Rule
- */
- public String toString() {
-
- StringBuffer sb = new StringBuffer("CallMethodRule[");
- sb.append("methodName=");
- sb.append(m_methodName);
- sb.append(", paramCount=");
- sb.append(m_paramCount);
- sb.append(", paramTypes={");
- if (m_paramTypes != null) {
- for (int i = 0; i < m_paramTypes.length; i++) {
- if (i > 0) {
- sb.append(", ");
- }
- sb.append(m_paramTypes[i].getName());
- }
- }
- sb.append("}");
- sb.append("]");
- return (sb.toString());
-
- }
-
- /**
- * Subclasses may override this method to perform additional processing of the
- * invoked method's result.
- *
- * @param result the Object returned by the method invoked, possibly null
- */
- protected void processMethodCallResult(Object result) {
-
- // do nothing but to fool checkstyle
- if (result != null) {
- // nop
- }
- }
+ /** The log object of this class. */
+ private static final Log LOG = CmsLog.getLog(CmsSetNextRule.class);
+ /**
+ * The body text collected from this element.
+ */
+ protected String m_bodyText;
+
+ /**
+ * The method name to call on the parent object.
+ */
+ protected String m_methodName;
+
+ /**
+ * The number of parameters to collect from MethodParam
+ * rules. If this value is zero, a single parameter will be collected from
+ * the body of this element.
+ */
+ protected int m_paramCount;
+
+ /**
+ * The parameter types of the parameters to be collected.
+ */
+ protected Class[] m_paramTypes;
+
+ /**
+ * Should MethodUtils.invokeExactMethod
be used for
+ * reflection.
+ */
+ protected boolean m_useExactMatch;
+
+ /**
+ * location of the target object for the call, relative to the top of the
+ * digester object stack. The default value of zero means the target object
+ * is the one on top of the stack.
+ */
+ private int m_targetOffset;
+
+ /**
+ * Construct a "call method" rule with the specified method name.
+ *
+ *
+ *
+ * The 1st argument of the method will be of type
+ * {@link CmsObject}
. It's value will remain null (except
+ * subsequent {@link org.apache.commons.digester.CallParamRule}
+ * would put a value which currently is impossible at initialization time
+ * within OpenCms).
+ *
+ *
+ * The 2nd argument will be the top-stack element at digestion
+ * time. That instance has to be of the same type as the clazz
+ * argument to succeed.
+ *
+ * + * + * @param methodName + * Method name of the parent method to call + * @param clazz + * The class of the top-stack element (child) that will be + * present at digestion-time + */ + public CmsSetNextRule(String methodName, Class clazz) { + + this(methodName, new Class[] { clazz }); + } + + /** + * Construct a "call method" rule with the specified method name and + * additional parameters. + *
+ *
+ *
+ * The 1st argument of the method will be of type
+ * {@link CmsObject}
. It's value will remain null (except
+ * subsequent {@link org.apache.commons.digester.CallParamRule}
+ * would put a value which currently is impossible at initialization time
+ * within OpenCms).
+ *
+ *
+ * The further arguments will be filled by the subsequent
+ * {@link org.apache.commons.digester.CallParamRule}
matches.
+ * If the first Class
in the given array matches the top
+ * stack element (child) that value will be used. If at digestion time no
+ * parameters are found for the given types their values for invocation of
+ * the method remain null.
+ *
+ * + * + * @param methodName + * Method name of the parent method to call + * @param clazzes + * an array with all parameter types for the method to invoke at + * digestion time + */ + public CmsSetNextRule(String methodName, Class[] clazzes) { + + m_targetOffset = 0; + m_methodName = methodName; + m_paramCount = clazzes.length + 1; + m_paramTypes = new Class[m_paramCount]; + m_paramTypes[0] = CmsObject.class; + System.arraycopy(clazzes, 0, m_paramTypes, 1, clazzes.length); + } + + /** + * Process the start of this element. + * + * @param attributes + * The attribute list for this element + * @param namespace + * the namespace URI of the matching element, or an empty string + * if the parser is not namespace aware or the element has no + * namespace + * @param name + * the local name if the parser is namespace aware, or just the + * element name otherwise + * @throws Exception + * if something goes wrong + */ + public void begin(java.lang.String namespace, java.lang.String name, + Attributes attributes) throws Exception { + + // not now: 6.0.0 + // digester.setLogger(CmsLog.getLog(digester.getClass())); + + // Push an array to capture the parameter values if necessary + if (m_paramCount > 0) { + Object[] parameters = new Object[m_paramCount]; + for (int i = 0; i < parameters.length; i++) { + parameters[i] = null; + } + digester.pushParams(parameters); + } + } + + /** + * Process the body text of this element. + *
+ * + * @param bodyText + * The body text of this element + * @param namespace + * the namespace URI of the matching element, or an empty string + * if the parser is not namespace aware or the element has no + * namespace + * @param name + * the local name if the parser is namespace aware, or just the + * element name otherwise + * @throws Exception + * if something goes wrong + */ + public void body(java.lang.String namespace, java.lang.String name, + String bodyText) throws Exception { + + if (m_paramCount == 0) { + m_bodyText = bodyText.trim(); + } + } + + /** + * Process the end of this element. + *
+ * + * @param namespace + * the namespace URI of the matching element, or an empty string + * if the parser is not namespace aware or the element has no + * namespace + * @param name + * the local name if the parser is namespace aware, or just the + * element name otherwise + * @throws Exception + * if something goes wrong + */ + public void end(java.lang.String namespace, java.lang.String name) + throws Exception { + + // Determine the target object for the method call: the parent object + Object parent = digester.peek(1); + Object child = digester.peek(0); + + // Retrieve or construct the parameter values array + Object[] parameters = null; + if (m_paramCount > 0) { + parameters = (Object[]) digester.popParams(); + if (LOG.isTraceEnabled()) { + for (int i = 0, size = parameters.length; i < size; i++) { + LOG.trace("[SetNextRuleWithParams](" + i + ")" + + parameters[i]); + } + } + + // In the case where the target method takes a single parameter + // and that parameter does not exist (the CallParamRule never + // executed or the CallParamRule was intended to set the parameter + // from an attribute but the attribute wasn't present etc) then + // skip the method call. + // + // This is useful when a class has a "default" value that should + // only be overridden if data is present in the XML. I don't + // know why this should only apply to methods taking *one* + // parameter, but it always has been so we can't change it now. + if ((m_paramCount == 1) && (parameters[0] == null)) { + return; + } + + } else if (m_paramTypes.length != 0) { + // Having paramCount == 0 and paramTypes.length == 1 indicates + // that we have the special case where the target method has one + // parameter being the body text of the current element. + + // There is no body text included in the source XML file, + // so skip the method call + if (m_bodyText == null) { + return; + } + + parameters = new Object[1]; + parameters[0] = m_bodyText; + if (m_paramTypes.length == 0) { + m_paramTypes = new Class[1]; + m_paramTypes[0] = String.class; + } + + } else { + // When paramCount is zero and paramTypes.length is zero it + // means that we truly are calling a method with no parameters. + // Nothing special needs to be done here. + parameters = new Object[0]; + } + + // Construct the parameter values array we will need + // We only do the conversion if the param value is a String and + // the specified paramType is not String. + Object[] paramValues = new Object[m_paramTypes.length]; + + Class propertyClass = child.getClass(); + for (int i = 0; i < m_paramTypes.length; i++) { + if (m_paramTypes[i] == propertyClass) { + // implant the original child to set if Class matches: + paramValues[i] = child; + } else if ((parameters[i] == null) + || ((parameters[i] instanceof String) && !String.class + .isAssignableFrom(m_paramTypes[i]))) { + // convert nulls and convert stringy parameters + // for non-stringy param types + if (parameters[i] == null) { + paramValues[i] = null; + } else { + paramValues[i] = ConvertUtils.convert( + (String) parameters[i], m_paramTypes[i]); + } + + } else { + paramValues[i] = parameters[i]; + } + } + + if (parent == null) { + StringBuffer sb = new StringBuffer(); + sb.append("[SetNextRuleWithParams]{"); + sb.append(digester.getMatch()); + sb.append("} Call target is null ("); + sb.append("targetOffset="); + sb.append(m_targetOffset); + sb.append(",stackdepth="); + sb.append(digester.getCount()); + sb.append(")"); + throw new org.xml.sax.SAXException(sb.toString()); + } + + // Invoke the required method on the top object + if (LOG.isDebugEnabled()) { + StringBuffer sb = new StringBuffer("[SetNextRuleWithParams]{"); + sb.append(digester.getMatch()); + sb.append("} Call "); + sb.append(parent.getClass().getName()); + sb.append("."); + sb.append(m_methodName); + sb.append("("); + for (int i = 0; i < paramValues.length; i++) { + if (i > 0) { + sb.append(","); + } + if (paramValues[i] == null) { + sb.append("null"); + } else { + sb.append(paramValues[i].toString()); + } + sb.append("/"); + if (m_paramTypes[i] == null) { + sb.append("null"); + } else { + sb.append(m_paramTypes[i].getName()); + } + } + sb.append(")"); + LOG.debug(sb.toString()); + } + + Object result = null; + if (m_useExactMatch) { + // invoke using exact match + result = MethodUtils.invokeExactMethod(parent, m_methodName, + paramValues, m_paramTypes); + + } else { + // invoke using fuzzier match + result = MethodUtils.invokeMethod(parent, m_methodName, + paramValues, m_paramTypes); + } + + processMethodCallResult(result); + } + + /** + * Clean up after parsing is complete. + *
+ *
+ * @param namespace
+ * the namespace URI of the matching element, or an empty string
+ * if the parser is not namespace aware or the element has no
+ * namespace
+ * @param name
+ * the local name if the parser is namespace aware, or just the
+ * element name otherwise
+ * @throws Exception
+ * if something goes wrong
+ */
+ public void finish(String namespace, String name) throws Exception {
+
+ String dummy = name;
+ dummy = namespace;
+ dummy = null;
+ m_bodyText = dummy;
+ }
+
+ /**
+ * Returns true if MethodUtils.invokeExactMethod
shall be
+ * used for the reflection.
+ *
+ *
+ * @return true if MethodUtils.invokeExactMethod
shall be
+ * used for the reflection.
+ */
+ public boolean getUseExactMatch() {
+
+ return m_useExactMatch;
+ }
+
+ /**
+ * Set the associated digester.
+ *
+ * + * The digester gets assigned to use the OpenCms conform logging + * + * If needed, this class loads the parameter classes from their names. + *
+ *
+ * @param aDigester
+ * the associated digester to set
+ */
+ public void setDigester(Digester aDigester) {
+
+ aDigester.setLogger(CmsLog.getLog(aDigester.getClass()));
+ // call superclass
+ super.setDigester(aDigester);
+ }
+
+ /**
+ * Set the value to use for MethodUtils.invokeExactMethod
to
+ * use.
+ *
+ *
+ * @param useExactMatch
+ * the value to use for
+ * MethodUtils.invokeExactMethod
to use
+ */
+ public void setUseExactMatch(boolean useExactMatch) {
+
+ m_useExactMatch = useExactMatch;
+ }
+
+ /**
+ * Returns a printable version of this Rule.
+ *
+ * + * @return a printable version of this Rule + */ + public String toString() { + + StringBuffer sb = new StringBuffer("CallMethodRule["); + sb.append("methodName="); + sb.append(m_methodName); + sb.append(", paramCount="); + sb.append(m_paramCount); + sb.append(", paramTypes={"); + if (m_paramTypes != null) { + for (int i = 0; i < m_paramTypes.length; i++) { + if (i > 0) { + sb.append(", "); + } + sb.append(m_paramTypes[i].getName()); + } + } + sb.append("}"); + sb.append("]"); + return (sb.toString()); + + } + + /** + * Subclasses may override this method to perform additional processing of + * the invoked method's result. + * + * @param result + * the Object returned by the method invoked, possibly null + */ + protected void processMethodCallResult(Object result) { + + // do nothing but to fool checkstyle + if (result != null) { + // nop + } + } } \ No newline at end of file Index: test/org/opencms/mail/TestCmsMail.java =================================================================== RCS file: test/org/opencms/mail/TestCmsMail.java diff -N test/org/opencms/mail/TestCmsMail.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ test/org/opencms/mail/TestCmsMail.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,200 @@ +/* + * File : $Source: /usr/local/cvs/opencms/test/org/opencms/search/TestCmsSearch.java,v $ + * Date : $Date: 2008-02-27 12:05:27 $ + * Version: $Revision: 1.24 $ + * + * This library is part of OpenCms - + * the Open Source Content Management System + * + * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * For further information about Alkacon Software GmbH, please see the + * company website: http://www.alkacon.com + * + * For further information about OpenCms, please see the + * project website: http://www.opencms.org + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +package org.opencms.mail; + +import javax.mail.Address; +import javax.mail.SendFailedException; +import javax.mail.internet.InternetAddress; + +import junit.extensions.TestSetup; +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.mail.EmailException; +import org.opencms.main.OpenCms; +import org.opencms.test.OpenCmsTestCase; +import org.opencms.test.OpenCmsTestProperties; + +import com.dumbster.smtp.SimpleSmtpServer; + +/** + * Unit test for the cms search indexer.
+ * + * @author Florian Heinisch + * @author Sebastian Himberger + * + * @version $Revision: 1.24 $ + */ +public class TestCmsMail extends OpenCmsTestCase { + + /** + * Port the SMTP server will listen to. Must be greater than 1000, depending + * on the underlying OS. + */ + private static final int SMTP_PORT = 2525; + + /** Name of the index used for testing. */ + public static final String INDEX_OFFLINE = "Offline project (VFS)"; + + /** Name of the search index created using API. */ + public static final String INDEX_TEST = "Test new index"; + + /** + * Default JUnit constructor.
+ * + * @param arg0 JUnit parameters + */ + public TestCmsMail(String arg0) { + + super(arg0); + } + + /** + * Test suite for this test class.
+ * + * @return the test suite + */ + public static Test suite() { + + OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); + + TestSuite suite = new TestSuite(); + suite.setName(TestCmsMail.class.getName()); + + suite.addTest(new TestCmsMail("testCmsSendSimpleMail")); + suite.addTest(new TestCmsMail("testCmsSendHtmlMail")); + suite.addTest(new TestCmsMail("testCmsInvalidMailAddress")); + TestSetup wrapper = new TestSetup(suite) { + // SMTP Server running locally (c.f. library dumbster-1.6.jar) + SimpleSmtpServer server; + + protected void setUp() { + + setupOpenCms("simpletest", "/sites/default/"); + // start SMTP server + server = SimpleSmtpServer.start(SMTP_PORT); + + } + + protected void tearDown() { + + removeOpenCms(); + // stop SMTP server + server.stop(); + } + }; + + return wrapper; + } + + /** + * Tests sending plain text mails.
+ * + * @throws Throwable if something goes wrong + */ + public void testCmsSendSimpleMail() throws Throwable { + echo("Trying to send a plain text mail ..."); + + CmsSimpleMail mail = new CmsSimpleMail(); + mail.setMsg("This is only a test mail for sending plain text mails."); + mail.addTo(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault()); + mail.setSubject("OpenCms TestCase Plain Text Mail"); + mail.setSmtpPort(SMTP_PORT); + String messageID = mail.send(); + assertNotNull(messageID); + + echo("Plain text mail was sent successfully."); + } + + /** + * Tests sending plain text mails.
+ * + * @throws Throwable if something goes wrong + */ + public void testCmsSendHtmlMail() throws Throwable { + echo("Trying to send an HTML mail ..."); + + CmsHtmlMail mail = new CmsHtmlMail(); + StringBuilder sb = new StringBuilder("
"); + sb.append("This is only a test mail for sending HTML mails.
"); + sb.append(""); + sb.append("www.opencms.org"); + sb.append(""); + mail.setHtmlMsg(sb.toString()); + mail.addTo(OpenCms.getSystemInfo().getMailSettings().getMailFromDefault()); + mail.setSubject("OpenCms TestCase HTML Mail"); + // SMTP port must be set manually + mail.setSmtpPort(SMTP_PORT); + String messageID = mail.send(); + assertNotNull(messageID); + + echo("HTML mail was sent successfully."); + } + + /** + * Tests sending mails to invalid email address.
+ * + * @throws Throwable if something goes wrong + */ + public void testCmsInvalidMailAddress() { + echo("Trying to send an HTML mail to invalid mail address ..."); + + String invalidMail = "abc@blockmail.de"; + CmsHtmlMail mail = new CmsHtmlMail(); + StringBuilder sb = new StringBuilder("
"); + sb.append("This is only a test mail for sending HTML mails.
"); + sb.append(""); + sb.append("www.opencms.org");
+ sb.append("");
+
+ // EmailException will be caught here to test functionality required by
+ // CmsMessageInfo.java
+ try {
+ mail.setHtmlMsg(sb.toString());
+ mail.addTo(invalidMail);
+ mail.setSubject("OpenCms TestCase HTML Mail");
+ mail.setSmtpPort(SMTP_PORT);
+ String messageID = mail.send();
+ assertNull(messageID);
+ } catch (EmailException e) {
+ // Check if root cause was SendFailedException due to rejected mail by SMTP server
+ assertTrue(e.getCause() instanceof SendFailedException);
+ SendFailedException sfe = (SendFailedException)e.getCause();
+ Address[] invalidAddresses = sfe.getInvalidAddresses();
+ InternetAddress invalidAddress = (InternetAddress)invalidAddresses[0];
+ echo("Invalid address was: " + invalidAddress.getAddress());
+ assertEquals(invalidMail, invalidAddress.getAddress());
+ }
+ }
+}
Index: test/org/opencms/mail/AllTests.java
===================================================================
RCS file: test/org/opencms/mail/AllTests.java
diff -N test/org/opencms/mail/AllTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/org/opencms/mail/AllTests.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,71 @@
+/*
+ * File : $Source: /usr/local/cvs/opencms/test/org/opencms/search/AllTests.java,v $
+ * Date : $Date: 2008-02-27 12:05:27 $
+ * Version: $Revision: 1.17 $
+ *
+ * This library is part of OpenCms -
+ * the Open Source Content Management System
+ *
+ * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * For further information about Alkacon Software GmbH, please see the
+ * company website: http://www.alkacon.com
+ *
+ * For further information about OpenCms, please see the
+ * project website: http://www.opencms.org
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package org.opencms.mail;
+
+import org.opencms.test.OpenCmsTestProperties;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Main test suite for the package {@link org.opencms.search}
.
+ * + * @author Alexander Kandzior + * @version $Revision: 1.17 $ + * + * @since 6.0 + */ +public final class AllTests { + + /** + * Hide constructor to prevent generation of class instances.
+ */ + private AllTests() { + + // empty + } + + /** + * Returns the JUnit test suite for this package.
+ * + * @return the JUnit test suite for this package + */ + public static Test suite() { + + TestSuite suite = new TestSuite("Tests for package " + AllTests.class.getPackage().getName()); + OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH); + //$JUnit-BEGIN$ + suite.addTest(TestCmsMail.suite()); + //$JUnit-END$ + return suite; + } +}