commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r1200553 - in /commons/proper/email/trunk/src: changes/ java/org/apache/commons/mail/ java/org/apache/commons/mail/impl/ java/org/apache/commons/mail/resolver/ java/org/apache/commons/mail/util/ test/attachments/ test/org/apache/commons/mai...
Date Thu, 10 Nov 2011 21:14:43 GMT
Author: sgoeschl
Date: Thu Nov 10 21:14:42 2011
New Revision: 1200553

URL: http://svn.apache.org/viewvc?rev=1200553&view=rev
Log:
[EMAIL-108] Embedded resources for ImageHtmlEmail can be now found using the classpath - furthermore refactored the resource resolving

Added:
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/
      - copied from r1165862, commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java   (contents, props changed)
      - copied, changed from r1165862, commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/DataSourceResolverImpl.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceUrlResolver.java
    commons/proper/email/trunk/src/test/attachments/autoloadertest.html
    commons/proper/email/trunk/src/test/attachments/classpathtest.html
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceClassPathResolverTest.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceFileResolverTest.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java
Removed:
    commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceResolverImpl.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/DataSourceResolverTest.java
Modified:
    commons/proper/email/trunk/src/changes/changes.xml
    commons/proper/email/trunk/src/java/org/apache/commons/mail/DataSourceResolver.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/package.html
    commons/proper/email/trunk/src/java/org/apache/commons/mail/util/MimeMessageParser.java
    commons/proper/email/trunk/src/java/org/apache/commons/mail/util/URLFactory.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java
    commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java

Modified: commons/proper/email/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/changes/changes.xml?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/changes/changes.xml (original)
+++ commons/proper/email/trunk/src/changes/changes.xml Thu Nov 10 21:14:42 2011
@@ -23,6 +23,9 @@
 
   <body>
     <release version="1.3" date="as in SVN">
+       <action dev="sgoeschl" type="add" issue="EMAIL-108" date="2011-11-10" due-to="Elisabeth Kasimir, Alexander Kasimir">
+          HtmlmageEmail should support class path resources
+       </action>
        <action dev="sgoeschl" type="fix" issue="EMAIL-107" date="2011-09-06" due-to="Claus Polanka, Michael Jakl">
           Added mime.types to META-INF - the definition is actually found in activation.jar
           but did not work.

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/DataSourceResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/DataSourceResolver.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/DataSourceResolver.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/DataSourceResolver.java Thu Nov 10 21:14:42 2011
@@ -34,4 +34,15 @@ public interface DataSourceResolver
      * @throws IOException the resource was not found
      */
     DataSource resolve(final String resourceLocation) throws IOException;
+
+    /**
+     * Resolves the given resource location to a <code>DataSource</code>.
+     *
+     * @param resourceLocation the location of the resource
+     * @param isLenient shall we ignore resources not found or complain with an exception?
+     * @return the data source containing the resource or null if the resource was not found in lenient mode
+     * @throws IOException resolving the resource failed
+     */
+    DataSource resolve(final String resourceLocation, final boolean isLenient)
+        throws IOException;
 }

Added: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java (added)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceBaseResolver.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import org.apache.commons.mail.DataSourceResolver;
+
+/**
+ * Base class for various resolvers.
+ *
+ * @since 1.3
+ */
+public abstract class DataSourceBaseResolver implements DataSourceResolver
+{
+    /** shall we ignore resources not found or complain with an exception */
+    private final boolean lenient;
+
+    public DataSourceBaseResolver()
+    {
+        this.lenient = false;
+    }
+
+    public DataSourceBaseResolver(final boolean lenient)
+    {
+        this.lenient = lenient;
+    }
+
+    /**
+     * Shall we ignore resources not found or throw an exception?
+     *
+     * @return the lenient flag
+     */
+    public boolean isLenient()
+    {
+        return lenient;
+    }
+
+    /**
+     * Is this a content id?
+     *
+     * @param resourceLocation the resource location
+     * @return true if it is a CID
+     */
+    protected boolean isCid(final String resourceLocation)
+    {
+        return resourceLocation.startsWith("cid:");
+    }
+
+    /**
+     * Is this a file URL?
+     *
+     * @param urlString the URL string
+     * @return true if it is a file URL
+     */
+    protected boolean isFileUrl(final String urlString)
+    {
+        return urlString.startsWith("file:/");
+    }
+
+    /**
+     * Is this a HTTP/HTTPS URL?
+     *
+     * @param urlString the URL string
+     * @return true if it is a HTTP/HTTPS URL
+     */
+    protected boolean isHttpUrl(final String urlString)
+    {
+        return urlString.startsWith("http://") || urlString.startsWith("https://");
+    }
+}

Added: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java (added)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import org.apache.commons.mail.ByteArrayDataSource;
+
+import javax.activation.DataSource;
+import javax.activation.FileTypeMap;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Creates a <code>DataSource</code> based on an class path.
+ *
+ * @since 1.3
+ */
+public class DataSourceClassPathResolver extends DataSourceBaseResolver
+{
+    /** the base string of the resource relative to the classpath when resolving relative paths */
+    private final String classPathBase;
+
+    public DataSourceClassPathResolver()
+    {
+        this.classPathBase = "/";
+    }
+
+    public DataSourceClassPathResolver(final String classPathBase)
+    {
+        this.classPathBase = classPathBase.endsWith("/") ? classPathBase : classPathBase + "/";
+    }
+
+    public DataSourceClassPathResolver(final String classPathBase, final boolean lenient)
+    {
+        super(lenient);
+        this.classPathBase = classPathBase.endsWith("/") ? classPathBase : classPathBase + "/";
+    }
+
+    /**
+     * @return the classPathBase
+     */
+    public String getClassPathBase()
+    {
+        return classPathBase;
+    }
+
+    public DataSource resolve(String resourceLocation) throws IOException
+    {
+        return resolve(resourceLocation, isLenient());
+    }
+
+    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
+    {
+        DataSource result = null;
+
+        try
+        {
+            if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation))
+            {
+                String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation);
+                String resourceName = getResourceName(resourceLocation);
+                InputStream is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName);
+
+                if(is != null)
+                {
+                    result = new ByteArrayDataSource(is, mimeType);
+                }
+                else
+                {
+                    if (isLenient)
+                    {
+                        return null;
+                    }
+                    else
+                    {
+                        throw new IOException("The following class path resource was not found : " + resourceLocation);
+                    }
+                }
+            }
+
+
+            return result;
+        }
+        catch (IOException e)
+        {
+            if (isLenient)
+            {
+                return null;
+            }
+            else
+            {
+                throw e;
+            }
+        }
+    }
+
+    private String getResourceName(final String resourceLocation)
+    {
+        return (getClassPathBase() + resourceLocation).replaceAll("//", "/");
+    }
+}

