1 16 package com.blandware.atleap.service.util; 17 18 import org.apache.commons.collections.ExtendedProperties; 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.velocity.exception.ResourceNotFoundException; 22 import org.apache.velocity.runtime.resource.Resource; 23 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; 24 25 import java.io.ByteArrayInputStream ; 26 import java.io.InputStream ; 27 import java.io.UnsupportedEncodingException ; 28 29 36 public class MailTemplateLoader extends ClasspathResourceLoader { 37 38 protected transient final Log log = LogFactory.getLog(MailTemplateLoader.class); 39 protected String encoding; 40 41 44 public MailTemplateLoader() { 45 } 46 47 50 public void init(ExtendedProperties extendedProperties) { 51 super.init(extendedProperties); 52 encoding = rsvc.getString("content.encoding", "utf-8"); 53 54 } 55 56 65 public InputStream getResourceStream(String templateName) throws ResourceNotFoundException { 66 67 InputStream result = null; 68 69 if ( templateName.startsWith("mailTemplate: ") ) { 70 templateName = templateName.substring("mailTemplate: ".length()); 71 byte[] template = null; 72 try { 73 template = templateName.getBytes(encoding); 74 } catch ( UnsupportedEncodingException e ) { 75 } 77 if ( template != null ) { 78 result = new ByteArrayInputStream (template); 79 } 80 } else { 81 result = super.getResourceStream(templateName); 82 } 83 84 return result; 85 } 86 87 92 public boolean isSourceModified(Resource resource) { 93 return super.isSourceModified(resource); 94 } 95 96 101 public long getLastModified(Resource resource) { 102 return super.getLastModified(resource); 103 } 104 } 105 | Popular Tags |