[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: java template emailer



Being a huge fan of Perl I would suggest regular expressions. The approach
is more scalable than jsp since it doesn't require webserver running.

Check http://jakarta.apache.org/oro/index.html for regular expression
library for Java. With it you can quickly define search and replace
patterns.

The other approach would be to use XML and XSLT but that's much harder and
requires you to learn XSL...

Try this:

...
import org.apache.oro.text.regex.*;
...

// begining of code
String name = "John Doe";
String email = "john@doe.com";
// you define the pattern!
String source = "Hello <%=name%> how are you? Your email is {#email#}";
String namePattern = "<%=name%>";
String emailPattern = "{#email#}";
source = replace( source, name, namePattern );
source = replace( source, email, emailPattern );
System.out.println( source );

private String replace( String source, String replacement, String regexp )
throws MalformedPatternException
{
	PatternMatcher matcher = new Perl5Matcher();
	PatternCompiler compiler = new Perl5Compiler();
	Pattern pattern = compiler.compile(regexp);
	return Util.substitute(
		matcher,
		pattern,
		new Perl5Substitution(replacement, Perl5Substitution.INTERPOLATE_ALL),
		source,
		Util.SUBSTITUTE_ALL);
}
// end of code

Nedim.

-----Original Message-----
From: Brian Lee [mailto:brian_a_lee@hotmail.com]
Sent: Friday, March 01, 2002 9:59 AM
To: csmith@cimaconsulting.com; ajug-members@www.ajug.org
Subject: Re: java template emailer


It might be easier for you not to use JSP to format the message.

It would be faster and simpler to just hold the HTML in some structure
(giant StringBuffer, xml Document, etc.) and put the data in yourself. The
problem with calling your JSP is that you'll be using a lot of processor
cycles and network traffic just to do replacements for you.

You can do something like this:
have a map with all of your replacement variables and names for each user:
name="john"
email="x@x.x"
etc.

Then have a SringBuffer that contains this:
Hello <%=name%> how are you? We are emailing you at <%=email%>...."

Then write a while loop to replace all the <%=%>'s with the values from the
Map. It's very exensible, quick and doesn't require a JSP engine.

BAL


>From: "Chad Smith" <csmith@cimaconsulting.com>
>To: <ajug-members@www.ajug.org>
>Subject: java template emailer
>Date: Fri, 1 Mar 2002 09:35:23 -0500
>MIME-Version: 1.0
>Received: from [66.45.18.180] by hotmail.com (3.2) with ESMTP id
>MHotMailBE48DD1800594136E80A422D12B481F20; Fri, 01 Mar 2002 06:37:24 -0800
>Received: (from list@localhost)by www.ajug.org (8.11.2/8.11.2) id
>g21FgCm01959;Fri, 1 Mar 2002 10:42:12 -0500
>From ajug-members-request@ajug.org Fri, 01 Mar 2002 06:39:04 -0800
>Resent-Date: Fri, 1 Mar 2002 10:42:12 -0500
>Message-ID: <001f01c1c12e$53d5c720$7fcb98ac@gattaca>
>X-Priority: 3 (Normal)
>X-MSMail-Priority: Normal
>X-Mailer: Microsoft Outlook, Build 10.0.2616
>Importance: Normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>In-Reply-To: <3C7F94B1.905842E2@pencom.com>
>Resent-Message-ID: <CeO-_.A.he.UF6f8@www>
>Resent-From: ajug-members@ajug.org
>X-Mailing-List: <ajug-members@ajug.org> archive/latest/3
>X-Loop: ajug-members@ajug.org
>List-Post: <mailto:ajug-members@ajug.org>
>List-Help: <mailto:ajug-members-request@ajug.org?subject=help>
>List-Subscribe: <mailto:ajug-members-request@ajug.org?subject=subscribe>
>List-Unsubscribe:
><mailto:ajug-members-request@ajug.org?subject=unsubscribe>
>Precedence: list
>Resent-Sender: ajug-members-request@ajug.org
>
>
>I'm trying to create a marketing campaign emailer  for a client that
>will let me send out a template JSP file that i will populate with data
>from a data source.
>For example, I have a TreeSet of data where each index holds personal
>information about a user (name, email address, city, etc.)
>I want to send out an HTML/JSP email as follows:
>
>Hello <%=NAME%>,
>
>Thank you for purchasing <%=PRODUCT%>.
>Please let us know if you are satisfied with the product:
>
><HERE IS A DROPDOWNLIST>
>Very Satisfied
>Satisfied
>Not Satisfied
>You're Awful
><END LIST>
>
><SAVE>
>
>Now the problem i'm having is ...I know how to display this information
>for each person in the TreeSet (using a forward or include), but
>how do i send the completed jsp/html email to that person?
>
>  I know that I can do the following:
>
>URL thePage = new URL("http://www.yoursite.com/yourjsp.jsp";);
>URLConnection conn = thePage.openConnection();
>InputStream is = conn.getInputStream();
>
>  // read from this InputStream
>Then you can direct the data from that InputStream into the e-mail body.
>
>But i'm pretty sure this will send out the jsp without having first
>compiled it.
>I need to figure out a way to either compile the jsp and then send it,
>or compile it to some sort of .html file and send it.
>I also need to find the most efficient way of doing this since  the
>client could be sending large campaigns of emails.
>
>Thanks for your time!
>
>Chad Smith
>"May the road rise to meet you."
>




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com