Hi,
I created a Email Template. Using
org.apache.commons.digester.Digester to parse my email.xml ---
<email>
<from>someone@[EMAIL PROTECTED]
>
<to>somebody@[EMAIL PROTECTED]
<subject>Hello,</subject>
<body> Hello {0} from {1 }</body>
</email>
When I tested it in the main method below. It works good.
public class DigesterDriver {
public static void main( String[] args ) {
try {
Digester digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate("email", EmailTemplate.class);
digester.addBeanPropertySetter("email/subject", "subject");
digester.addBeanPropertySetter("email/body", "body");
digester.addBeanPropertySetter("email/from", "from");
//Sorry, the three lines below not parsed correctly so far.
// digester.addCallMethod("email/to", "addTo", 0);
// digester.addCallMethod("email/cc", "addCc", 0);
// digester.addCallMethod("email/bcc", "addBcc", 0);
File input = new File( "C:\\requestInfoEmail.xml" );
EmailTemplate et = (EmailTemplate)digester.parse(input);
String[] arg = {" peter ", "zhang"};
String body = MessageFormat.format(et.getBody(),
(Object[])arg);
System.out.println("subject: " + et.getSubject());
System.out.println("body: " + body);
System.out.println("from: " + et.getFrom());
} catch( Exception exc ) {
exc.printStackTrace();
}
}
}
I could get some print out.
But the exactly same thing used in backing bean method. It didn't work.
digester.parse(input) always return a null. And the error is it could
not recognize the
<email> in the xml file. So it couldn't parse it.
By the way, this backing bean method is invoked when someone request
some infomation, it send a email to the info dept.
Why? It is weird.


|