Copied: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java (from r1165862, commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/DataSourceResolverImpl.java)
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java?p2=commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java&p1=commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/DataSourceResolverImpl.java&r1=1165862&r2=1200553&rev=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/impl/DataSourceResolverImpl.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java Thu Nov 10 21:14:42 2011
@@ -14,105 +14,77 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.commons.mail.impl;
+package org.apache.commons.mail.resolver;
 
 import org.apache.commons.mail.DataSourceResolver;
-import org.apache.commons.mail.util.URLFactory;
 
 import javax.activation.DataSource;
-import javax.activation.URLDataSource;
 import java.io.IOException;
-import java.net.URL;
 
 /**
- * Creates a <code>DataSource</code> based on an URL.
+ * A composite data source resolver. It allows to resolve data sources coming from
+ * multiple locations such as the classpath, the file system or an URL.
  *
  * @since 1.3
  */
-public class DataSourceResolverImpl implements DataSourceResolver
+public class DataSourceCompositeResolver extends DataSourceBaseResolver
 {
-    /**  the base url of the resource when resolving relative paths */
-    private final URL baseUrl;
+    /** the list of resolvers */
+    private DataSourceResolver[] dataSourceResolvers;
 
-    /** shall we ignore resources not found or complain with an exception */
-    private final boolean isLenient;
-
-    /**
-     * Constructor.
-     *
-     * @param baseUrl the base URL used for resolving relative resource locations
-     */
-    public DataSourceResolverImpl(URL baseUrl)
+    public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers)
     {
-        this(baseUrl, false);
+        this.dataSourceResolvers = new DataSourceResolver[dataSourceResolvers.length];
+        System.arraycopy(dataSourceResolvers, 0, this.dataSourceResolvers, 0, dataSourceResolvers.length);
     }
 
-    /**
-     * Constructor.
-     *
-     * @param baseUrl the base URL used for resolving relative resource locations
-     * @param lenient shall we ignore resources not found or complain with an exception
-     */
-    public DataSourceResolverImpl(URL baseUrl, boolean lenient)
+    public DataSourceCompositeResolver(final DataSourceResolver[] dataSourceResolvers, final boolean isLenient)
     {
-        this.baseUrl = baseUrl;
-        this.isLenient = lenient;
+        super(isLenient);
+        this.dataSourceResolvers = new DataSourceResolver[dataSourceResolvers.length];
+        System.arraycopy(dataSourceResolvers, 0, this.dataSourceResolvers, 0, dataSourceResolvers.length);
     }
 
-    /**
-     * Get the base URL used for resolving relative resource locations.
-     *
-     * @return the baseUrl
-     */
-    public URL getBaseUrl()
+    public DataSourceResolver[] getDataSourceResolvers()
     {
-        return baseUrl;
+        return dataSourceResolvers;
     }
 
-    /**
-     * Shall we ignore resources not found or throw an exception?
-     *
-     * @return the lenient flag
-     */
-    public boolean isLenient()
+    public DataSource resolve(String resourceLocation) throws IOException
     {
-        return isLenient;
+        DataSource result = resolve(resourceLocation, true);
+
+        if (isLenient() || result != null)
+        {
+            return result;
+        }
+        else
+        {
+            throw new IOException("The following resource was not found : " + resourceLocation);
+        }
+
     }
 
-    /**
-     * Resolve a resource location to be embedded into the email. When using
-     * the lenient mode a resource which can't be resolved returns "null".
-     * When using the non-lenient mode an exception would be thrown.
-     *
-     * @param resourceLocation the location of the resource
-     * @return the data source containing the resource
-     * @throws IOException resolving the resource failed
-     */
-    public DataSource resolve(String resourceLocation) throws IOException
+    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
     {
-        DataSource result = null;
-
-        try
+        for (int i = 0; i < getDataSourceResolvers().length; i++)
         {
-            if (!resourceLocation.startsWith("cid:"))
+            DataSourceResolver dataSourceResolver = getDataSourceResolvers()[i];
+            DataSource dataSource = dataSourceResolver.resolve(resourceLocation, isLenient);
+
+            if (dataSource != null)
             {
-                URL url = URLFactory.createUrl(getBaseUrl(), resourceLocation);
-                result = new URLDataSource(url);
-                result.getInputStream();
+                return dataSource;
             }
+        }
 
-            return result;
+        if (isLenient)
+        {
+            return null;
         }
-        catch (IOException e)
+        else
         {
-            if (isLenient())
-            {
-                return null;
-            }
-            else
-            {
-                throw e;
-            }
+            throw new IOException("The following resource was not found : " + resourceLocation);
         }
     }
 }

