[jbpm-commits] JBoss JBPM SVN: r4527 - jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Apr 9 16:07:18 EDT 2009
Author: bradsdavis
Date: 2009-04-09 16:07:18 -0400 (Thu, 09 Apr 2009)
New Revision: 4527
Modified:
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/HtmlScriptMailProducer.java
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/ScriptMailProducer.java
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/SimpleMailProducer.java
Log:
Extracted logic for resolving and populating attachments.
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/HtmlScriptMailProducer.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/HtmlScriptMailProducer.java 2009-04-09 19:44:10 UTC (rev 4526)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/HtmlScriptMailProducer.java 2009-04-09 20:07:18 UTC (rev 4527)
@@ -47,41 +47,18 @@
this.text = (String)scriptManager.evaluateScript(this.text, exe, language);
this.subject = (String)scriptManager.evaluateScript(this.subject, exe, language);
this.html = (String)scriptManager.evaluate(this.html, exe, language);
-
- //Resolve attachements from script to URL.
- if(urlAttachments!=null)
- {
- for(String urlKey : urlAttachments.keySet())
- {
- String url = urlAttachments.get(urlKey);
- url = (String)scriptManager.evaluateScript(url, exe, language);
- urlAttachments.put(urlKey, url);
- }
- }
+ this.resolveAttachments(scriptManager, exe);
//Create an HTML message.
HtmlEmail email = new HtmlEmail();
//Populate recipients.
this.populateAddresses(mailContext, email);
+ this.populateAttachments((MultiPartEmail)email);
+
//Set the regular body [non-html] and subject.
email.setTextMsg(this.text);
email.setSubject(this.subject);
- if(urlAttachments!=null)
- {
- for(String urlKey : urlAttachments.keySet())
- {
- try {
- URL url = new URL(urlAttachments.get(urlKey));
- ((MultiPartEmail)email).attach(url,urlKey,urlKey);
- }
- catch(EmailException urlException)
- {
- log.error("Exception getting the URL.",urlException);
- }
- }
- }
-
//Keep track of the CIDs that have replaced SRCs to reduce
//calls to replace. Should improve efficiency.
Set<String> cidSet = new HashSet<String>();
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/ScriptMailProducer.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/ScriptMailProducer.java 2009-04-09 19:44:10 UTC (rev 4526)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/ScriptMailProducer.java 2009-04-09 20:07:18 UTC (rev 4527)
@@ -29,9 +29,21 @@
//as evaluated by the JBPM script manager.
this.text = (String)scriptManager.evaluateScript(this.text, exe, language);
this.subject = (String)scriptManager.evaluateScript(this.subject, exe, language);
+ this.resolveAttachments(scriptManager,exe);
- //Resolve attachements from script to URL.
- if(urlAttachments!=null)
+
+ //Populate and produce email based on SimpleMailProducer logic now that fields
+ //have been resolved using the JBPM script manager.
+ return super.produce(exe, mailContext);
+ }
+
+ public void setLanguage(String language) {
+ this.language = language;
+ }
+
+ protected void resolveAttachments(final ScriptManager scriptManager, final Execution exe) {
+ //Resolve attachments from script to URL.
+ if(urlAttachments!=null&&!urlAttachments.isEmpty())
{
for(String urlKey : urlAttachments.keySet())
{
@@ -40,14 +52,6 @@
urlAttachments.put(urlKey, url);
}
}
-
- //Populate and produce email based on SimpleMailProducer logic now that fields
- //have been resolved using the JBPM script manager.
- return super.produce(exe, mailContext);
}
- public void setLanguage(String language) {
- this.language = language;
- }
-
}
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/SimpleMailProducer.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/SimpleMailProducer.java 2009-04-09 19:44:10 UTC (rev 4526)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/producer/impl/SimpleMailProducer.java 2009-04-09 20:07:18 UTC (rev 4527)
@@ -51,26 +51,17 @@
//Resolve and populate to, cc, bcc addresses.
populateAddresses(mailContext, email);
-
+
+ //If there are attachments, add them to the email.
+ if(urlAttachments!=null&&!urlAttachments.isEmpty())
+ {
+ populateAttachments((MultiPartEmail)email);
+ }
+
//Set subject and message.
email.setSubject(subject);
email.setMsg(text);
- if(urlAttachments!=null)
- {
- for(String urlKey : urlAttachments.keySet())
- {
- try {
- URL url = new URL(urlAttachments.get(urlKey));
- ((MultiPartEmail)email).attach(url,urlKey,urlKey);
- }
- catch(EmailException urlException)
- {
- log.error("Exception getting the URL.",urlException);
- }
- }
- }
-
Collection<Email> emails = new HashSet<Email>();
emails.add(email);
@@ -148,6 +139,18 @@
return name;
}
+
+ protected void populateAttachments(MultiPartEmail email) throws Exception
+ {
+ if(urlAttachments!=null&&!urlAttachments.isEmpty())
+ {
+ for(String urlKey : urlAttachments.keySet())
+ {
+ URL url = new URL(urlAttachments.get(urlKey));
+ ((MultiPartEmail)email).attach(url,urlKey,urlKey);
+ }
+ }
+ }
public void setText(String text) {
More information about the jbpm-commits
mailing list