Skip to content

Commit

Permalink
drop ClassPathEmailAttachment and ClassPathTemplate. Use InputStream
Browse files Browse the repository at this point in the history
versions with ResourceProvider.loadResourceStream
  • Loading branch information
codylerum committed Mar 4, 2011
1 parent f5eac9d commit 36aa623
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 177 deletions.
Expand Up @@ -31,7 +31,7 @@
* @author Cody Lerum
*
*/
public class BaseEmailAttachment extends BeanManagerAware implements EmailAttachment
public class BaseAttachment extends BeanManagerAware implements EmailAttachment
{
private String contentId;
private String fileName;
Expand All @@ -40,7 +40,7 @@ public class BaseEmailAttachment extends BeanManagerAware implements EmailAttach
private Collection<Header> headers = new ArrayList<Header>();
private byte[] bytes;

public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes)
public BaseAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes)
{
this();
this.fileName = fileName;
Expand All @@ -49,13 +49,13 @@ public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition
this.bytes = bytes;
}

public BaseEmailAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes, String contentClass)
public BaseAttachment(String fileName, String mimeType, ContentDisposition contentDisposition, byte[] bytes, String contentClass)
{
this(fileName, mimeType, contentDisposition, bytes);
this.addHeader(new Header("Content-Class", contentClass));
}

public BaseEmailAttachment()
public BaseAttachment()
{
this.contentId = UUID.randomUUID().toString();
}
Expand Down

This file was deleted.

@@ -0,0 +1,45 @@
package org.jboss.seam.mail.attachments;

import java.io.File;
import java.io.IOException;

import javax.activation.FileDataSource;

import org.jboss.seam.mail.core.AttachmentException;
import org.jboss.seam.mail.core.Header;
import org.jboss.seam.mail.core.enumurations.ContentDisposition;

import com.google.common.io.Files;

/**
*
* @author Cody Lerum
*
*/
public class FileAttachment extends BaseAttachment
{
public FileAttachment(File file, ContentDisposition contentDisposition)
{
super();

FileDataSource fds = new FileDataSource(file);

try
{
super.setFileName(fds.getName());
super.setMimeType(fds.getContentType());
super.setContentDisposition(contentDisposition);
super.setBytes(Files.toByteArray(file));
}
catch (IOException e)
{
throw new AttachmentException("Wasn't able to create email attachment from File: " + file.getName(), e);
}
}

public FileAttachment(File file, ContentDisposition contentDisposition, String contentClass)
{
this(file, contentDisposition);
super.addHeader(new Header("Content-Class", contentClass));
}
}
Expand Up @@ -14,9 +14,9 @@
* @author Cody Lerum
*
*/
public class InputStreamEmailAttachment extends BaseEmailAttachment
public class InputStreamAttachment extends BaseAttachment
{
public InputStreamEmailAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition)
public InputStreamAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition)
{
super();

Expand All @@ -33,7 +33,7 @@ public InputStreamEmailAttachment(InputStream inputStream, String fileName, Stri
}
}

public InputStreamEmailAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition, String contentClass)
public InputStreamAttachment(InputStream inputStream, String fileName, String mimeType, ContentDisposition contentDisposition, String contentClass)
{
this(inputStream, fileName, mimeType, contentDisposition);
super.addHeader(new Header("Content-Class", contentClass));
Expand Down
Expand Up @@ -10,9 +10,9 @@
import org.jboss.seam.mail.core.Header;
import org.jboss.seam.mail.core.enumurations.ContentDisposition;

public class URLEmailAttachment extends BaseEmailAttachment
public class URLAttachment extends BaseAttachment
{
public URLEmailAttachment(String url, String fileName, ContentDisposition contentDisposition)
public URLAttachment(String url, String fileName, ContentDisposition contentDisposition)
{
super();

Expand Down Expand Up @@ -40,7 +40,7 @@ public URLEmailAttachment(String url, String fileName, ContentDisposition conten
}
}

public URLEmailAttachment(String url, String fileName, ContentDisposition contentDisposition, String contentClass)
public URLAttachment(String url, String fileName, ContentDisposition contentDisposition, String contentClass)
{
this(url, fileName, contentDisposition);
super.addHeader(new Header("Content-Class", contentClass));
Expand Down
Expand Up @@ -5,7 +5,7 @@

import javax.activation.FileDataSource;

import org.jboss.seam.mail.attachments.BaseEmailAttachment;
import org.jboss.seam.mail.attachments.BaseAttachment;
import org.jboss.seam.mail.core.enumurations.ContentDisposition;

import com.google.common.io.Files;
Expand All @@ -15,7 +15,7 @@
* @author Cody Lerum
*
*/
public class FileEmailAttachment extends BaseEmailAttachment
public class FileEmailAttachment extends BaseAttachment
{
public FileEmailAttachment(File file, ContentDisposition contentDisposition)
{
Expand Down
Expand Up @@ -25,7 +25,7 @@
import javax.mail.internet.InternetAddress;

import org.jboss.seam.mail.api.MailMessage;
import org.jboss.seam.mail.attachments.BaseEmailAttachment;
import org.jboss.seam.mail.attachments.BaseAttachment;
import org.jboss.seam.mail.core.enumurations.ContentDisposition;
import org.jboss.seam.mail.core.enumurations.ContentType;
import org.jboss.seam.mail.core.enumurations.EmailMessageType;
Expand Down Expand Up @@ -278,7 +278,7 @@ public MailMessage iCal(String html, byte[] bytes)
{
emailMessage.setType(EmailMessageType.INVITE_ICAL);
emailMessage.setHtmlBody(html);
emailMessage.addAttachment(new BaseEmailAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage"));
emailMessage.addAttachment(new BaseAttachment(null, "text/calendar;method=CANCEL", ContentDisposition.INLINE, bytes, "urn:content-classes:calendarmessage"));
return this;
}

Expand Down

This file was deleted.

Expand Up @@ -26,16 +26,22 @@
* @author Cody Lerum
*
*/
public class InputStreamMailTemplate implements MailTemplate
public class InputStreamTemplate implements MailTemplate
{
private String templateName;
private InputStream inputStream;

public InputStreamMailTemplate(InputStream inputStream, String templateName)
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()
{
Expand Down
@@ -0,0 +1,54 @@
/*
* 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.util.Map;

import org.jboss.seam.mail.core.EmailAttachment;

/**
*
* @author Cody Lerum
*
*/
public class MailContext
{

private Map<String, EmailAttachment> attachments;

public MailContext(Map<String, EmailAttachment> attachments)
{
this.attachments = attachments;
}

public String insert(String fileName)
{
EmailAttachment attachment = null;

attachment = attachments.get(fileName);

if (attachment == null)
{
throw new RuntimeException("Unable to find attachment: " + fileName);
}
else
{
return "cid:" + attachment.getContentId();
}
}
}

0 comments on commit 36aa623

Please sign in to comment.