You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by gl...@apache.org on 2002/10/31 06:01:28 UTC
cvs commit: jakarta-taglibs/mailer/xml intro.xml mailer.xml
glenn 2002/10/30 21:01:28
Modified: mailer/examples/conf web.xml
mailer/examples/web mailer.jsp
mailer/src/org/apache/taglibs/mailer AddRecipientTag.java
FromTag.java HeaderTag.java MailTag.java
MessageTag.java ReplyToTag.java SendTag.java
ServerTag.java SetRecipientTag.java SubjectTag.java
mailer/xml intro.xml mailer.xml
Log:
Bumped version up to 1.1 Beta.
Refactored tags to support JSP custom tag pooling for servlet
containers like Tomcat 4.1 with Jasper 2.
Revision Changes Path
1.4 +1 -1 jakarta-taglibs/mailer/examples/conf/web.xml
Index: web.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/examples/conf/web.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- web.xml 22 Oct 2002 02:40:37 -0000 1.3
+++ web.xml 31 Oct 2002 05:01:27 -0000 1.4
@@ -17,7 +17,7 @@
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<taglib>
- <taglib-uri>http://jakarta.apache.org/taglibs/mailer-1.0</taglib-uri>
+ <taglib-uri>http://jakarta.apache.org/taglibs/mailer-1.1</taglib-uri>
<taglib-location>/WEB-INF/taglibs-mailer.tld</taglib-location>
</taglib>
1.8 +1 -1 jakarta-taglibs/mailer/examples/web/mailer.jsp
Index: mailer.jsp
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/examples/web/mailer.jsp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- mailer.jsp 7 Dec 2001 20:05:35 -0000 1.7
+++ mailer.jsp 31 Oct 2002 05:01:27 -0000 1.8
@@ -1,6 +1,6 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
-<%@ taglib uri="http://jakarta.apache.org/taglibs/mailer-1.0" prefix="mt" %>
+<%@ taglib uri="http://jakarta.apache.org/taglibs/mailer-1.1" prefix="mt" %>
<%@ page language="java" %>
<head>
<title>Example JSP using mailer taglib</title>
1.6 +65 -55 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/AddRecipientTag.java
Index: AddRecipientTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/AddRecipientTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AddRecipientTag.java 3 Apr 2002 17:48:36 -0000 1.5
+++ AddRecipientTag.java 31 Oct 2002 05:01:27 -0000 1.6
@@ -103,21 +103,19 @@
/**
* The type of address to add either to, cc, or bcc
*/
- private String type = null;
+ private String type_string = null;
+ private int type = 0;
+
/**
* The address to be added
*/
private String address = null;
- /**
- * The parent tag of this tag
- */
- MailTag myparent = null;
/**
* implementation of the method from the tag interface that tells the JSP
* page what to do at the start of this tag
*
- * @throws JSPException thrown when an error occurs while processing the
+ * @throws JSPTagException thrown when an error occurs while processing the
* body of this method
*
* @return SKIP_BODY int telling the tag handler to not evaluate the body
@@ -127,33 +125,11 @@
*
*/
public final int doStartTag() throws JspException {
- // parent tag must be a MailTag, gives access to methods in parent
- myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
-
- if (myparent == null)
- throw new JspException("addrecipient tag not nested within mail tag");
- // Make sure type is set..either "to", "cc", or "bcc"
- if ((type != null) && (type.equalsIgnoreCase("to") ||
- type.equalsIgnoreCase("cc") || type.equalsIgnoreCase("bcc"))) {
-
- if (address != null) {
- // Try to see if the address attribute was used.
- if (type.equalsIgnoreCase("to"))
- // set to in the parent tag
- myparent.addTo(address);
- if (type.equalsIgnoreCase("cc"))
- // set cc in the parent tag
- myparent.addCc(address);
- if (type.equalsIgnoreCase("bcc"))
- // set bcc in the parent tag
- myparent.addBcc(address);
- address = null; // reset address
- return SKIP_BODY;
- } else
- return EVAL_BODY_TAG;
- } else
- throw new JspException("The type attribute is not set. " +
- " Specify either \"to\", \"cc\", or \"bcc\".");
+ if (address != null && address.length() > 0 ) {
+ addToParent(address);
+ return SKIP_BODY;
+ }
+ return EVAL_BODY_TAG;
}
@@ -169,23 +145,18 @@
*
*/
public final int doAfterBody() throws JspException {
- if ((address = bodyContent.getString()) != null) {
- // Try to see if the body was used for the address.
- if (type.equalsIgnoreCase("to"))
- // set to in the parent tag
- myparent.addTo(address);
- if (type.equalsIgnoreCase("cc"))
- // set cc in the parent tag
- myparent.addCc(address);
- if (type.equalsIgnoreCase("bcc"))
- // set bcc in the parent tag
- myparent.addBcc(address);
- address = null; // reset address so tag can be reused
- return SKIP_BODY;
- } else
- throw new JspException("Address was not found. set " +
+ BodyContent body = getBodyContent();
+ String addr = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (addr != null && addr.length() > 0 ) {
+ addToParent(addr);
+ return SKIP_BODY;
+ } else {
+ throw new JspException("addrecpient tag could not find an email address. set " +
" the address attribute, or place the address in" +
" the body of the tag.");
+ }
}
/**
@@ -193,10 +164,19 @@
*
* @param type string that is the type of the address either
* "to", "cc", or "bcc".
- *
*/
- public final void setType(String type) {
- this.type = type.trim();
+ public final void setType(String type) throws JspTagException {
+ this.type_string = type.trim();
+ if (type_string.equalsIgnoreCase(MailTag.TO_ADDRESS_STRING)) {
+ this.type = MailTag.TO_ADDRESS;
+ } else if (type_string.equalsIgnoreCase(MailTag.CC_ADDRESS_STRING)) {
+ this.type = MailTag.CC_ADDRESS;
+ } else if (type_string.equalsIgnoreCase(MailTag.BCC_ADDRESS_STRING)) {
+ this.type = MailTag.BCC_ADDRESS;
+ } else {
+ throw new JspTagException
+ ("addrecipient tag type attribute must be \"to\", \"cc\", or \"bcc\"");
+ }
}
/**
@@ -204,9 +184,39 @@
*
* @param address string that is an address to be added to the
* "to", "cc", or "bcc" lists of addresses.
- *
*/
public final void setAddress(String address) {
this.address = address.trim();
}
+
+ private void addToParent(String addr) throws JspTagException {
+ // parent tag must be a MailTag, gives access to methods in parent
+ MailTag myparent =
+ (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass
+ (this, MailTag.class);
+
+ if (myparent == null) {
+ throw new JspTagException("addrecipient tag not nested within mail tag");
+ }
+
+ // Make sure type is set..either "to", "cc", or "bcc"
+ switch (type) {
+ case MailTag.TO_ADDRESS:
+ // set to in the parent tag
+ myparent.addTo(addr);
+ break;
+ case MailTag.CC_ADDRESS:
+ // set cc in the parent tag
+ myparent.addCc(addr);
+ break;
+ case MailTag.BCC_ADDRESS:
+ // set bcc in the parent tag
+ myparent.addBcc(addr);
+ break;
+ default:
+ throw new JspTagException("addrecipient tag type attribute is not set. " +
+ " Specify either \"to\", \"cc\", or \"bcc\".");
+ }
+ }
+
}
1.2 +17 -11 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/FromTag.java
Index: FromTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/FromTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FromTag.java 31 Mar 2001 03:10:36 -0000 1.1
+++ FromTag.java 31 Oct 2002 05:01:27 -0000 1.2
@@ -99,16 +99,22 @@
// parent tag must be a MailTag, gives access to methods in parent
MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- String from; // the from address for this email
- if (myparent == null)
+ if (myparent == null) {
throw new JspException("from tag not nested within mail tag");
- else {
- if ((from = bodyContent.getString()) != null) {
- myparent.setFrom(from.trim()); // set from in the parent tag
- } else
- throw new JspException("The from tag is empty");
+ }
+
+ BodyContent body = getBodyContent();
+ String from = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (from != null) {
+ from.trim();
+ if (from.length() > 0) {
+ myparent.resetFrom(from); // set from in the parent tag
+ return SKIP_BODY;
+ }
}
- return SKIP_BODY;
+ throw new JspException("The from tag is empty");
}
}
1.4 +15 -15 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/HeaderTag.java
Index: HeaderTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/HeaderTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HeaderTag.java 23 May 2001 18:51:41 -0000 1.3
+++ HeaderTag.java 31 Oct 2002 05:01:27 -0000 1.4
@@ -119,19 +119,19 @@
// parent tag must be a MailTag, gives access to methods in parent
MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- if (myparent == null)
+ if (myparent == null) {
throw new JspException("header tag not nested within mail tag");
- else {
- myparent.setHeaderName(name); // set header name in parent tag
- if (value != null)
- // set header value in the parent tag
- myparent.setHeaderValue(value);
- else if ((value = bodyContent.getString()) != null) {
- // if value was set in body of header tag
- myparent.setHeaderValue(value);
- } else
- throw new JspException("The header tag is empty");
- }
+ }
+ BodyContent body = getBodyContent();
+ if (value == null ) {
+ value = body.getString();
+ }
+ // Clear the body since we only used it as input for the header value
+ body.clearBody();
+ if (value == null) {
+ throw new JspException("The header tag is empty");
+ }
+ myparent.setHeader(name,value); // set header in parent tag
return SKIP_BODY;
}
1.9 +241 -103 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java
Index: MailTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MailTag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MailTag.java 23 Feb 2002 19:30:35 -0000 1.8
+++ MailTag.java 31 Oct 2002 05:01:27 -0000 1.9
@@ -144,85 +144,121 @@
public class MailTag extends BodyTagSupport {
/**
+ * The address type string constants
+ */
+ protected final static String TO_ADDRESS_STRING = "to";
+ protected final static String CC_ADDRESS_STRING = "cc";
+ protected final static String BCC_ADDRESS_STRING = "bcc";
+
+ /**
+ * The address type int constants
+ */
+ protected final static int TO_ADDRESS = 1;
+ protected final static int CC_ADDRESS = 2;
+ protected final static int BCC_ADDRESS = 3;
+
+ /**
* the address to which the mail is to be sent
*/
private String to = null;
+ private StringBuffer addTO = new StringBuffer();
+
/**
* the address to whom the recipient can reply to
*/
private String from = null;
+ private String reset_from = null;
+
/**
* the carbon copy list addresses that the message will be sent to
*/
private String cc = null;
+ private StringBuffer addCC = new StringBuffer();
+
/**
* the blind carbon copy list of addresses to recieve the message
*/
private String bcc = null;
+ private StringBuffer addBCC = new StringBuffer();
+
/**
* the subject of the message
*/
private String subject = "";
+ private String reset_subject;
+
/**
* the body of the email message
*/
private String body = null;
+
/**
* or provide the server here for a new session
*/
private String server = "localhost";
+ private String reset_server = null;
+
/**
* can be "text" or "html" (otherwise text is default)
*/
private String type = "text/plain";
+
/**
* jndi name for Session object
*/
private String session = null;
+
/**
* jndi named MimePartDataSource object
*/
private String mimemessage = null;
+
/**
* user to login to smtp server
*/
private String user = null;
+
/**
* simple text password to authenticate on smtp server
*/
private String password = null;
+
/**
* The actual session object
*/
private Session sessionobj = null;
- /**
- * the email object to be sent
- */
- private MimeMessage message = null;
+
/**
* the reply to address
*/
private String replyto = null;
+ private String reset_replyto = null;
+
/**
* list of names extra headers to add
*/
private ArrayList name = new ArrayList(10);
+
/**
* list of values of extra headers to add
*/
private ArrayList value = new ArrayList(10);
+
/**
* list of attachments stored as mimebodyparts
*/
private ArrayList bodyparts = new ArrayList(10);
+
/**
* flag that lets the send tag know if attachments are being sent
*/
private boolean attachments = false;
+
/**
* flag determines if an error has occured
*/
private boolean error = false;
+
/**
* flag that determines if the session for sending mail should have an
* authenticator so that user name and password can be entered if it is
@@ -242,64 +278,28 @@
*
*/
public final int doStartTag() throws JspException {
-
- if (mimemessage != null) {
- try {
- // get initial context from which to lookup messagedatasource
- Context ctx = new InitialContext();
-
- // create mail message using preexisting jndi named message
- MimePartDataSource mds =
- (MimePartDataSource)ctx.lookup(mimemessage);
- sessionobj = (Session)mds.getMessageContext().getSession();
- message = new MimeMessage(sessionobj);
- } catch (NamingException ne) {
- throw new JspException("Naming Exception " +
- ne.getExplanation());
- }
- } else if (session != null) {
- try {
- // get initial context from which to lookup session
- Context ctx = new InitialContext();
-
- // create the mail message using the preconfigured jndi
- // named session
- sessionobj = (Session)ctx.lookup(session);
- message = new MimeMessage(sessionobj);
- } catch (NamingException ne) {
- throw new JspException("Naming Exception " +
- ne.getExplanation());
- }
- } else {
- // if configuring one of the above objects the following list
- // are a good set to use to take care of error handling if some
- // addresses are not valid
-
- // set up the smtp session that will send the message
- Properties props = new Properties();
- // set host to server
- props.put("mail.smtp.host", server);
- // set properties to deal will SendFailedExceptions
- // send to all legal addresses
- props.put("mail.smtp.sendpartial", "true");
- // set notification
- props.put("mail.smtp.dsn.notify", "FAILURE");
- // set amount of message to get returned
- props.put("mail.smtp.dsn.ret", "FULL");
- // create new piece of mail for the smtp mail session check if
- // authentication is required for the mail server
-
- if (authentication) {
- // create the session with an authenticator object
- // better way to do authentication
- props.put("mail.smtp.auth", "true");
- sessionobj = Session.getDefaultInstance(props,
- new MailAuthenticator(user, password));
- } else
- sessionobj = Session.getDefaultInstance(props, null);
-
- message = new MimeMessage(sessionobj);
- }
+ // Reset dynamic email addresses
+ addTO.setLength(0);
+ if (to != null) {
+ addTO.append(to);
+ }
+ addCC.setLength(0);
+ if (cc != null) {
+ addCC.append(cc);
+ }
+ addBCC.setLength(0);
+ if (bcc != null) {
+ addBCC.append(bcc);
+ }
+ reset_from = null;
+ reset_replyto = null;
+ reset_subject = null;
+ reset_server = null;
+ name.clear();
+ value.clear();
+ bodyparts.clear();
+ attachments = false;
+ sessionobj = null;
// taglibs 1.1
return EVAL_BODY_TAG; // evaluate the body of this tag
@@ -324,7 +324,7 @@
if (bodyContent.getString().trim().length() == 0)
return EVAL_PAGE;
else {
- // write out to bodycontent of paren tag
+ // write out to bodycontent of parent tag
try {
pageContext.getOut().write(bodyContent.getString());
} catch (IOException ie) {
@@ -341,7 +341,69 @@
* @return message - the entire email message
*
*/
- public final MimeMessage getMessage() {
+ public final MimeMessage getMessage() throws JspException {
+ MimeMessage message;
+ if (mimemessage != null) {
+ try {
+ // get initial context from which to lookup messagedatasource
+ Context ctx = new InitialContext();
+
+ // create mail message using preexisting jndi named message
+ MimePartDataSource mds =
+ (MimePartDataSource)ctx.lookup(mimemessage);
+ sessionobj = (Session)mds.getMessageContext().getSession();
+ message = new MimeMessage(sessionobj);
+ } catch (NamingException ne) {
+ throw new JspException("Naming Exception " +
+ ne.getExplanation());
+ }
+ } else if (session != null) {
+ try {
+ // get initial context from which to lookup session
+ Context ctx = new InitialContext();
+
+ // create the mail message using the preconfigured jndi
+ // named session
+ sessionobj = (Session)ctx.lookup(session);
+ message = new MimeMessage(sessionobj);
+ } catch (NamingException ne) {
+ throw new JspException("Naming Exception " +
+ ne.getExplanation());
+ }
+ } else {
+ // if configuring one of the above objects the following list
+ // are a good set to use to take care of error handling if some
+ // addresses are not valid
+
+ // set up the smtp session that will send the message
+ Properties props = new Properties();
+ // set host to server
+ if (reset_server != null) {
+ props.put("mail.smtp.host", reset_server);
+ } else {
+ props.put("mail.smtp.host", server);
+ }
+ // set properties to deal will SendFailedExceptions
+ // send to all legal addresses
+ props.put("mail.smtp.sendpartial", "true");
+ // set notification
+ props.put("mail.smtp.dsn.notify", "FAILURE");
+ // set amount of message to get returned
+ props.put("mail.smtp.dsn.ret", "FULL");
+ // create new piece of mail for the smtp mail session check if
+ // authentication is required for the mail server
+
+ if (authentication) {
+ // create the session with an authenticator object
+ // better way to do authentication
+ props.put("mail.smtp.auth", "true");
+ sessionobj = Session.getDefaultInstance(props,
+ new MailAuthenticator(user, password));
+ } else
+ sessionobj = Session.getDefaultInstance(props, null);
+
+ message = new MimeMessage(sessionobj);
+ }
return message;
}
@@ -372,7 +434,10 @@
*
*/
public final String getTo() {
- return to;
+ if (addTO.length() > 0 ) {
+ return addTO.toString();
+ }
+ return null;
}
/**
@@ -382,28 +447,37 @@
*
*/
public final String getReplyTo() {
+ if (reset_replyto != null) {
+ return reset_replyto;
+ }
return replyto;
}
/**
- * set the from address for this email
+ * get the from address for this email
*
* @return - the address from whom this mail is to be sent
*
*/
public final String getFrom() {
+ if (reset_from != null) {
+ return reset_from;
+ }
return from;
}
/**
- * set the cc address/addresses for this email
+ * get the cc address/addresses for this email
*
* @return - list of carbon copy addresses to recieve
* this email
*
*/
public final String getCc() {
- return cc;
+ if (addCC.length() > 0 ) {
+ return addCC.toString();
+ }
+ return null;
}
/**
@@ -414,7 +488,10 @@
*
*/
public final String getBcc() {
- return bcc;
+ if (addBCC.length() > 0 ) {
+ return addBCC.toString();
+ }
+ return null;
}
/**
@@ -424,6 +501,9 @@
*
*/
public final String getSubject() {
+ if (reset_subject != null) {
+ return reset_subject;
+ }
return subject;
}
@@ -526,7 +606,7 @@
*
*/
public final void setCc(String value) {
- cc = value;
+ cc = value;
}
/**
@@ -551,23 +631,14 @@
}
/**
- * set the name of any extra headers to be sent
- *
- * @param value string that is the name of an extra header to be set
+ * set the name and value of any extra headers to be sent
*
+ * @param name string that is the name of an extra header to be sent
+ * @param value string that is the value of an extra header to be sent
*/
- public final void setHeaderName(String value) {
- name.add(value);
- }
-
- /**
- * set the value of any extra headers to be set
- *
- * @param value string that is the value of an extra header to be set
- *
- */
- public final void setHeaderValue(String value) {
- this.value.add(value);
+ protected final void setHeader(String name, String value) {
+ this.name.add(name);
+ this.value.add(value);
}
/**
@@ -677,11 +748,11 @@
* @param value string that is an address to whom this mail is to be sent
*
*/
- public final void addTo(String value) {
- if (to == null)
- to = value;
- else
- to = to.concat("," + value);
+ protected final void addTo(String value) {
+ if (addTO.length() > 0) {
+ addTO.append(",");
+ }
+ addTO.append(value);
}
/**
@@ -691,11 +762,11 @@
* addresses for this email
*
*/
- public final void addCc(String value) {
- if (cc == null)
- cc = value;
- else
- cc = cc.concat("," + value);
+ protected final void addCc(String value) {
+ if (addCC.length() > 0) {
+ addCC.append(",");
+ }
+ addCC.append(value);
}
/**
@@ -705,11 +776,78 @@
* addresses for this email
*
*/
- public final void addBcc(String value) {
- if (bcc == null)
- bcc = value;
- else
- bcc = bcc.concat("," + value);
+ protected final void addBcc(String value) {
+ if (addBCC.length() > 0) {
+ addBCC.append(",");
+ }
+ addBCC.append(value);
+ }
+
+ /**
+ * reset the to address to a single email address
+ *
+ * @param value string that is an address to whom this mail is to be sent
+ */
+ protected final void resetTo(String value) {
+ addTO.setLength(0);
+ addTO.append(value);
}
+
+ /**
+ * reset the cc address to a single email address
+ *
+ * @param value string that is a cc address to be used for this email
+ */
+ protected final void resetCc(String value) {
+ addCC.setLength(0);
+ addCC.append(value);
+ }
+
+ /**
+ * reset the bcc address to a single email address
+ *
+ * @param value string that is a bcc address to be used for this email
+ */
+ protected final void resetBcc(String value) {
+ addBCC.setLength(0);
+ addBCC.append(value);
+ }
+
+ /**
+ * reset the from address for this email
+ *
+ * @param value string that is the address from whom this mail is to be sent
+ */
+ protected final void resetFrom(String value) {
+ reset_from = value;
+ }
+
+ /**
+ * reset the replyto address for this email
+ *
+ * @param value string that is the address for email reply to
+ */
+ protected final void resetReplyTo(String value) {
+ reset_replyto = value;
+ }
+
+ /**
+ * reset the email subject
+ *
+ * @param value string that is the email subject
+ */
+ protected final void resetSubject(String value) {
+ reset_subject = value;
+ }
+
+ /**
+ * reset the SMTP server hostname
+ *
+ * @param value string that is SMTP server hostname
+ */
+ protected final void resetServer(String value) {
+ reset_server = value;
+ }
+
}
1.5 +15 -13 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MessageTag.java
Index: MessageTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/MessageTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MessageTag.java 29 May 2001 22:47:11 -0000 1.4
+++ MessageTag.java 31 Oct 2002 05:01:27 -0000 1.5
@@ -109,17 +109,19 @@
// parent tag must be a MailTag, gives access to methods in parent
MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- String body; // the body for this email
-
- if (myparent == null)
+ if (myparent == null) {
throw new JspException("message tag not nested within mail tag");
- else {
- if ((body = bodyContent.getString()) != null) {
- myparent.setMessage(body); // set message in the parent tag
- myparent.setType(type); // set the mime type of the message
- } else
- throw new JspException("The message tag is empty");
- }
+ }
+
+ BodyContent body = getBodyContent();
+ String message = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (message == null) {
+ throw new JspException("The message tag is empty");
+ }
+ myparent.setMessage(message); // set message in the parent tag
+ myparent.setType(type); // set the mime type of the message
return SKIP_BODY;
}
1.4 +22 -16 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/ReplyToTag.java
Index: ReplyToTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/ReplyToTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ReplyToTag.java 23 May 2001 18:52:58 -0000 1.3
+++ ReplyToTag.java 31 Oct 2002 05:01:27 -0000 1.4
@@ -97,18 +97,24 @@
*/
public final int doAfterBody() throws JspException {
- // parent tag must be a MailTag, gives access to methods in parent
- MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- String replyto; // the replyto address for this email
+ // parent tag must be a MailTag, gives access to methods in parent
+ MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- if (myparent == null)
- throw new JspException("replyto tag not nested within mail tag");
- else {
- if ((replyto = bodyContent.getString()) != null) {
- myparent.setReplyTo(replyto); // set replyto in the parent tag
- } else
- throw new JspException("The ReplyTo tag is empty");
- }
- return SKIP_BODY;
+ if (myparent == null) {
+ throw new JspException("replyto tag not nested within mail tag");
+ }
+
+ BodyContent body = getBodyContent();
+ String replyto = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (replyto != null) {
+ replyto.trim();
+ if (replyto.length() > 0) {
+ myparent.resetReplyTo(replyto); // set replyto in the parent tag
+ return SKIP_BODY;
+ }
+ }
+ throw new JspException("The replyto tag is empty");
}
}
1.13 +5 -19 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SendTag.java
Index: SendTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SendTag.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- SendTag.java 23 Feb 2002 19:30:35 -0000 1.12
+++ SendTag.java 31 Oct 2002 05:01:27 -0000 1.13
@@ -102,6 +102,7 @@
*/
public final int doStartTag() throws JspException {
+ error = null;
int i = 0; // counter for list of extra header name/value pairs
MimeMessage message; // message object that contains this message
// Added by Jayson Falkner - 5/8/2001 --------------------------
@@ -140,11 +141,6 @@
// get the to address(es)
if ((to = myparent.getTo()) != null) {
- // due to the way address are added if addTo is used a ','
- // could be in the first position strip it
- if (to.indexOf(',') == 0)
- to = to.substring(1);
-
try {
// set the to address for this message
// catch any errors in the format of the addresses
@@ -254,11 +250,6 @@
// check for and set cc addresses
if ((cc = myparent.getCc()) != null) {
- // due to the way address are added if addCc is used a
- // ',' could be in the first position strip it
- if (cc.indexOf(',') == 0)
- cc = cc.substring(1);
-
try {
message.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc));
@@ -301,11 +292,6 @@
// check for and set bcc addresses
if ((bcc = myparent.getBcc()) != null) {
- // due to the way address are added if addBcc is used a
- // ',' could be in the first position strip it
- if (bcc.indexOf(',') == 0)
- bcc = bcc.substring(1);
-
try {
message.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc));
@@ -451,7 +437,7 @@
*
*/
public final ArrayList getError() {
- return error;
+ return error;
}
}
1.3 +22 -16 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/ServerTag.java
Index: ServerTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/ServerTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServerTag.java 7 Sep 2002 17:32:03 -0000 1.2
+++ ServerTag.java 31 Oct 2002 05:01:27 -0000 1.3
@@ -102,18 +102,24 @@
*/
public final int doAfterBody() throws JspException {
- // parent tag must be a MailTag, gives access to methods in parent
- MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- String server; // the url for the page to be scraped
+ // parent tag must be a MailTag, gives access to methods in parent
+ MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- if (myparent == null)
- throw new JspException("server tag not nested within mail tag");
- else {
- if ((server = bodyContent.getString()) != null) {
- myparent.setServer(server); // set the url in the parent tag
- } else
- throw new JspException("The mail server was not provided");
- }
- return SKIP_BODY;
+ if (myparent == null) {
+ throw new JspException("server tag not nested within mail tag");
+ }
+
+ BodyContent body = getBodyContent();
+ String server = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (server != null) {
+ server.trim();
+ if (server.length() > 0) {
+ myparent.resetServer(server); // set server in the parent tag
+ return SKIP_BODY;
+ }
+ }
+ throw new JspException("The server tag is empty");
}
}
1.6 +69 -59 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SetRecipientTag.java
Index: SetRecipientTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SetRecipientTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SetRecipientTag.java 3 Apr 2002 17:48:36 -0000 1.5
+++ SetRecipientTag.java 31 Oct 2002 05:01:27 -0000 1.6
@@ -103,21 +103,19 @@
/**
* The type of address to add either to, cc, or bcc
*/
- private String type = null;
+ private String type_string = null;
+ private int type = 0;
+
/**
* The address to be added
*/
private String address = null;
- /**
- * The parent tag of this tag
- */
- MailTag myparent = null;
/**
* implementation of the method from the tag interface that tells the JSP
* page what to do at the start of this tag
*
- * @throws JSPException thrown when an error occurs while processing the
+ * @throws JSPTagException thrown when an error occurs while processing the
* body of this method
*
* @return SKIP_BODY int telling the tag handler to not evaluate the body
@@ -127,33 +125,11 @@
*
*/
public final int doStartTag() throws JspException {
- // parent tag must be a MailTag, gives access to methods in parent
- myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
-
- if (myparent == null)
- throw new JspException("setrecipient tag not nested within mail tag");
- // Make sure type is set..either "to", "cc", or "bcc"
- if ((type != null) && (type.equalsIgnoreCase("to") ||
- type.equalsIgnoreCase("cc") || type.equalsIgnoreCase("bcc"))) {
-
- if (address != null) {
- // Try to see if the address attribute was used.
- if (type.equalsIgnoreCase("to"))
- // set to in the parent tag
- myparent.setTo(address);
- if (type.equalsIgnoreCase("cc"))
- // set cc in the parent tag
- myparent.setCc(address);
- if (type.equalsIgnoreCase("bcc"))
- // set bcc in the parent tag
- myparent.setBcc(address);
- address = null; // reset address
- return SKIP_BODY;
- } else
- return EVAL_BODY_TAG;
- } else
- throw new JspException("The type attribute is not set. " +
- " Specify either \"to\", \"cc\", or \"bcc\".");
+ if (address != null && address.length() > 0 ) {
+ addToParent(address);
+ return SKIP_BODY;
+ }
+ return EVAL_BODY_TAG;
}
@@ -169,44 +145,78 @@
*
*/
public final int doAfterBody() throws JspException {
- if ((address = bodyContent.getString()) != null) {
- // Try to see if the body was used for the address.
- if (type.equalsIgnoreCase("to"))
- // set to in the parent tag
- myparent.setTo(address);
- if (type.equalsIgnoreCase("cc"))
- // set cc in the parent tag
- myparent.setCc(address);
- if (type.equalsIgnoreCase("bcc"))
- // set bcc in the parent tag
- myparent.setBcc(address);
- address = null; // reset address so tag can be reused
- return SKIP_BODY;
- } else
- throw new JspException("Address was not found. set " +
- " the address attribute, or place the address in" +
- " the body of the tag.");
+ BodyContent body = getBodyContent();
+ String addr = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (addr != null && addr.length() > 0 ) {
+ addToParent(addr);
+ return SKIP_BODY;
+ } else {
+ throw new JspException("addrecpient tag could not find an email address. set " +
+ " the address attribute, or place the address in" +
+ " the body of the tag.");
+ }
}
/**
* set the type of recipient for the address
*
- * @param type string that is the type of the address either
+ * @param type string that is the type of the address either
* "to", "cc", or "bcc".
- *
*/
- public final void setType(String type) {
- this.type = type.trim();
+ public final void setType(String type) throws JspTagException {
+ this.type_string = type.trim();
+ if (type_string.equalsIgnoreCase(MailTag.TO_ADDRESS_STRING)) {
+ this.type = MailTag.TO_ADDRESS;
+ } else if (type_string.equalsIgnoreCase(MailTag.CC_ADDRESS_STRING)) {
+ this.type = MailTag.CC_ADDRESS;
+ } else if (type_string.equalsIgnoreCase(MailTag.BCC_ADDRESS_STRING)) {
+ this.type = MailTag.BCC_ADDRESS;
+ } else {
+ throw new JspTagException
+ ("setrecipient tag type attribute must be \"to\", \"cc\", or \"bcc\"");
+ }
}
/**
* set the value for an address to be later added to the email
*
- * @param address string that is an address to be added to the
+ * @param address string that is an address to be added to the
* "to", "cc", or "bcc" lists of addresses.
- *
*/
public final void setAddress(String address) {
this.address = address.trim();
}
+
+ private void addToParent(String addr) throws JspTagException {
+ // parent tag must be a MailTag, gives access to methods in parent
+ MailTag myparent =
+ (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass
+ (this, MailTag.class);
+
+ if (myparent == null) {
+ throw new JspTagException("setrecipient tag not nested within mail tag");
+ }
+
+ // Make sure type is set..either "to", "cc", or "bcc"
+ switch (type) {
+ case MailTag.TO_ADDRESS:
+ // set to in the parent tag
+ myparent.resetTo(addr);
+ break;
+ case MailTag.CC_ADDRESS:
+ // set cc in the parent tag
+ myparent.resetCc(addr);
+ break;
+ case MailTag.BCC_ADDRESS:
+ // set bcc in the parent tag
+ myparent.resetBcc(addr);
+ break;
+ default:
+ throw new JspTagException("setrecipient tag type attribute is not set. " +
+ " Specify either \"to\", \"cc\", or \"bcc\".");
+ }
+ }
}
+
1.5 +22 -16 jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SubjectTag.java
Index: SubjectTag.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/src/org/apache/taglibs/mailer/SubjectTag.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SubjectTag.java 29 May 2001 22:47:47 -0000 1.4
+++ SubjectTag.java 31 Oct 2002 05:01:27 -0000 1.5
@@ -97,18 +97,24 @@
*/
public final int doAfterBody() throws JspException {
- // parent tag must be a MailTag, gives access to methods in parent
- MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- String sub; // the subject for this email
+ // parent tag must be a MailTag, gives access to methods in parent
+ MailTag myparent = (MailTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, MailTag.class);
- if (myparent == null)
- throw new JspException("subject tag not nested within mail tag");
- else {
- if ((sub = bodyContent.getString()) != null) {
- myparent.setSubject(sub); // set subject in the parent tag
- } else
- throw new JspException("The subject tag is empty");
- }
- return SKIP_BODY;
+ if (myparent == null) {
+ throw new JspException("subject tag not nested within mail tag");
+ }
+
+ BodyContent body = getBodyContent();
+ String subject = body.getString();
+ // Clear the body since we only used it as input for the email address
+ body.clearBody();
+ if (subject != null) {
+ subject.trim();
+ if (subject.length() > 0) {
+ myparent.resetSubject(subject); // set subject in the parent tag
+ return SKIP_BODY;
+ }
+ }
+ throw new JspException("The subject tag is empty");
}
}
1.4 +10 -2 jakarta-taglibs/mailer/xml/intro.xml
Index: intro.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/xml/intro.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- intro.xml 15 Apr 2002 00:59:52 -0000 1.3
+++ intro.xml 31 Oct 2002 05:01:27 -0000 1.4
@@ -17,6 +17,14 @@
<section name="News" href="News">
<news>
+ <newsitem date="10/30/2002">
+ The nightly build now has support for the Server tag for setting
+ the SMTP host dynamically. Many tags refactored to fix bugs when
+ running in a JSP engine which supports custom tag pooling like
+ Tomcat 4.1 with Jasper 2. This is considered version 1.1 Beta now.
+ </newsitem>
+ </news>
+ <news>
<newsitem date="04/14/2002">
Version 1.0 Released
</newsitem>
@@ -28,8 +36,8 @@
<p>For more information about the Mailer Tag Library, look at the on-line documentation:</p>
<ul>
<li>
- View the current release <a href="mailer-1.0/index.html">
- Mailer 1.0 Taglib Documentation</a></li>
+ View the current release <a href="mailer-1.1/index.html">
+ Mailer 1.1 Taglib Documentation</a></li>
<li>
View the development version of the <a href="index.html">
Mailer Taglib Documentation</a>
1.8 +11 -3 jakarta-taglibs/mailer/xml/mailer.xml
Index: mailer.xml
===================================================================
RCS file: /home/cvs/jakarta-taglibs/mailer/xml/mailer.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- mailer.xml 7 Sep 2002 17:15:54 -0000 1.7
+++ mailer.xml 31 Oct 2002 05:01:28 -0000 1.8
@@ -36,13 +36,13 @@
<taglib>
<!-- The following elements are from the JSP 1.2 TLD DTD -->
<!-- Version number of this tagib -->
- <tlib-version>1.0</tlib-version>
+ <tlib-version>1.1</tlib-version>
<!-- Minimum version of JSP spec required -->
<jsp-version>1.1</jsp-version>
<!-- jakarta-taglib name of this tag library -->
<short-name>mailer</short-name>
<!-- URI of taglib -->
- <uri>http://jakarta.apache.org/taglibs/mailer-1.0</uri>
+ <uri>http://jakarta.apache.org/taglibs/mailer-1.1</uri>
<!-- The name to use in titles, etc. for the taglib -->
<display-name>Mailer Tag library</display-name>
@@ -339,7 +339,7 @@
<summary>
Used to set the mail server that will send the mail.
</summary>
- <availability>1.0</availability>
+ <availability>1.1</availability>
<restrictions>
Must be nested within a mail tag.<br/>Must occur before send tag.
</restrictions>
@@ -1031,6 +1031,14 @@
</tagtoc>
</taglib>
+
+<revision release="1.1 Beta" date="10/30/2002">
+ <description>
+ Added the server tag so that the SMTP host can be set dynamically.
+ Refactored tags to fix bugs when running in a JSP engine which
+ implements custom tag pooling like Tomcat 4.1 Jasper 2.
+ </description>
+</revision>
<revision release="1.0" date="04/14/2002">
<description>1.0 Release</description>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>