scolebourne 2003/01/19 12:03:11
Modified: email gump.xml project.xml LICENSE.txt
email/src/java/org/apache/commons/mail HtmlEmail.java
Added: email/src/java/org/apache/commons/mail GenerateUniqueID.java
Log:
Remove dependency on [util] and [lang]
Fix licence
Revision Changes Path
1.3 +0 -1 jakarta-commons-sandbox/email/gump.xml
Index: gump.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/email/gump.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- gump.xml 25 Jul 2002 01:54:27 -0000 1.2
+++ gump.xml 19 Jan 2003 20:03:11 -0000 1.3
@@ -22,7 +22,6 @@
<depend project="jakarta-ant" inherit="runtime"/>
<depend project="xml-xerces"/>
- <depend project="commons-util"/>
<depend project="javamail"/>
<depend project="jaf"/>
1.8 +1 -11 jakarta-commons-sandbox/email/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/email/project.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- project.xml 17 Dec 2002 07:00:20 -0000 1.7
+++ project.xml 19 Jan 2003 20:03:11 -0000 1.8
@@ -69,17 +69,6 @@
<dependencies>
<dependency>
- <id>commons-util</id>
- <version>1.0-rc2-dev</version>
- </dependency>
-
- <!-- needed as util now depends on lang -->
- <dependency>
- <id>commons-lang</id>
- <version>SNAPSHOT</version>
- </dependency>
-
- <dependency>
<id>javamail</id>
<version>1.2</version>
</dependency>
@@ -88,6 +77,7 @@
<version>1.0.2</version>
</dependency>
</dependencies>
+
<build>
<sourceDirectory>src/java</sourceDirectory>
<unitTestSourceDirectory>src/test</unitTestSourceDirectory>
1.2 +3 -3 jakarta-commons-sandbox/email/LICENSE.txt
Index: LICENSE.txt
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/email/LICENSE.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LICENSE.txt 11 May 2002 14:29:43 -0000 1.1
+++ LICENSE.txt 19 Jan 2003 20:03:11 -0000 1.2
@@ -1,7 +1,7 @@
-/*
+/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,7 +30,7 @@
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
- * permission of the Apache Group.
+ * permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1.5 +16 -18
jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java
Index: HtmlEmail.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/HtmlEmail.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- HtmlEmail.java 17 Dec 2002 06:51:37 -0000 1.4
+++ HtmlEmail.java 19 Jan 2003 20:03:11 -0000 1.5
@@ -1,9 +1,7 @@
-package org.apache.commons.mail;
-
/* ====================================================================
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -18,21 +16,21 @@
* the documentation and/or other materials provided with the
* distribution.
*
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "Apache" and "Apache Software Foundation" and
- * "Apache Turbine" must not be used to endorse or promote products
- * derived from this software without prior written permission. For
- * written permission, please contact [EMAIL PROTECTED]
- *
- * 5. Products derived from this software may not be called "Apache",
- * "Apache Turbine", nor may "Apache" appear in their name, without
- * prior written permission of the Apache Software Foundation.
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -53,6 +51,7 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
+package org.apache.commons.mail;
import java.net.URL;
import javax.activation.DataHandler;
@@ -63,7 +62,6 @@
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
-import org.apache.commons.util.identifier.StringAlphanumeric10IdentifierFactory;
/**
* An HTML multipart email.
@@ -205,7 +203,7 @@
mbp.setDataHandler (new DataHandler(new URLDataSource(url)));
mbp.setFileName(name);
mbp.setDisposition("inline");
- String cid = StringAlphanumeric10IdentifierFactory.nextIdentifier();
+ String cid = GenerateUniqueID.getIdentifier();
mbp.addHeader("Content-ID", cid);
getHtmlContent().addBodyPart(mbp);
1.1
jakarta-commons-sandbox/email/src/java/org/apache/commons/mail/GenerateUniqueID.java
Index: GenerateUniqueID.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.mail;
import java.util.Random;
/**
* <p>Generates a unique 10+ character identifier. Useful for
* authenticating users or tracking users around. Creates a suitable
* string for session identification. Uses synchronized count and
* time to ensure uniqueness. Not guaranteed unique across JVMs, but
* fairly safe none the less.</p>
*
* <p>Originally ported from JServ internals by Jon Stevens.</p>
*
* <p>Copied from [util] as that project died. Copied to avoid single
* dependency on [lang].</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jon S. Stevens</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Neeme Praks</a>
* @author Stephen Colebourne
* @version $Id: GenerateUniqueID.java,v 1.1 2003/01/19 20:03:11 scolebourne Exp $
*/
class GenerateUniqueID
{
private static int counter = 0;
private static long lastTimeVal = 0;
private static Random randomSource = new Random();
/**
* We want to have a random string with a length of 6 characters.
* Since we encode it base-36, we modulo the random number with
* this value.
*/
protected final static long MAX_RANDOM_LEN = 2176782336L; // 36 ** 6
/**
* The identifier must be unique within the typical lifespan of a
* session; the value can roll over after that. 3 characters:
* (this means a roll over after over a day, which is much larger
* than a typical lifespan)
*/
protected final static long MAX_SESSION_LIFESPAN_TICS = 46656; // 36 ** 3
/**
* Milliseconds between different tics. The 3-character time
* string has a new value every 2 seconds.
*/
protected final static long TIC_DIFFERENCE = 2000;
/**
* <p>Generates a unique identifier. Only guaranteed unique within
* this JVM, but fairly safe for cross JVM usage as well.</p>
*
* <p>Format of identifier is
* [6 chars random][3 chars time][1+ char count].</p>
*
* @return The new unique identifier.
*/
public static synchronized String getIdentifier()
{
StringBuffer id = new StringBuffer();
// Random value.
long n = randomSource.nextLong();
if (n < 0)
{
n = -n;
}
n %= MAX_RANDOM_LEN;
// Pad the leading characters with '0', removing the first
// digit.
n += MAX_RANDOM_LEN;
// MAX_RADIX is 36
id.append(Long.toString(n, Character.MAX_RADIX).substring(1));
long timeVal = (System.currentTimeMillis() / TIC_DIFFERENCE);
// Cut.
timeVal %= MAX_SESSION_LIFESPAN_TICS;
// Padding.
timeVal += MAX_SESSION_LIFESPAN_TICS;
id.append(Long.toString(timeVal, Character.MAX_RADIX).substring(1));
// Make the string unique by appending the count since last
// time flip.
// Count sessions only within tics (so the 'real' counter
// isn't exposed to the public).
if (lastTimeVal != timeVal)
{
lastTimeVal = timeVal;
counter = 0;
}
id.append (Long.toString(++counter, Character.MAX_RADIX));
return id.toString();
}
/**
* As {@link #getIdentifier()}, but appends additional text
* separated by a dot to the end of the identifier.
*
* @param suffix Text to append to the end of the generated
* identifier.
* @return The new unique identifier.
* @see #getIdentifier()
*/
public synchronized String getIdentifier(String suffix)
{
if (suffix != null && suffix.length() > 0)
{
return getIdentifier() + '.' + suffix;
}
else
{
return getIdentifier();
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>