Propchange: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceCompositeResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java (added)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceFileResolver.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Creates a <code>DataSource</code> based on an URL. The implementation
+ * also resolves file resources.
+ *
+ * @since 1.3
+ */
+public class DataSourceFileResolver extends DataSourceBaseResolver
+{
+    /** the base directory of the resource when resolving relative paths */
+    private final File baseDir;
+
+    public DataSourceFileResolver()
+    {
+        baseDir = new File(".");
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory of the resource when resolving relative paths
+     */
+    public DataSourceFileResolver(final File baseDir)
+    {
+        this.baseDir = baseDir;
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param baseDir the base directory of the resource when resolving relative paths
+     * @param lenient shall we ignore resources not found or complain with an exception
+     */
+    public DataSourceFileResolver(final File baseDir, final boolean lenient)
+    {
+        super(lenient);
+        this.baseDir = baseDir;
+    }
+
+    /**
+     * Get the base directory used for resolving relative resource locations.
+     *
+     * @return the baseUrl
+     */
+    public File getBaseDir()
+    {
+        return baseDir;
+    }
+
+    public DataSource resolve(final String resourceLocation) throws IOException
+    {
+        return resolve(resourceLocation, isLenient());
+    }
+
+    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
+    {
+        File file;
+        DataSource result = null;
+
+        if (!isCid(resourceLocation))
+        {
+            file = new File(resourceLocation);
+
+            if (!file.isAbsolute())
+            {
+                file = (getBaseDir() != null ? new File(getBaseDir(), resourceLocation) : new File(resourceLocation));
+            }
+
+            if (file.exists())
+            {
+                result = new FileDataSource(file);
+            }
+            else
+            {
+                if (!isLenient)
+                {
+                    throw new IOException("Cant resolve the following file resource :" + file.getAbsolutePath());
+                }
+            }
+        }
+
+        return result;
+    }
+}

Added: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceUrlResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceUrlResolver.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceUrlResolver.java (added)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/DataSourceUrlResolver.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import javax.activation.DataSource;
+import javax.activation.URLDataSource;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Creates a <code>DataSource</code> based on an URL.
+ *
+ * @since 1.3
+ */
+public class DataSourceUrlResolver extends DataSourceBaseResolver
+{
+    /** the base url of the resource when resolving relative paths */
+    private final URL baseUrl;
+
+    /**
+     * Constructor.
+     *
+     * @param baseUrl the base URL used for resolving relative resource locations
+     */
+    public DataSourceUrlResolver(final URL baseUrl)
+    {
+        super();
+        this.baseUrl = baseUrl;
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param baseUrl the base URL used for resolving relative resource locations
+     * @param lenient shall we ignore resources not found or complain with an exception
+     */
+    public DataSourceUrlResolver(final URL baseUrl, final boolean lenient)
+    {
+        super(lenient);
+        this.baseUrl = baseUrl;
+    }
+
+    /**
+     * Get the base URL used for resolving relative resource locations.
+     *
+     * @return the baseUrl
+     */
+    public URL getBaseUrl()
+    {
+        return baseUrl;
+    }
+
+    public DataSource resolve(String resourceLocation) throws IOException
+    {
+        return resolve(resourceLocation, isLenient());
+    }
+
+    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
+    {
+        DataSource result = null;
+
+        try
+        {
+            if (!isCid(resourceLocation))
+            {
+                URL url = createUrl(resourceLocation);
+                result = new URLDataSource(url);
+                result.getInputStream();
+            }
+
+            return result;
+        }
+        catch (IOException e)
+        {
+            if (isLenient)
+            {
+                return null;
+            }
+            else
+            {
+                throw e;
+            }
+        }
+    }
+
+    /**
+     * Create an URL based on a base URL and a resource location suitable for loading
+     * the resource.
+     *
+     * @param resourceLocation a resource location
+     * @return the corresponding URL
+     * @throws java.net.MalformedURLException creating the URL failed
+     */
+    private URL createUrl(final String resourceLocation) throws MalformedURLException
+    {
+        // if we get an non-existing base url than the resource can
+        // be directly used to create an URL
+        if (baseUrl == null)
+        {
+            return new URL(resourceLocation);
+        }
+
+        // if we get an non-existing location what we shall do?
+        if (resourceLocation == null || resourceLocation.length() == 0)
+        {
+            throw new IllegalArgumentException("No resource defined");
+        }
+
+        // if we get a stand-alone resource than ignore the base url
+        if (isFileUrl(resourceLocation) || isHttpUrl(resourceLocation))
+        {
+            return new URL(resourceLocation);
+        }
+
+        return new URL(getBaseUrl(), resourceLocation.replaceAll("&amp;", "&"));
+    }
+}

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/package.html
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/package.html?rev=1200553&r1=1165862&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/package.html (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/resolver/package.html Thu Nov 10 21:14:42 2011
@@ -17,7 +17,12 @@
 <html>
 <body>
 <p>
-    Contains implemetation classes.
+    Contains implementation classes to resolve data sources from the following locations
+    <ul>
+        <li>class path</li>
+        <li>file system</li>
+        <li>URL</li>
+    </ul>
 </p>
 </body>
 </html>

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/util/MimeMessageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/util/MimeMessageParser.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/util/MimeMessageParser.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/util/MimeMessageParser.java Thu Nov 10 21:14:42 2011
@@ -66,7 +66,7 @@ public class MimeMessageParser
      *
      * @param message the message to parse
      */
-    public MimeMessageParser(MimeMessage message)
+    public MimeMessageParser(final MimeMessage message)
     {
         attachmentList = new ArrayList();
         this.mimeMessage = message;
@@ -309,12 +309,12 @@ public class MimeMessageParser
     {
         String result = dataSource.getName();
 
-        if(result == null || result.length() == 0)
+        if (result == null || result.length() == 0)
         {
             result = part.getFileName();
         }
 
-        if(result != null && result.length() > 0)
+        if (result != null && result.length() > 0)
         {
             result = MimeUtility.decodeText( result );
         }

Modified: commons/proper/email/trunk/src/java/org/apache/commons/mail/util/URLFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/java/org/apache/commons/mail/util/URLFactory.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/java/org/apache/commons/mail/util/URLFactory.java (original)
+++ commons/proper/email/trunk/src/java/org/apache/commons/mail/util/URLFactory.java Thu Nov 10 21:14:42 2011
@@ -16,9 +16,7 @@
  */
 package org.apache.commons.mail.util;
 
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.nio.charset.Charset;
 
 /**
  * Create an URL for embedding a resource.
@@ -28,105 +26,15 @@ import java.net.URL;
 public final class URLFactory
 {
     /**
-     * Instances should NOT be constructed in standard programming.
-     */
-    private URLFactory()
-    {
-        super();
-    }
-
-    /**
-     * Create an URL based on a base URL and a resource location suitable for loading
-     * the resource.
-     *
-     * @param baseUrl an optional base URL
-     * @param resource a resource location
-     * @return the corresponding URL
-     * @throws java.net.MalformedURLException creating the URL failed
-     */
-    public static URL createUrl(final URL baseUrl, final String resource) throws MalformedURLException
-    {
-        // if we get an non-existing base url than the resource can
-        // be directly used to create an URL
-        if (baseUrl == null)
-        {
-            return new URL(resource);
-        }
-
-        // if we get an non-existing location what we shall do?
-        if (resource == null)
-        {
-            throw new IllegalArgumentException("No resource defined");
-        }
-
-        // if we get a stand-alone resource than ignore the base url
-        if (isFileUrl(resource) || isHttpUrl(resource))
-        {
-            return new URL(resource);
-        }
-
-        // crate a file URL
-        String baseUrlString = baseUrl.toExternalForm();
-        if (isFileUrl(baseUrlString))
-        {
-            return new File(toFile(baseUrl), resource).toURI().toURL();
-        }
-        else
-        {
-            return new URL(baseUrl, resource.replaceAll("&amp;", "&"));
-        }
-    }
-
-    /**
-     * Is this a file URL?
-     *
-     * @param urlString the URL string
-     * @return true if it is a file URL
+     * The UTF-8 character set, used to decode octets in URLs.
      */
-    private static boolean isFileUrl(String urlString)
-    {
-        return urlString.startsWith("file:/");
-    }
+    private static final Charset UTF8 = Charset.forName("UTF-8");
 
     /**
-     * Is this a HTTP/HTTPS URL?
-     *
-     * @param urlString the URL string
-     * @return true if it is a HTTP/HTTPS URL
-     */
-    private static boolean isHttpUrl(String urlString)
-    {
-        return urlString.startsWith("http://") || urlString.startsWith("https://");
-    }
-
-    /**
-     * Convert from a <code>URL</code> to a <code>File</code>.
-     *
-     * @param url  the file URL to convert, <code>null</code> returns <code>null</code>
-     * @return the equivalent <code>File</code> object, or <code>null</code>
-     *  if the URL's protocol is not <code>file</code>
-     * @throws IllegalArgumentException if the file is incorrectly encoded
+     * Instances should NOT be constructed in standard programming.
      */
-    private static File toFile(URL url)
+    private URLFactory()
     {
-        if (url == null || !url.getProtocol().equals("file"))
-        {
-            return null;
-        }
-        else
-        {
-            String filename = url.getFile().replace('/', File.separatorChar);
-            int pos = 0;
-            while ((pos = filename.indexOf('%', pos)) >= 0)
-            {
-                if (pos + 2 < filename.length())
-                {
-                    String hexStr = filename.substring(pos + 1, pos + 3);
-                    char ch = (char) Integer.parseInt(hexStr, 16);
-                    filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
-                }
-            }
-            return new File(filename);
-        }
+        super();
     }
 }

Added: commons/proper/email/trunk/src/test/attachments/autoloadertest.html
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/attachments/autoloadertest.html?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/attachments/autoloadertest.html (added)
+++ commons/proper/email/trunk/src/test/attachments/autoloadertest.html Thu Nov 10 21:14:42 2011
@@ -0,0 +1,28 @@
+<!--
+Copyright 2011 The Apache Software Foundation.
+
+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.
+-->
+<!DOCTYPE html>
+<html>
+   <head>
+      <title></title>
+      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+   </head>
+   <body>
+      <div>
+         <h1>Auto Loader Test</h1>
+         <img src="images/asf_logo_wide.gif"/>
+      </div>
+   </body>
+</html>

Added: commons/proper/email/trunk/src/test/attachments/classpathtest.html
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/attachments/classpathtest.html?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/attachments/classpathtest.html (added)
+++ commons/proper/email/trunk/src/test/attachments/classpathtest.html Thu Nov 10 21:14:42 2011
@@ -0,0 +1,28 @@
+<!--
+Copyright 2011 The Apache Software Foundation.
+
+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.
+-->
+<!DOCTYPE html>
+<html>
+   <head>
+      <title></title>
+      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+   </head>
+   <body>
+      <div>
+         <h1>Classpath Resolver Test</h1>
+         <img src="images/asf_logo_wide.gif"/>
+      </div>
+   </body>
+</html>

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/EmailLiveTest.java Thu Nov 10 21:14:42 2011
@@ -18,7 +18,7 @@ package org.apache.commons.mail;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.commons.mail.impl.DataSourceResolverImpl;
+import org.apache.commons.mail.resolver.DataSourceUrlResolver;
 import org.apache.commons.mail.settings.EmailConfiguration;
 
 import javax.activation.DataSource;
@@ -268,7 +268,7 @@ public class EmailLiveTest extends BaseE
         String htmlMsg1 = FileUtils.readFileToString(htmlFile);
 
         ImageHtmlEmail email = (ImageHtmlEmail) create(ImageHtmlEmail.class);
-        email.setDataSourceResolver(new DataSourceResolverImpl(htmlFile.getParentFile().toURI().toURL(), false));
+        email.setDataSourceResolver(new DataSourceUrlResolver(htmlFile.getParentFile().toURI().toURL(), false));
         email.setSubject("[testImageHtmlEmail] 1.Test: simple html content");
         email.setHtmlMsg(htmlMsg1);
 
@@ -288,11 +288,11 @@ public class EmailLiveTest extends BaseE
         if(EmailConfiguration.MAIL_FORCE_SEND)
         {
             URL url = new URL("http://commons.apache.org/email/");
-            // URL url = new URL("http://nemo.sonarsource.org/project/index/221295?page_id=2");
+            // URL url = new URL("http://www.dzone.com/links/index.html");
             String htmlMsg = getFromUrl(url);
 
             ImageHtmlEmail email = (ImageHtmlEmail) create(ImageHtmlEmail.class);
-            email.setDataSourceResolver(new DataSourceResolverImpl(url, false));
+            email.setDataSourceResolver(new DataSourceUrlResolver(url, true));
             email.setSubject("[testImageHtmlEmail] 2.Test: complex html content");
             email.setHtmlMsg(htmlMsg);
 

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/ImageHtmlEmailTest.java Thu Nov 10 21:14:42 2011
@@ -16,6 +16,17 @@
  */
 package org.apache.commons.mail;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.resolver.DataSourceClassPathResolver;
+import org.apache.commons.mail.resolver.DataSourceCompositeResolver;
+import org.apache.commons.mail.resolver.DataSourceUrlResolver;
+import org.apache.commons.mail.mocks.MockImageHtmlEmailConcrete;
+import org.apache.commons.mail.util.MimeMessageParser;
+import org.apache.commons.mail.util.MimeMessageUtils;
+import org.subethamail.wiser.WiserMessage;
+
+import javax.mail.internet.MimeMessage;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -26,264 +37,340 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import javax.mail.internet.MimeMessage;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.mail.impl.DataSourceResolverImpl;
-import org.apache.commons.mail.mocks.MockImageHtmlEmailConcrete;
-import org.apache.commons.mail.util.MimeMessageParser;
-import org.subethamail.wiser.WiserMessage;
-
 public class ImageHtmlEmailTest extends HtmlEmailTest {
 
     private static final boolean TEST_IS_LENIENT = true;
-    private static final URL TEST_IMAGE_URL = ImageHtmlEmailTest.class.getResource("/images/asf_logo_wide.gif");    
+    private static final URL TEST_IMAGE_URL = ImageHtmlEmailTest.class.getResource("/images/asf_logo_wide.gif");
     private static final File TEST_IMAGE_DIR = new File(TEST_IMAGE_URL.getPath()).getParentFile();
     private static final URL TEST_HTML_URL = ImageHtmlEmailTest.class.getResource("/attachments/download_email.cgi.html");
+    private static final URL TEST2_HTML_URL = ImageHtmlEmailTest.class.getResource("/attachments/classpathtest.html");
 
     private MockImageHtmlEmailConcrete email;
 
     public ImageHtmlEmailTest(String name) throws IOException {
-		super(name);
-	}
+        super(name);
+    }
 
-	protected void setUp() throws Exception {
-		super.setUp();
-		// reusable objects to be used across multiple tests
-		email = new MockImageHtmlEmailConcrete();
-	}
+    protected void setUp() throws Exception {
+        super.setUp();
+        // reusable objects to be used across multiple tests
+        email = new MockImageHtmlEmailConcrete();
+    }
 
     // ======================================================================
     // Start of Tests
     // ======================================================================
 
-	public void testSendHtml() throws Exception {
+    public void testSendHtml() throws Exception {
 
-		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
 
-		// Create the email message
-		getMailServer();
+        // Create the email message
+        getMailServer();
 
-		String strSubject = "Test HTML Send default";
+        String strSubject = "Test HTML Send default";
 
-		email = new MockImageHtmlEmailConcrete();
-        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
-		email.setHostName(strTestMailServer);
-		email.setSmtpPort(getMailServerPort());
-		email.setFrom(strTestMailFrom);
-		email.addTo(strTestMailTo);
-		email.setSubject(strSubject);
-
-		URL url = TEST_HTML_URL;
-		InputStream stream = url.openStream();
-		StringBuffer str = new StringBuffer();
-		try {
-			List lines = IOUtils.readLines(stream);
-			for(int i=0;i<lines.size();i++) {
-                String line = (String) lines.get(i);
-				str.append(line).append("\n");
-			}
-		} finally {
-			stream.close();
-		}
-		String html = str.toString();
-
-		// set the html message
-		email.setHtmlMsg(html);
-
-		// set the alternative message
-		email.setTextMsg("Your email client does not support HTML messages");
+        email = new MockImageHtmlEmailConcrete();
+        email.setDataSourceResolver(new DataSourceUrlResolver(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+
+        String html = loadUrlContent(TEST_HTML_URL);
 
-		// send the email
-		email.send();
+        // set the html message
+        email.setHtmlMsg(html);
 
-		fakeMailServer.stop();
+        // set the alternative message
+        email.setTextMsg("Your email client does not support HTML messages");
+
+        // send the email
+        email.send();
+
+        fakeMailServer.stop();
+
+        assertEquals(1, fakeMailServer.getMessages().size());
+        MimeMessage mimeMessage = ((WiserMessage) fakeMailServer.getMessages().get(0)).getMimeMessage();
 
-		assertEquals(1, fakeMailServer.getMessages().size());
-		MimeMessage mimeMessage = ((WiserMessage) fakeMailServer.getMessages().get(0)).getMimeMessage();
         MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse();
         assertTrue(mimeMessageParser.getHtmlContent().indexOf("\"cid:") >= 0);
         assertTrue(mimeMessageParser.getAttachmentList().size() == 3);
-	}
+    }
+
+    public void testSendEmptyHTML() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        ImageHtmlEmail email = new ImageHtmlEmail();
+
+        // set the html message
+        try {
+            email.setHtmlMsg(null);
+            fail("Should fail here!");
+        } catch (EmailException e) {
+            assertTrue(e.getMessage(), e.getMessage().indexOf(
+                    "Invalid message supplied") >= 0);
+        }
+    }
+
+    public void testSendEmptyHTML2() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        ImageHtmlEmail email = new ImageHtmlEmail();
+
+        // set the html message
+        try {
+            email.setHtmlMsg("");
+            fail("Should fail here!");
+        } catch (EmailException e) {
+            assertTrue(e.getMessage(), e.getMessage().indexOf(
+                    "Invalid message supplied") >= 0);
+        }
+
+    }
+
+    public void testSendHtmlUrl() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        getMailServer();
+
+        String strSubject = "Test HTML Send default with URL";
+
+        // Create the email message
+        email = new MockImageHtmlEmailConcrete();
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+        email.setDataSourceResolver(new DataSourceUrlResolver(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
+
+        // set the html message
+        email.setHtmlMsg(
+                "<html><body><img src=\"http://www.apache.org/images/feather.gif\"/></body></html>"
+        );
+
+        // send the email
+        email.send();
+
+        fakeMailServer.stop();
+        // validate txt message
+        validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
+                email.getFromAddress(), email.getToAddresses(),
+                email.getCcAddresses(), email.getBccAddresses(), true);
+    }
+
+    public void testSendHTMLAbsoluteLocalFile() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        getMailServer();
+
+        String strSubject = "Test HTML Send default with absolute local path";
+
+        // Create the email message
+        email = new MockImageHtmlEmailConcrete();
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+        email.setDataSourceResolver(new DataSourceUrlResolver(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
+
+        File file = File.createTempFile("emailtest", ".tst");
+        FileUtils.writeStringToFile(file,
+                "just some silly data that we won't be able to display anyway");
+
+        // set the html message
+        email.setHtmlMsg("<html><body><img src=\"" + file.getAbsolutePath()
+                + "\"/></body></html>"
+        );
+
+        // send the email
+        email.send();
+
+        fakeMailServer.stop();
+        // validate txt message
+        validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
+                email.getFromAddress(), email.getToAddresses(),
+                email.getCcAddresses(), email.getBccAddresses(), true);
+    }
+
+    public void testSendHTMLClassPathFile() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        getMailServer();
+
+        String strSubject = "Test HTML Send default";
+
+        email = new MockImageHtmlEmailConcrete();
+        email.setDataSourceResolver(new DataSourceClassPathResolver("/", TEST_IS_LENIENT));
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+
+        String html = loadUrlContent(TEST2_HTML_URL);
+
+        // set the html message
+        email.setHtmlMsg(html);
+
+        // set the alternative message
+        email.setTextMsg("Your email client does not support HTML messages");
+
+        // send the email
+        email.send();
+
+        fakeMailServer.stop();
+
+        assertEquals(1, fakeMailServer.getMessages().size());
+        MimeMessage mimeMessage = ((WiserMessage) fakeMailServer.getMessages().get(0)).getMimeMessage();
+        MimeMessageUtils.writeMimeMessage(mimeMessage, new File("./target/test-emails/testSendHTMLClassPathFile.eml"));
+
+        MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse();
+        assertTrue(mimeMessageParser.getHtmlContent().indexOf("\"cid:") >= 0);
+        assertTrue(mimeMessageParser.getAttachmentList().size() == 1);
+    }
+
+    public void testSendHTMLAutoResolveFile() throws Exception {
+        Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+
+        // Create the email message
+        getMailServer();
+
+        String strSubject = "Test HTML Send default";
+
+        email = new MockImageHtmlEmailConcrete();
+        DataSourceResolver dataSourceResolvers[] = new DataSourceResolver[2];
+        dataSourceResolvers[0] = new DataSourceUrlResolver(new URL("http://foo"), true);
+        dataSourceResolvers[1] = new DataSourceClassPathResolver("/", true);
+
+        email.setDataSourceResolver(new DataSourceCompositeResolver(dataSourceResolvers));
+        email.setHostName(strTestMailServer);
+        email.setSmtpPort(getMailServerPort());
+        email.setFrom(strTestMailFrom);
+        email.addTo(strTestMailTo);
+        email.setSubject(strSubject);
+
+        String html = loadUrlContent(TEST2_HTML_URL);
+
+        // set the html message
+        email.setHtmlMsg(html);
+
+        // set the alternative message
+        email.setTextMsg("Your email client does not support HTML messages");
 
-	public void testSendEmptyHTML() throws Exception {
-		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
+        // send the email
+        email.send();
 
-		// Create the email message
-		ImageHtmlEmail email = new ImageHtmlEmail();
+        fakeMailServer.stop();
+
+        assertEquals(1, fakeMailServer.getMessages().size());
+        MimeMessage mimeMessage = ((WiserMessage) fakeMailServer.getMessages().get(0)).getMimeMessage();
+        MimeMessageUtils.writeMimeMessage(mimeMessage, new File("./target/test-emails/testSendHTMLAutoFile.eml"));
+
+        MimeMessageParser mimeMessageParser = new MimeMessageParser(mimeMessage).parse();
+        assertTrue(mimeMessageParser.getHtmlContent().indexOf("\"cid:") >= 0);
+        assertTrue(mimeMessageParser.getAttachmentList().size() == 1);
+    }
+
+    public void testRegex() {
+        Pattern pattern = Pattern.compile(ImageHtmlEmail.REGEX_IMG_SRC);
+
+        // ensure that the regex that we use is catching the cases correctly
+        Matcher matcher = pattern
+                .matcher("<html><body><img src=\"h\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("h", matcher.group(2));
+
+        matcher = pattern
+                .matcher("<html><body><img id=\"laskdasdkj\" src=\"h\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("h", matcher.group(2));
+
+        // uppercase
+        matcher = pattern
+                .matcher("<html><body><IMG id=\"laskdasdkj\" SRC=\"h\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("h", matcher.group(2));
+
+        // matches twice
+        matcher = pattern
+                .matcher("<html><body><img id=\"laskdasdkj\" src=\"http://dstadler1.org/\"/><img id=\"laskdasdkj\" src=\"http://dstadler2.org/\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler1.org/", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler2.org/", matcher.group(2));
+
+        // what about newlines
+        matcher = pattern
+                .matcher("<html><body><img\n \rid=\"laskdasdkj\"\n \rsrc=\"http://dstadler1.org/\"/><img id=\"laskdasdkj\" src=\"http://dstadler2.org/\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler1.org/", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler2.org/", matcher.group(2));
+
+        // what about newlines and other whitespaces
+        matcher = pattern
+                .matcher("<html><body><img\n \t\rid=\"laskdasdkj\"\n \rsrc \n =\r  \"http://dstadler1.org/\"/><img  \r  id=\" laskdasdkj\"    src    =   \"http://dstadler2.org/\"/></body></html>");
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler1.org/", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("http://dstadler2.org/", matcher.group(2));
 
-		// set the html message
-		try {
-			email.setHtmlMsg(null);
-			fail("Should fail here!");
-		} catch (EmailException e) {
-			assertTrue(e.getMessage(), e.getMessage().indexOf(
-					"Invalid message supplied") >= 0);
-		}
-	}
-
-	public void testSendEmptyHTML2() throws Exception {
-		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
-
-		// Create the email message
-		ImageHtmlEmail email = new ImageHtmlEmail();
-
-		// set the html message
-		try {
-			email.setHtmlMsg("");
-			fail("Should fail here!");
-		} catch (EmailException e) {
-			assertTrue(e.getMessage(), e.getMessage().indexOf(
-					"Invalid message supplied") >= 0);
-		}
-
-	}
-
-	public void testSendHtmlUrl() throws Exception {
-		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
-
-		getMailServer();
-
-		String strSubject = "Test HTML Send default with URL";
-
-		// Create the email message
-		email = new MockImageHtmlEmailConcrete();
-		email.setHostName(strTestMailServer);
-		email.setSmtpPort(getMailServerPort());
-		email.setFrom(strTestMailFrom);
-		email.addTo(strTestMailTo);
-		email.setSubject(strSubject);
-        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
-
-		// set the html message
-		email.setHtmlMsg(
-            "<html><body><img src=\"http://www.apache.org/images/feather.gif\"/></body></html>"
-            );
-
-		// send the email
-		email.send();
-
-		fakeMailServer.stop();
-		// validate txt message
-		validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
-				email.getFromAddress(), email.getToAddresses(),
-				email.getCcAddresses(), email.getBccAddresses(), true);
-	}
-
-	public void testSendHTMLAbsoluteLocalFile() throws Exception {
-		Logger.getLogger(ImageHtmlEmail.class.getName()).setLevel(Level.FINEST);
-
-		// Create the email message
-		getMailServer();
-
-		String strSubject = "Test HTML Send default with absolute local path";
-
-		// Create the email message
-		email = new MockImageHtmlEmailConcrete();
-		email.setHostName(strTestMailServer);
-		email.setSmtpPort(getMailServerPort());
-		email.setFrom(strTestMailFrom);
-		email.addTo(strTestMailTo);
-		email.setSubject(strSubject);
-        email.setDataSourceResolver(new DataSourceResolverImpl(TEST_IMAGE_DIR.toURI().toURL(), TEST_IS_LENIENT));
-
-		File file = File.createTempFile("emailtest", ".tst");
-		FileUtils.writeStringToFile(file,
-				"just some silly data that we won't be able to display anyway");
-
-		// set the html message
-		email.setHtmlMsg("<html><body><img src=\"" + file.getAbsolutePath()
-				+ "\"/></body></html>"
-            );
-
-		// send the email
-		email.send();
-
-		fakeMailServer.stop();
-		// validate txt message
-		validateSend(fakeMailServer, strSubject, email.getHtmlMsg(),
-				email.getFromAddress(), email.getToAddresses(),
-				email.getCcAddresses(), email.getBccAddresses(), true);
-	}
-
-	public void testRegex() 
-	{	
-		Pattern pattern = Pattern.compile(ImageHtmlEmail.REGEX_IMG_SRC);
-
-		// ensure that the regex that we use is catching the cases correctly
-		Matcher matcher = pattern
-				.matcher("<html><body><img src=\"h\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("h", matcher.group(2));
-
-		matcher = pattern
-				.matcher("<html><body><img id=\"laskdasdkj\" src=\"h\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("h", matcher.group(2));
-
-		// uppercase
-		matcher = pattern
-				.matcher("<html><body><IMG id=\"laskdasdkj\" SRC=\"h\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("h", matcher.group(2));
-
-		// matches twice
-		matcher = pattern
-				.matcher("<html><body><img id=\"laskdasdkj\" src=\"http://dstadler1.org/\"/><img id=\"laskdasdkj\" src=\"http://dstadler2.org/\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler1.org/", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler2.org/", matcher.group(2));
-
-		// what about newlines
-		matcher = pattern
-				.matcher("<html><body><img\n \rid=\"laskdasdkj\"\n \rsrc=\"http://dstadler1.org/\"/><img id=\"laskdasdkj\" src=\"http://dstadler2.org/\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler1.org/", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler2.org/", matcher.group(2));
-
-		// what about newlines and other whitespaces
-		matcher = pattern
-				.matcher("<html><body><img\n \t\rid=\"laskdasdkj\"\n \rsrc \n =\r  \"http://dstadler1.org/\"/><img  \r  id=\" laskdasdkj\"    src    =   \"http://dstadler2.org/\"/></body></html>");
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler1.org/", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("http://dstadler2.org/", matcher.group(2));
-		
         // what about some real markup
         matcher = pattern.matcher("<img alt=\"Chart?ck=xradar&amp;w=120&amp;h=120&amp;c=7fff00|7fff00&amp;m=4&amp;g=0\" src=\"/chart?ck=xradar&amp;w=120&amp;h=120&amp;c=7fff00|7fff00&amp;m=4&amp;g=0.2&amp;l=A,C,S,T&amp;v=3.0,3.0,2.0,2.0\"");
         assertTrue(matcher.find());
         assertEquals("/chart?ck=xradar&amp;w=120&amp;h=120&amp;c=7fff00|7fff00&amp;m=4&amp;g=0.2&amp;l=A,C,S,T&amp;v=3.0,3.0,2.0,2.0", matcher.group(2));
-        
+
         // had a problem with multiple img-source tags
-		matcher = pattern
-				.matcher("<img src=\"file1\"/><img src=\"file2\"/>");
-		assertTrue(matcher.find());
-		assertEquals("file1", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file2", matcher.group(2));
-
-		matcher = pattern
-				.matcher("<img src=\"file1\"/><img src=\"file2\"/><img src=\"file3\"/><img src=\"file4\"/><img src=\"file5\"/>");
-		assertTrue(matcher.find());
-		assertEquals("file1", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file2", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file3", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file4", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file5", matcher.group(2));
-
-		// try with invalid HTML that is seens sometimes, i.e. without closing "/" or "</img>"
-		matcher = pattern
-				.matcher("<img src=\"file1\"><img src=\"file2\">");
-		assertTrue(matcher.find());
-		assertEquals("file1", matcher.group(2));
-		assertTrue(matcher.find());
-		assertEquals("file2", matcher.group(2));        
-	}
+        matcher = pattern
+                .matcher("<img src=\"file1\"/><img src=\"file2\"/>");
+        assertTrue(matcher.find());
+        assertEquals("file1", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file2", matcher.group(2));
+
+        matcher = pattern
+                .matcher("<img src=\"file1\"/><img src=\"file2\"/><img src=\"file3\"/><img src=\"file4\"/><img src=\"file5\"/>");
+        assertTrue(matcher.find());
+        assertEquals("file1", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file2", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file3", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file4", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file5", matcher.group(2));
+
+        // try with invalid HTML that is seens sometimes, i.e. without closing "/" or "</img>"
+        matcher = pattern
+                .matcher("<img src=\"file1\"><img src=\"file2\">");
+        assertTrue(matcher.find());
+        assertEquals("file1", matcher.group(2));
+        assertTrue(matcher.find());
+        assertEquals("file2", matcher.group(2));
+    }
+
+    private String loadUrlContent(URL url) throws IOException {
+        InputStream stream = url.openStream();
+        StringBuffer str = new StringBuffer();
+        try {
+            List lines = IOUtils.readLines(stream);
+            for (int i = 0; i < lines.size(); i++) {
+                String line = (String) lines.get(i);
+                str.append(line).append("\n");
+            }
+        } finally {
+            stream.close();
+        }
+        String html = str.toString();
+        return html;
+    }
 }

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceClassPathResolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceClassPathResolverTest.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceClassPathResolverTest.java (added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceClassPathResolverTest.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.DataSourceResolver;
+
+import javax.activation.DataSource;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * JUnit test case for DataSourceClassPathResolver..
+ *
+ * @since 1.3
+ */
+
+public class DataSourceClassPathResolverTest extends TestCase
+{
+    private final int IMG_SIZE = 5866;
+
+    public DataSourceClassPathResolverTest(String name)
+    {
+        super(name);
+    }
+
+    // ======================================================================
+    // Start of Tests
+    // ======================================================================
+    
+    public void testResolvingClassPathLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver;
+
+        dataSourceResolver = new DataSourceClassPathResolver("/", true);
+        assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("/images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertNull(dataSourceResolver.resolve("/asf_logo_wide.gif"));
+
+        dataSourceResolver = new DataSourceClassPathResolver("/images", true);
+        assertTrue(toByteArray(dataSourceResolver.resolve("asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("./asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertNull(dataSourceResolver.resolve("./images/asf_logo_wide.gif"));
+    }
+
+    public void testResolvingClassPathNonLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver;
+
+        dataSourceResolver = new DataSourceClassPathResolver("/", false);
+        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));
+
+        try
+        {
+            dataSourceResolver.resolve("asf_logo_wide.gif");
+            fail("Expecting an IOException");
+        }
+        catch(IOException e)
+        {
+            return;
+        }
+    }
+
+    private byte[] toByteArray(DataSource dataSource) throws IOException
+    {
+        if(dataSource != null)
+        {
+            InputStream is = dataSource.getInputStream();
+            return IOUtils.toByteArray(is);
+        }
+        else
+        {
+            return null;
+        }
+    }
+
+}

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java (added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.DataSourceResolver;
+
+import javax.activation.DataSource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * JUnit test case for DateSourceResolver.
+ *
+ * @since 1.3
+ */
+
+public class DataSourceCompositeResolverTest extends TestCase
+{
+    public DataSourceCompositeResolverTest(String name)
+    {
+        super(name);
+    }
+
+    public void testResolvingFilesLenient() throws Exception
+    {
+        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
+        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images", false);
+        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver, classPathResolver };
+        DataSourceResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, true);
+
+        // resolve using HTTP
+        assertTrue(toByteArray(dataSourceResolver.resolve("/images/feather-small.gif")).length > 0);
+
+        // resolve using class path
+        assertTrue(toByteArray(dataSourceResolver.resolve("/contentTypeTest.gif")).length > 0);
+    }
+
+    public void testResolvingFilesNonLenient() throws Exception
+    {
+        DataSourceResolver urlResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
+        DataSourceResolver classPathResolver = new DataSourceClassPathResolver("/images", false);
+        DataSourceResolver[] dataSourceResolvers = new DataSourceResolver[] { urlResolver, classPathResolver };
+        DataSourceResolver dataSourceResolver = new DataSourceCompositeResolver(dataSourceResolvers, false);
+
+        try
+        {
+            dataSourceResolver.resolve("./image/does-not-exist.gif");
+            fail("Expected an IOException");
+        }
+        catch(IOException e)
+        {
+            // expected
+            return;
+        }
+    }
+
+    private byte[] toByteArray(DataSource dataSource) throws IOException
+    {
+        if(dataSource != null)
+        {
+            InputStream is = dataSource.getInputStream();
+            return IOUtils.toByteArray(is);
+        }
+        else
+        {
+            return null;
+        }
+    }
+}

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceFileResolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceFileResolverTest.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceFileResolverTest.java (added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceFileResolverTest.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.DataSourceResolver;
+
+import javax.activation.DataSource;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * JUnit test case for DateSourceResolver.
+ *
+ * @since 1.3
+ */
+
+public class DataSourceFileResolverTest extends TestCase
+{
+    private final int IMG_SIZE = 5866;
+
+    public DataSourceFileResolverTest(String name)
+    {
+        super(name);
+    }
+
+    public void testResolvingFileLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceFileResolver(new File("./src/test"), true);
+        assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("../test/images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertNull(toByteArray(dataSourceResolver.resolve("/images/asf_logo_wide.gif")));
+        assertNull(dataSourceResolver.resolve("./images/does-not-exist.gif"));
+    }
+
+    public void testResolvingFileNonLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceFileResolver(new File("."), false);
+        assertNotNull(dataSourceResolver.resolve("./src/test/images/asf_logo_wide.gif"));
+
+        try
+        {
+            dataSourceResolver.resolve("asf_logo_wide.gif");
+            fail("Expecting an IOException");
+        }
+        catch(IOException e)
+        {
+            return;
+        }
+    }
+
+    private byte[] toByteArray(DataSource dataSource) throws IOException
+    {
+        if(dataSource != null)
+        {
+            InputStream is = dataSource.getInputStream();
+            return IOUtils.toByteArray(is);
+        }
+        else
+        {
+            return null;
+        }
+    }
+}

Added: commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java?rev=1200553&view=auto
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java (added)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java Thu Nov 10 21:14:42 2011
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.commons.mail.resolver;
+
+import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.mail.DataSourceResolver;
+
+import javax.activation.DataSource;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * JUnit test case for DateSourceResolver.
+ *
+ * @since 1.3
+ */
+
+public class DataSourceUrlResolverTest extends TestCase
+{
+    private final int IMG_SIZE = 5866;
+
+    public DataSourceUrlResolverTest(String name)
+    {
+        super(name);
+    }
+
+    public void testResolvingFilesLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new File("./src/test").toURI().toURL(), true);
+        assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("/images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
+        assertNull(dataSourceResolver.resolve("./images/does-not-exist.gif"));
+    }
+
+    public void testResolvingHttpLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), true);
+        assertTrue(toByteArray(dataSourceResolver.resolve("http://www.apache.org/images/feather-small.gif")).length > 1);
+        assertTrue(toByteArray(dataSourceResolver.resolve("images/feather-small.gif")).length > 1);
+        assertTrue(toByteArray(dataSourceResolver.resolve("./images/feather-small.gif")).length > 1);
+        assertTrue(toByteArray(dataSourceResolver.resolve("/images/feather-small.gif")).length > 1);
+        assertNull(toByteArray(dataSourceResolver.resolve("/images/does-not-exist.gif")));
+    }
+
+
+    public void testResolvingClassPathNonLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new File("./src/test").toURI().toURL());
+        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));
+
+        try
+        {
+            dataSourceResolver.resolve("asf_logo_wide.gif");
+            fail("Expecting an IOException");
+        }
+        catch(IOException e)
+        {
+            // expected
+            return;
+        }
+    }
+
+    public void testResolvingHttpNonLenient() throws Exception
+    {
+        DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://www.apache.org"), false);
+        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));
+
+        try
+        {
+            dataSourceResolver.resolve("images/does-not-exist.gif");
+            fail("Expecting an IOException");
+        }
+        catch(IOException e)
+        {
+            // expected
+            return;
+        }
+    }
+
+    private byte[] toByteArray(DataSource dataSource) throws IOException
+    {
+        if(dataSource != null)
+        {
+            InputStream is = dataSource.getInputStream();
+            return IOUtils.toByteArray(is);
+        }
+        else
+        {
+            return null;
+        }
+    }
+}

Modified: commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java?rev=1200553&r1=1200552&r2=1200553&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java (original)
+++ commons/proper/email/trunk/src/test/org/apache/commons/mail/util/URLFactoryTest.java Thu Nov 10 21:14:42 2011
@@ -39,29 +39,4 @@ public class URLFactoryTest extends Test
     // ======================================================================
     // Start of Tests
     // ======================================================================
-    
-    public void testCreateUrl() throws Exception
-    {
-        URL url;
-        URL baseUrl;
-        String location;
-
-        // base URL + relative file name
-        location = "pom.xml";
-        baseUrl = new File("").toURI().toURL();
-        url = URLFactory.createUrl(baseUrl, location);
-        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
-
-        // base URL  + file URL
-        location = new File("pom.xml").toURI().toURL().toExternalForm();
-        baseUrl = new File("").toURI().toURL();
-        url = URLFactory.createUrl(baseUrl, location);
-        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
-
-        // file URL only
-        location = new File("pom.xml").toURI().toURL().toExternalForm();
-        baseUrl = null;
-        url = URLFactory.createUrl(baseUrl, location);
-        assertEquals(new File("pom.xml").toURI().toURL().toExternalForm(), url.toExternalForm());
-    }
 }



Mime
View raw message