diff --git a/core/api/src/main/java/org/jboss/seam/mail/templating/MailTemplate.java b/core/api/src/main/java/org/jboss/seam/mail/templating/MailTemplate.java deleted file mode 100644 index 6866b31..0000000 --- a/core/api/src/main/java/org/jboss/seam/mail/templating/MailTemplate.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.seam.mail.templating; - -import java.io.InputStream; -/** - * - * @author Cody Lerum - * - */ -public interface MailTemplate -{ - public String getTemplateName(); - - public InputStream getInputStream(); -} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/FileTemplate.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/FileTemplate.java deleted file mode 100644 index 554a2c2..0000000 --- a/core/impl/src/main/java/org/jboss/seam/mail/templating/FileTemplate.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.seam.mail.templating; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; - -import org.jboss.seam.mail.templating.TemplatingException; - -/** - * - * @author Cody Lerum - * - */ -public class FileTemplate implements MailTemplate -{ - private String templateName; - private File file; - - public FileTemplate(File file) - { - this.templateName = file.getName(); - this.file = file; - } - - public FileTemplate(File file, String templateName) - { - this.templateName = file.getName(); - this.file = file; - } - - public String getTemplateName() - { - return templateName; - } - - public InputStream getInputStream() - { - try - { - return new FileInputStream(file); - } - catch (FileNotFoundException e) - { - throw new TemplatingException("Unable to find template file " + file.getName(), e); - } - } -} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java deleted file mode 100644 index a02a2df..0000000 --- a/core/impl/src/main/java/org/jboss/seam/mail/templating/InputStreamTemplate.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.seam.mail.templating; - -import java.io.InputStream; - - -/** - * - * @author Cody Lerum - * - */ -public class InputStreamTemplate implements MailTemplate -{ - private String templateName; - private InputStream inputStream; - - public InputStreamTemplate(InputStream inputStream, String templateName) - { - this.templateName = templateName; - this.inputStream = inputStream; - } - - public InputStreamTemplate(InputStream inputStream) - { - this.templateName = "default"; - this.inputStream = inputStream; - } - - public String getTemplateName() - { - return templateName; - } - - public InputStream getInputStream() - { - return inputStream; - } -} diff --git a/core/impl/src/main/java/org/jboss/seam/mail/templating/StringTemplate.java b/core/impl/src/main/java/org/jboss/seam/mail/templating/StringTemplate.java deleted file mode 100644 index eb22672..0000000 --- a/core/impl/src/main/java/org/jboss/seam/mail/templating/StringTemplate.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2011, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jboss.seam.mail.templating; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; - -import org.jboss.seam.mail.templating.TemplatingException; - -/** - * - * @author Cody Lerum - * - */ -public class StringTemplate implements MailTemplate -{ - private String templateName; - private String content; - - public StringTemplate(String content) - { - this.templateName = "stringTemplate"; - this.content = content; - } - - public StringTemplate(String content, String templateName) - { - this.templateName = templateName; - this.content = content; - } - - public String getTemplateName() - { - return templateName; - } - - public InputStream getInputStream() - { - try - { - return new ByteArrayInputStream(content.getBytes("UTF-8")); - } - catch (UnsupportedEncodingException e) - { - throw new TemplatingException("Unable to create template from String value", e); - } - } - -} diff --git a/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java b/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java index e38024e..ffb8d7f 100644 --- a/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java +++ b/examples/sendmail/src/test/java/org/jboss/seam/mail/FreeMarkerMailMessageTest.java @@ -18,6 +18,7 @@ package org.jboss.seam.mail; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import javax.enterprise.inject.Instance; @@ -356,7 +357,7 @@ public void testSMTPSessionAuthentication() throws MessagingException, Malformed } @Test(expected=SendFailedException.class) - public void testFreeMarkerTextMailMessageSendFailed() + public void testFreeMarkerTextMailMessageSendFailed() throws UnsupportedEncodingException { String uuid = java.util.UUID.randomUUID().toString(); String subject = "Text Message from $version Mail - " + uuid; diff --git a/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java b/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java index c2d79b1..70da0cd 100644 --- a/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java +++ b/examples/sendmail/src/test/java/org/jboss/seam/mail/VelocityMailMessageTest.java @@ -18,6 +18,7 @@ package org.jboss.seam.mail; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import javax.enterprise.inject.Instance; @@ -357,7 +358,7 @@ public void testSMTPSessionAuthentication() throws MessagingException, Malformed } @Test(expected=SendFailedException.class) - public void testVelocityTextMailMessageSendFailed() + public void testVelocityTextMailMessageSendFailed() throws UnsupportedEncodingException { String uuid = java.util.UUID.randomUUID().toString(); String subject = "Text Message from $version Mail - " + uuid; diff --git a/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerTemplate.java b/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerTemplate.java index 2809088..86867fb 100644 --- a/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerTemplate.java +++ b/freemarker/impl/src/main/java/org/jboss/seam/mail/templating/freemarker/FreeMarkerTemplate.java @@ -17,18 +17,18 @@ package org.jboss.seam.mail.templating.freemarker; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Map; -import org.jboss.seam.mail.templating.FileTemplate; -import org.jboss.seam.mail.templating.InputStreamTemplate; -import org.jboss.seam.mail.templating.MailTemplate; -import org.jboss.seam.mail.templating.StringTemplate; import org.jboss.seam.mail.templating.TemplateProvider; import org.jboss.seam.mail.templating.TemplatingException; @@ -46,28 +46,23 @@ public class FreeMarkerTemplate implements TemplateProvider { private Configuration configuration; private Map rootMap = new HashMap(); - private MailTemplate mailTemplate; + private InputStream inputStream; - public FreeMarkerTemplate(MailTemplate mailTemplate) + public FreeMarkerTemplate(InputStream inputStream) { - this.mailTemplate = mailTemplate; + this.inputStream = inputStream; configuration = new Configuration(); configuration.setObjectWrapper(new DefaultObjectWrapper()); } - public FreeMarkerTemplate(String string) - { - this(new StringTemplate(string)); - } - - public FreeMarkerTemplate(InputStream inputStream) + public FreeMarkerTemplate(String string) throws UnsupportedEncodingException { - this(new InputStreamTemplate(inputStream)); + this(new ByteArrayInputStream(string.getBytes("UTF-8"))); } - public FreeMarkerTemplate(File file) + public FreeMarkerTemplate(File file) throws FileNotFoundException { - this(new FileTemplate(file)); + this(new FileInputStream(file)); } public String merge(Map context) @@ -78,7 +73,7 @@ public String merge(Map context) try { - Template template = new Template(mailTemplate.getTemplateName(), new InputStreamReader(mailTemplate.getInputStream()), configuration); + Template template = new Template("mailGenerated", new InputStreamReader(inputStream), configuration); template.process(rootMap, writer); } catch (IOException e) diff --git a/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityTemplate.java b/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityTemplate.java index 3127978..60bcd39 100644 --- a/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityTemplate.java +++ b/velocity/impl/src/main/java/org/jboss/seam/mail/templating/velocity/VelocityTemplate.java @@ -17,11 +17,15 @@ package org.jboss.seam.mail.templating.velocity; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.util.Map; import org.apache.velocity.VelocityContext; @@ -29,10 +33,6 @@ import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; -import org.jboss.seam.mail.templating.FileTemplate; -import org.jboss.seam.mail.templating.InputStreamTemplate; -import org.jboss.seam.mail.templating.MailTemplate; -import org.jboss.seam.mail.templating.StringTemplate; import org.jboss.seam.mail.templating.TemplateProvider; import org.jboss.seam.mail.templating.TemplatingException; @@ -46,50 +46,39 @@ public class VelocityTemplate implements TemplateProvider private VelocityEngine velocityEngine; private VelocityContext velocityContext; private CDIVelocityContext cdiContext; + private InputStream inputStream; - private MailTemplate mailTemplate; - - public VelocityTemplate(MailTemplate mailTemplate) + public VelocityTemplate(InputStream inputStream) { velocityEngine = new VelocityEngine(); velocityEngine.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem"); - this.mailTemplate = mailTemplate; + this.inputStream = inputStream; } - public VelocityTemplate(MailTemplate mailTemplate, CDIVelocityContext cdiContext) + public VelocityTemplate(InputStream inputStream, CDIVelocityContext cdiContext) { - this(mailTemplate); + this(inputStream); this.cdiContext = cdiContext; } - - public VelocityTemplate(String string) - { - this(new StringTemplate(string)); - } - - public VelocityTemplate(String string, CDIVelocityContext cdiContext) - { - this(new StringTemplate(string), cdiContext); - } - - public VelocityTemplate(InputStream inputStream) + + public VelocityTemplate(String string) throws UnsupportedEncodingException { - this(new InputStreamTemplate(inputStream)); - } + this(new ByteArrayInputStream(string.getBytes("UTF-8"))); + } - public VelocityTemplate(InputStream inputStream, CDIVelocityContext cdiContext) + public VelocityTemplate(String string, CDIVelocityContext cdiContext) throws UnsupportedEncodingException { - this(new InputStreamTemplate(inputStream), cdiContext); - } - - public VelocityTemplate(File file) + this(new ByteArrayInputStream(string.getBytes("UTF-8")), cdiContext); + } + + public VelocityTemplate(File file) throws FileNotFoundException { - this(new FileTemplate(file)); + this(new FileInputStream(file)); } - - public VelocityTemplate(File file, CDIVelocityContext cdiContext) + + public VelocityTemplate(File file, CDIVelocityContext cdiContext) throws FileNotFoundException { - this(new FileTemplate(file), cdiContext); + this(new FileInputStream(file), cdiContext); } public String merge(Map context) @@ -103,7 +92,7 @@ public String merge(Map context) try { - velocityEngine.evaluate(velocityContext, writer, mailTemplate.getTemplateName(), new InputStreamReader(mailTemplate.getInputStream())); + velocityEngine.evaluate(velocityContext, writer, "mailGenerated", new InputStreamReader(inputStream)); } catch (ResourceNotFoundException e) {