Author: bago
Date: Wed Jan 12 13:38:24 2011
New Revision: 1058135
URL: http://svn.apache.org/viewvc?rev=1058135&view=rev
Log:
Replaced usage of Jakarta-ORO with java regex (JAMES-1067).
This may introduce backward compatibility issues but we are prepared to fix
them before 3.0 final.
Modified:
james/server/trunk/dnsservice-library/pom.xml
james/server/trunk/mail-file/pom.xml
james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
james/server/trunk/mailets/pom.xml
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/FileRegexMatcher.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/GenericRegexMatcher.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegex.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/NESSpamCheck.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/RecipientIsRegex.java
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/SenderIsRegex.java
james/server/trunk/pom.xml
james/server/trunk/user-library/pom.xml
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/AbstractVirtualUserTable.java
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/VirtualUserTableUtil.java
james/server/trunk/util/pom.xml
james/server/trunk/util/src/main/java/org/apache/james/util/TimeConverter.java
james/server/trunk/util/src/main/java/org/apache/james/util/XMLResources.java
james/server/trunk/util/src/main/java/org/apache/james/util/sql/SqlResources.java
Modified: james/server/trunk/dnsservice-library/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/dnsservice-library/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/dnsservice-library/pom.xml (original)
+++ james/server/trunk/dnsservice-library/pom.xml Wed Jan 12 13:38:24 2011
@@ -79,16 +79,6 @@
<groupId>${javax.mail.groupId}</groupId>
<artifactId>${javax.mail.artifactId}</artifactId>
</dependency>
- <!--
- <dependency>
- <groupId>org.apache.james</groupId>
- <artifactId>james-server-lifecycle-api</artifactId>
- </dependency>
- <dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- </dependency>
- -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Modified: james/server/trunk/mail-file/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/mail-file/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/mail-file/pom.xml (original)
+++ james/server/trunk/mail-file/pom.xml Wed Jan 12 13:38:24 2011
@@ -69,10 +69,6 @@
<artifactId>mail</artifactId>
</dependency>
<dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.0_spec</artifactId>
</dependency>
Modified:
james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
(original)
+++
james/server/trunk/mail-file/src/main/java/org/apache/james/mailrepository/file/MBoxMailRepository.java
Wed Jan 12 13:38:24 2011
@@ -47,33 +47,14 @@
package org.apache.james.mailrepository.file;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.james.core.MailImpl;
-import org.apache.james.lifecycle.api.Configurable;
-import org.apache.james.lifecycle.api.LogEnabled;
-import org.apache.james.mailrepository.api.MailRepository;
-import org.apache.mailet.Mail;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Matcher;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.internet.MimeMessage;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
-import java.security.NoSuchAlgorithmException;
import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -83,6 +64,21 @@ import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.core.MailImpl;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.lifecycle.api.LogEnabled;
+import org.apache.james.mailrepository.api.MailRepository;
+import org.apache.mailet.Mail;
/**
* Implementation of a MailRepository using UNIX mbox files.
@@ -298,9 +294,7 @@ public class MBoxMailRepository implemen
}
try {
- Perl5Compiler sepMatchCompiler = new Perl5Compiler();
- Pattern sepMatchPattern = sepMatchCompiler.compile("^From (.*)
(.*):(.*):(.*)$");
- Perl5Matcher sepMatch = new Perl5Matcher();
+ Pattern sepMatchPattern = Pattern.compile("^From (.*)
(.*):(.*):(.*)$");
int c;
boolean inMessage = false;
@@ -312,7 +306,7 @@ public class MBoxMailRepository implemen
if (BUFFERING) {
String line = null;
while ((line = ins.readLine()) != null) {
- foundSep = sepMatch.contains(line + "\n", sepMatchPattern);
+ foundSep = sepMatchPattern.matcher(line).matches();
if (foundSep && inMessage) {
// if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
@@ -341,7 +335,7 @@ public class MBoxMailRepository implemen
StringBuffer line = new StringBuffer();
while ((c = ins.read()) != -1) {
if (c == 10) {
- foundSep = sepMatch.contains(line.toString(),
sepMatchPattern);
+ foundSep = sepMatchPattern.matcher(line).matches();
if (foundSep && inMessage) {
// if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
// getLogger().debug(this.getClass().getName() + "
Invoking " + messAct.getClass() + " at " + prevMessageStart);
@@ -377,7 +371,7 @@ public class MBoxMailRepository implemen
}
} catch (IOException ioEx) {
getLogger().error("Unable to write file (General I/O problem) " +
mboxFile, ioEx);
- } catch (MalformedPatternException e) {
+ } catch (PatternSyntaxException e) {
getLogger().error("Bad regex passed " + mboxFile, e);
} finally {
if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) {
Modified: james/server/trunk/mailets/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/mailets/pom.xml (original)
+++ james/server/trunk/mailets/pom.xml Wed Jan 12 13:38:24 2011
@@ -178,10 +178,6 @@
<artifactId>geronimo-annotation_1.0_spec</artifactId>
</dependency>
<dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-james-mailbox-api</artifactId>
</dependency>
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
Wed Jan 12 13:38:24 2011
@@ -29,6 +29,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.regex.PatternSyntaxException;
import javax.annotation.Resource;
import javax.mail.MessagingException;
@@ -42,7 +43,6 @@ import org.apache.james.vut.lib.VirtualU
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.base.GenericMailet;
-import org.apache.oro.text.regex.MalformedPatternException;
/**
* Provides an abstraction of common functionality needed for implementing
@@ -121,7 +121,7 @@ public abstract class AbstractVirtualUse
if (targetAddress.startsWith("regex:")) {
try {
targetAddress =
VirtualUserTableUtil.regexMap(source, targetAddress);
- } catch (MalformedPatternException e) {
+ } catch (PatternSyntaxException e) {
log("Exception during regexMap processing: ",
e);
}
if (targetAddress == null) continue;
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/DSNBounce.java
Wed Jan 12 13:38:24 2011
@@ -31,6 +31,9 @@ import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import javax.mail.MessagingException;
import javax.mail.SendFailedException;
@@ -46,11 +49,6 @@ import org.apache.mailet.MailAddress;
import org.apache.mailet.base.RFC2822Headers;
import org.apache.mailet.base.RFC822DateFormat;
import org.apache.mailet.base.mail.MimeMultipartReport;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
@@ -106,21 +104,18 @@ public class DSNBounce extends AbstractN
* Compiles patterns for processing exception messages.<p>
*/
static {
- Perl5Compiler compiler = new Perl5Compiler();
String status_pattern_string =
".*\\s*([245]\\.\\d{1,3}\\.\\d{1,3}).*\\s*";
String diag_pattern_string = "^\\d{3}\\s.*$";
try {
- statusPattern = compiler.
- compile(status_pattern_string, Perl5Compiler.READ_ONLY_MASK);
- } catch(MalformedPatternException mpe) {
+ statusPattern = Pattern.compile(status_pattern_string);
+ } catch(PatternSyntaxException mpe) {
//this should not happen as the pattern string is hardcoded.
System.err.println ("Malformed pattern: " + status_pattern_string);
mpe.printStackTrace (System.err);
}
try {
- diagPattern = compiler.
- compile(diag_pattern_string, Perl5Compiler.READ_ONLY_MASK);
- } catch(MalformedPatternException mpe) {
+ diagPattern = Pattern.compile(diag_pattern_string);
+ } catch(PatternSyntaxException mpe) {
//this should not happen as the pattern string is hardcoded.
System.err.println ("Malformed pattern: " + diag_pattern_string);
}
@@ -177,7 +172,7 @@ public class DSNBounce extends AbstractN
if (isDebug)
log("Processing a bounce request for a message with a reverse
path. The bounce will be sent to " + reversePath);
- Collection newRecipients = new HashSet();
+ Collection<MailAddress> newRecipients = new HashSet<MailAddress>();
newRecipients.add(reversePath);
newMail.setRecipients(newRecipients);
@@ -276,7 +271,7 @@ public class DSNBounce extends AbstractN
}
out.println(bounceBuffer.toString());
out.println("Failed recipient(s):");
- for (Iterator i = originalMail.getRecipients().iterator();
i.hasNext(); ) {
+ for (Iterator<?> i = originalMail.getRecipients().iterator();
i.hasNext(); ) {
out.println(i.next());
}
String ex = (String)originalMail.getAttribute("delivery-error");
@@ -341,7 +336,7 @@ public class DSNBounce extends AbstractN
// per recipient fields //
//////////////////////////
- Iterator recipients = originalMail.getRecipients().iterator();
+ Iterator<MailAddress> recipients =
originalMail.getRecipients().iterator();
while (recipients.hasNext())
{
MailAddress rec = (MailAddress)recipients.next();
@@ -379,9 +374,7 @@ public class DSNBounce extends AbstractN
String diagnosticCode = ex;
// Sometimes this is the smtp diagnostic code,
// but James often gives us other messages
- Perl5Matcher diagMatcher = new Perl5Matcher();
- boolean smtpDiagCodeAvailable =
- diagMatcher.matches(diagnosticCode, diagPattern);
+ boolean smtpDiagCodeAvailable =
diagPattern.matcher(diagnosticCode).matches();
if (smtpDiagCodeAvailable){
diagnosticType = "smtp";
} else {
@@ -454,11 +447,10 @@ public class DSNBounce extends AbstractN
protected String getStatus(MessagingException me) {
if (me.getNextException() == null) {
String mess = me.getMessage();
- Perl5Matcher m = new Perl5Matcher();
+ Matcher m = statusPattern.matcher(mess);
StringBuffer sb = new StringBuffer();
- if (m.matches(mess, statusPattern)) {
- MatchResult res = m.getMatch();
- sb.append(res.group(1));
+ if (m.matches()) {
+ sb.append(m.group(1));
return sb.toString();
}
// bad destination system adress
@@ -474,11 +466,10 @@ public class DSNBounce extends AbstractN
return DSNStatus.getStatus(DSNStatus.PERMANENT,
DSNStatus.UNDEFINED_STATUS);
} else {
Exception ex1 = me.getNextException();
- Perl5Matcher m = new Perl5Matcher ();
+ Matcher m = statusPattern.matcher(ex1.getMessage());
StringBuffer sb = new StringBuffer();
- if (m.matches(ex1.getMessage(), statusPattern)) {
- MatchResult res = m.getMatch();
- sb.append(res.group(1));
+ if (m.matches()) {
+ sb.append(m.group(1));
return sb.toString();
} else if (ex1 instanceof SendFailedException) {
// other/undefined protocol status
@@ -578,8 +569,8 @@ public class DSNBounce extends AbstractN
/**
* @return <CODE>SpecialAddress.REVERSE_PATH</CODE>
*/
- protected Collection getRecipients() {
- Collection newRecipients = new HashSet();
+ protected Collection<MailAddress> getRecipients() {
+ Collection<MailAddress> newRecipients = new HashSet<MailAddress>();
newRecipients.add(SpecialAddress.REVERSE_PATH);
return newRecipients;
}
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
Wed Jan 12 13:38:24 2011
@@ -38,11 +38,6 @@ import org.apache.mailet.HostAddress;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MailetContext;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
import javax.annotation.Resource;
import javax.mail.Address;
@@ -75,6 +70,9 @@ import java.util.Properties;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
/**
@@ -122,9 +120,8 @@ public class RemoteDelivery extends Gene
*/
static {
try {
- Perl5Compiler compiler = new Perl5Compiler();
- PATTERN = compiler.compile(PATTERN_STRING,
Perl5Compiler.READ_ONLY_MASK);
- } catch(MalformedPatternException mpe) {
+ PATTERN = Pattern.compile(PATTERN_STRING);
+ } catch(PatternSyntaxException mpe) {
//this should not happen as the pattern string is hardcoded.
mpe.printStackTrace (System.err);
}
@@ -237,14 +234,13 @@ public class RemoteDelivery extends Gene
if (getInitParameter("delayTime") != null) {
// parses delayTimes specified in config file.
- final Perl5Matcher delayTimeMatcher = new Perl5Matcher();
String delayTimesParm = getInitParameter("delayTime");
// Split on commas
StringTokenizer st = new StringTokenizer (delayTimesParm,",");
while (st.hasMoreTokens()) {
String delayTime = st.nextToken();
- delayTimesList.add (new Delay(delayTimeMatcher,
delayTime));
+ delayTimesList.add (new Delay(delayTime));
}
} else {
// Use default delayTime.
@@ -475,13 +471,12 @@ public class RemoteDelivery extends Gene
* @param initString
* the string to initialize this Delay object from
**/
- public Delay(final Perl5Matcher delayTimeMatcher, String initString)
throws MessagingException {
+ public Delay(String initString) throws MessagingException {
// Default unit value to 'msec'.
String unit = "msec";
- if (delayTimeMatcher.matches(initString, PATTERN)) {
- MatchResult res = delayTimeMatcher.getMatch();
-
+ Matcher res = PATTERN.matcher(initString);
+ if (res.matches()) {
// The capturing groups will now hold:
// at 1: attempts * (if present)
// at 2: delaytime
@@ -660,17 +655,6 @@ public class RemoteDelivery extends Gene
*/
public void run() {
- /* TODO: CHANGE ME!!! The problem is that we need to wait for James to
- * finish initializing. We expect the HELLO_NAME to be put into
- * the MailetContext, but in the current configuration we get
- * started before the SMTP Server, which establishes the value.
- * Since there is no contractual guarantee that there will be a
- * HELLO_NAME value, we can't just wait for it. As a temporary
- * measure, I'm inserting this philosophically unsatisfactory
- * fix.
- */
- long stop = System.currentTimeMillis() + 60000;
-
//Checks the pool and delivers a mail message
Properties props = new Properties();
//Not needed for production environment
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/FileRegexMatcher.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/FileRegexMatcher.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/FileRegexMatcher.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/FileRegexMatcher.java
Wed Jan 12 13:38:24 2011
@@ -22,8 +22,8 @@
package org.apache.james.transport.matchers;
import java.io.IOException;
+import java.util.regex.PatternSyntaxException;
-import org.apache.oro.text.regex.MalformedPatternException;
import javax.mail.MessagingException;
/**
@@ -57,7 +57,7 @@ public class FileRegexMatcher extends Ge
catch (java.io.IOException ioe) {
throw new MessagingException("Could not read patterns.", ioe);
}
- catch(MalformedPatternException mp) {
+ catch(PatternSyntaxException mp) {
throw new MessagingException("Could not initialize regex
patterns", mp);
} finally {
if (patternSource != null) {
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/GenericRegexMatcher.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/GenericRegexMatcher.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/GenericRegexMatcher.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/GenericRegexMatcher.java
Wed Jan 12 13:38:24 2011
@@ -24,14 +24,12 @@ package org.apache.james.transport.match
import org.apache.mailet.base.GenericMatcher;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.util.Collection;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
/**
* This is a generic matcher that uses regular expressions. If any of
@@ -48,12 +46,12 @@ import java.util.Collection;
abstract public class GenericRegexMatcher extends GenericMatcher {
protected Object[][] patterns;
- public void compile(Object[][] patterns) throws MalformedPatternException {
+ public void compile(Object[][] patterns) throws PatternSyntaxException {
// compile a bunch of regular expressions
this.patterns = patterns;
for (int i = 0; i < patterns.length; i++) {
String pattern = (String)patterns[i][1];
- patterns[i][1] = new Perl5Compiler().compile(pattern,
Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
+ patterns[i][1] = Pattern.compile(pattern);
}
}
@@ -67,7 +65,6 @@ abstract public class GenericRegexMatche
*/
public Collection<MailAddress> match(Mail mail) throws MessagingException {
MimeMessage message = mail.getMessage();
- Perl5Matcher matcher = new Perl5Matcher();
//Loop through all the patterns
if (patterns != null) for (int i = 0; i < patterns.length; i++) {
@@ -79,7 +76,7 @@ abstract public class GenericRegexMatche
String headers[] = message.getHeader(headerName);
//Loop through the header values
if (headers != null) for (int j = 0; j < headers.length; j++) {
- if (matcher.matches(headers[j], pattern)) {
+ if (pattern.matcher(headers[j]).matches()) {
// log("Match: " + headerName + "[" + j + "]: " +
headers[j]);
return mail.getRecipients();
}
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegex.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegex.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegex.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/HasMailAttributeWithValueRegex.java
Wed Jan 12 13:38:24 2011
@@ -27,14 +27,12 @@ import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
import org.apache.mailet.MatcherConfig;
import java.util.Collection;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
import javax.mail.MessagingException;
import java.io.Serializable;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
-
/**
* <P>This Matcher determines if the mail contains the attribute specified in
the
* condition and that attribute matches the supplied regular expression,
@@ -53,7 +51,6 @@ public class HasMailAttributeWithValueRe
{
private String attributeName;
- private Perl5Matcher matcher = new Perl5Matcher();
private Pattern pattern = null;
/**
@@ -73,9 +70,8 @@ public class HasMailAttributeWithValueRe
attributeName = condition.substring(0,idx).trim();
String pattern_string = condition.substring (idx+1,
condition.length()).trim();
try {
- Perl5Compiler compiler = new Perl5Compiler();
- pattern = compiler.compile(pattern_string);
- } catch(MalformedPatternException mpe) {
+ pattern = Pattern.compile(pattern_string);
+ } catch(PatternSyntaxException mpe) {
throw new MessagingException("Malformed pattern: " +
pattern_string, mpe);
}
} else {
@@ -94,7 +90,7 @@ public class HasMailAttributeWithValueRe
{
Serializable obj = mail.getAttribute (attributeName);
//to be a little more generic the toString of the value is what is
matched against
- if ( obj != null && matcher.matches(obj.toString(), pattern)) {
+ if ( obj != null && pattern.matcher(obj.toString()).matches()) {
return mail.getRecipients();
}
return null;
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/NESSpamCheck.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/NESSpamCheck.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/NESSpamCheck.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/NESSpamCheck.java
Wed Jan 12 13:38:24 2011
@@ -21,10 +21,11 @@
package org.apache.james.transport.matchers;
+import java.util.regex.PatternSyntaxException;
+
import javax.mail.MessagingException;
import org.apache.mailet.base.RFC2822Headers;
-import org.apache.oro.text.regex.MalformedPatternException;
/**
* This is based on a sample filter.cfg for a Netscape Mail Server to stop
@@ -94,7 +95,7 @@ public class NESSpamCheck extends Generi
//No condition passed... just compile a bunch of regular expressions
try {
compile(NESPatterns);
- } catch(MalformedPatternException mp) {
+ } catch(PatternSyntaxException mp) {
throw new MessagingException("Could not initialize NES patterns",
mp);
}
}
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/RecipientIsRegex.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/RecipientIsRegex.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/RecipientIsRegex.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/RecipientIsRegex.java
Wed Jan 12 13:38:24 2011
@@ -21,12 +21,11 @@
package org.apache.james.transport.matchers;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
import org.apache.mailet.base.GenericRecipientMatcher;
import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
import javax.mail.MessagingException;
@@ -56,18 +55,16 @@ public class RecipientIsRegex extends Ge
}
patternString = patternString.trim();
- Perl5Compiler compiler = new Perl5Compiler();
try {
- pattern = compiler.compile(patternString,
Perl5Compiler.READ_ONLY_MASK);
- } catch(MalformedPatternException mpe) {
+ pattern = Pattern.compile(patternString);
+ } catch(PatternSyntaxException mpe) {
throw new MessagingException("Malformed pattern: " +
patternString, mpe);
}
}
public boolean matchRecipient(MailAddress recipient) {
String myRecipient = recipient.toString();
- Perl5Matcher matcher = new Perl5Matcher();
- if (matcher.matches(myRecipient, pattern)){
+ if (pattern.matcher(myRecipient).matches()){
return true;
} else {
return false;
Modified:
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/SenderIsRegex.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/SenderIsRegex.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/SenderIsRegex.java
(original)
+++
james/server/trunk/mailets/src/main/java/org/apache/james/transport/matchers/SenderIsRegex.java
Wed Jan 12 13:38:24 2011
@@ -24,12 +24,10 @@ package org.apache.james.transport.match
import org.apache.mailet.base.GenericMatcher;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
import java.util.Collection;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import javax.mail.MessagingException;
@@ -65,10 +63,9 @@ public class SenderIsRegex extends Gener
}
patternString = patternString.trim();
- Perl5Compiler compiler = new Perl5Compiler();
try {
- pattern = compiler.compile(patternString,
Perl5Compiler.READ_ONLY_MASK);
- } catch(MalformedPatternException mpe) {
+ pattern = Pattern.compile(patternString);
+ } catch(PatternSyntaxException mpe) {
throw new MessagingException("Malformed pattern: " +
patternString, mpe);
}
}
@@ -79,8 +76,7 @@ public class SenderIsRegex extends Gener
return null;
}
String senderString = mailAddress.toString();
- Perl5Matcher matcher = new Perl5Matcher();
- if (matcher.matches(senderString, pattern)) {
+ if (pattern.matcher(senderString).matches()) {
return mail.getRecipients();
}
return null;
Modified: james/server/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Wed Jan 12 13:38:24 2011
@@ -1002,11 +1002,6 @@
<version>${derby.version}</version>
<scope>runtime</scope>
</dependency>
- <dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- <version>2.0.8</version>
- </dependency>
<!-- Used by Mime4J -->
Modified: james/server/trunk/user-library/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/user-library/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/user-library/pom.xml (original)
+++ james/server/trunk/user-library/pom.xml Wed Jan 12 13:38:24 2011
@@ -65,10 +65,6 @@
<groupId>${javax.mail.groupId}</groupId>
<artifactId>${javax.mail.artifactId}</artifactId>
</dependency>
- <dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- </dependency>
<!-- Test dependencies -->
<dependency>
Modified:
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/AbstractVirtualUserTable.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/AbstractVirtualUserTable.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/AbstractVirtualUserTable.java
(original)
+++
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/AbstractVirtualUserTable.java
Wed Jan 12 13:38:24 2011
@@ -23,6 +23,8 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import javax.mail.internet.ParseException;
@@ -34,8 +36,6 @@ import org.apache.james.lifecycle.api.Lo
import org.apache.james.vut.api.VirtualUserTable;
import org.apache.james.vut.api.VirtualUserTableException;
import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.Perl5Compiler;
/**
*
@@ -120,7 +120,7 @@ public abstract class AbstractVirtualUse
if (target.startsWith(VirtualUserTable.REGEX_PREFIX)) {
try {
target = VirtualUserTableUtil.regexMap(new
MailAddress(user,domain), target);
- } catch (MalformedPatternException e) {
+ } catch (PatternSyntaxException e) {
getLogger().error("Exception during regexMap
processing: ", e);
} catch (ParseException e) {
// should never happen
@@ -186,8 +186,8 @@ public abstract class AbstractVirtualUse
*/
public void addRegexMapping(String user, String domain, String regex)
throws VirtualUserTableException {
try {
- new Perl5Compiler().compile(regex);
- } catch (MalformedPatternException e) {
+ Pattern.compile(regex);
+ } catch (PatternSyntaxException e) {
throw new VirtualUserTableException("Invalid regex: " + regex, e);
}
Modified:
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/VirtualUserTableUtil.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/VirtualUserTableUtil.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/VirtualUserTableUtil.java
(original)
+++
james/server/trunk/user-library/src/main/java/org/apache/james/vut/lib/VirtualUserTableUtil.java
Wed Jan 12 13:38:24 2011
@@ -24,15 +24,13 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import org.apache.james.util.XMLResources;
import org.apache.james.vut.api.VirtualUserTable;
import org.apache.mailet.MailAddress;
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
/**
* This helper class contains methods for the VirtualUserTable implementations
@@ -55,14 +53,14 @@ public class VirtualUserTableUtil {
* @param targetString a String specifying the mapping
* @throws MalformedPatternException
*/
- public static String regexMap( MailAddress address, String targetString)
throws MalformedPatternException {
+ public static String regexMap( MailAddress address, String targetString) {
String result = null;
int identifierLength = VirtualUserTable.REGEX_PREFIX.length();
int msgPos = targetString.indexOf(':', identifierLength + 1);
// Throw exception on invalid format
- if (msgPos < identifierLength + 1) throw new
MalformedPatternException("Regex should be formatted as
regex:<regular-expression>:<parameterized-string>");
+ if (msgPos < identifierLength + 1) throw new
PatternSyntaxException("Regex should be formatted as
regex:<regular-expression>:<parameterized-string>", targetString, 0);
// log("regex: targetString = " + targetString);
// log("regex: msgPos = " + msgPos);
@@ -70,13 +68,12 @@ public class VirtualUserTableUtil {
// log("regex: address = " + address.toString());
// log("regex: replace = " + targetString.substring(msgPos + 1));
- Pattern pattern = new
Perl5Compiler().compile(targetString.substring(identifierLength, msgPos));
- Perl5Matcher matcher = new Perl5Matcher();
+ Pattern pattern =
Pattern.compile(targetString.substring(identifierLength, msgPos));
+ Matcher match = pattern.matcher(address.toString());
- if (matcher.matches(address.toString(), pattern)) {
- MatchResult match = matcher.getMatch();
- Map parameters = new HashMap(match.groups());
- for (int i = 1; i < match.groups(); i++) {
+ if (match.matches()) {
+ Map<String, String> parameters = new HashMap<String,
String>(match.groupCount());
+ for (int i = 1; i < match.groupCount(); i++) {
parameters.put(Integer.toString(i), match.group(i));
}
result =
XMLResources.replaceParameters(targetString.substring(msgPos + 1), parameters);
@@ -91,7 +88,7 @@ public class VirtualUserTableUtil {
* @param domain the virtual domain
* @return the real recipient address, or <code>null</code> if no mapping
exists
*/
- public static String getTargetString(String user, String domain, Map
mappings) {
+ public static String getTargetString(String user, String domain,
Map<String, String> mappings) {
StringBuffer buf;
String target;
@@ -137,8 +134,8 @@ public class VirtualUserTableUtil {
* @param mapping A String which contains a list of mappings
* @return Map which contains the mappings
*/
- public static Map getXMLMappings(String mapping) {
- Map mappings = new HashMap();
+ public static Map<String, String> getXMLMappings(String mapping) {
+ Map<String, String> mappings = new HashMap<String, String>();
StringTokenizer tokenizer = new StringTokenizer(mapping, ",");
while(tokenizer.hasMoreTokens()) {
String mappingItem = tokenizer.nextToken();
@@ -184,9 +181,9 @@ public class VirtualUserTableUtil {
* @param map the Collection
* @return mapping the mapping String
*/
- public static String CollectionToMapping(Collection map) {
+ public static String CollectionToMapping(Collection<String> map) {
StringBuffer mapping = new StringBuffer();
- Iterator mappings = map.iterator();
+ Iterator<String> mappings = map.iterator();
while (mappings.hasNext()) {
mapping.append(mappings.next());
if (mappings.hasNext()) {
Modified: james/server/trunk/util/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/util/pom.xml?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
--- james/server/trunk/util/pom.xml (original)
+++ james/server/trunk/util/pom.xml Wed Jan 12 13:38:24 2011
@@ -76,10 +76,6 @@
<artifactId>apache-mailet</artifactId>
</dependency>
<dependency>
- <groupId>oro</groupId>
- <artifactId>oro</artifactId>
- </dependency>
- <dependency>
<groupId>${javax.mail.groupId}</groupId>
<artifactId>${javax.mail.artifactId}</artifactId>
</dependency>
Modified:
james/server/trunk/util/src/main/java/org/apache/james/util/TimeConverter.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/util/src/main/java/org/apache/james/util/TimeConverter.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/util/src/main/java/org/apache/james/util/TimeConverter.java
(original)
+++
james/server/trunk/util/src/main/java/org/apache/james/util/TimeConverter.java
Wed Jan 12 13:38:24 2011
@@ -16,21 +16,15 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
-
-
package org.apache.james.util;
import java.util.HashMap;
-
-import org.apache.oro.text.regex.MalformedPatternException;
-import org.apache.oro.text.regex.MatchResult;
-import org.apache.oro.text.regex.Pattern;
-import org.apache.oro.text.regex.Perl5Compiler;
-import org.apache.oro.text.regex.Perl5Matcher;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class TimeConverter {
- private static HashMap multipliers = new HashMap(10);
+ private static HashMap<String, Integer> multipliers = new HashMap<String,
Integer>(10);
private static final String PATTERN_STRING =
"\\s*([0-9]+)\\s*([a-z,A-Z]+)\\s*";
@@ -49,13 +43,7 @@ public class TimeConverter {
multipliers.put("day", new Integer(1000 * 60 * 60 * 24));
multipliers.put("days", new Integer(1000 * 60 * 60 * 24));
- try {
- Perl5Compiler compiler = new Perl5Compiler();
- PATTERN = compiler.compile(PATTERN_STRING,
- Perl5Compiler.READ_ONLY_MASK);
- } catch (MalformedPatternException mpe) {
- // Will never happen cause its hardcoded
- }
+ PATTERN = Pattern.compile(PATTERN_STRING);
}
@@ -96,18 +84,9 @@ public class TimeConverter {
*/
public static long getMilliSeconds(String rawString)
throws NumberFormatException {
- Perl5Matcher matcher = new Perl5Matcher();
-
- try {
- Perl5Compiler compiler = new Perl5Compiler();
- PATTERN = compiler.compile(PATTERN_STRING,
- Perl5Compiler.READ_ONLY_MASK);
- } catch (MalformedPatternException mpe) {
- // Will never happen
- }
-
- if (matcher.matches(rawString, PATTERN)) {
- MatchResult res = matcher.getMatch();
+ PATTERN = Pattern.compile(PATTERN_STRING);
+ Matcher res = PATTERN.matcher(rawString);
+ if (res.matches()) {
if (res.group(1) != null && res.group(2) != null) {
long time = Integer.parseInt(res.group(1).trim());
Modified:
james/server/trunk/util/src/main/java/org/apache/james/util/XMLResources.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/util/src/main/java/org/apache/james/util/XMLResources.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/util/src/main/java/org/apache/james/util/XMLResources.java
(original)
+++
james/server/trunk/util/src/main/java/org/apache/james/util/XMLResources.java
Wed Jan 12 13:38:24 2011
@@ -20,8 +20,6 @@
package org.apache.james.util;
-import org.apache.oro.text.perl.MalformedPerl5PatternException;
-import org.apache.oro.text.perl.Perl5Util;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -34,6 +32,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.regex.Pattern;
/*
* This is derived from the SQLResources.java class that we have been
@@ -79,17 +78,12 @@ public class XMLResources
/**
* A map of statement types to resource strings
*/
- private Map m_resource = new HashMap();
+ private Map<String, String> m_resource = new HashMap<String, String>();
/**
* A set of all used String values
*/
- static private Map stringTable = java.util.Collections.synchronizedMap(new
HashMap());
-
- /**
- * A Perl5 regexp matching helper class
- */
- private Perl5Util m_perl5Util = new Perl5Util();
+ static private Map<String, String> stringTable =
java.util.Collections.synchronizedMap(new HashMap<String, String>());
/**
* Configures an XMLResources object to provide string statements from a
file.
@@ -105,7 +99,7 @@ public class XMLResources
* replaced where found in the input strings
*/
public void init(File xmlFile, String group,
- String select, Map configParameters)
+ String select, Map<String, String> configParameters)
throws Exception
{
// Parse the xmlFile as an XML document.
@@ -119,7 +113,6 @@ public class XMLResources
String selectTag = null;
if ( matcherElement != null ) {
selectTag = match(select, matcherElement);
- m_perl5Util = null; // release the PERL matcher!
}
// Now get the section defining strings for the group required.
@@ -146,7 +139,7 @@ public class XMLResources
// Get parameters defined within the file as defaults,
// and use supplied parameters as overrides.
- Map parameters = new HashMap();
+ Map<String, String> parameters = new HashMap<String, String>();
// First read from the <params> element, if it exists.
Element parametersElement =
(Element)(sectionElement.getElementsByTagName("parameters").item(0));
@@ -166,8 +159,8 @@ public class XMLResources
// 2 maps - one for storing default statements,
// the other for statements with a "for" attribute matching this
// connection.
- Map defaultStrings = new HashMap();
- Map selectTagStrings = new HashMap();
+ Map<String, String> defaultStrings = new HashMap<String, String>();
+ Map<String, String> selectTagStrings = new HashMap<String, String>();
// Process each string resource, replacing string parameters,
// and adding to the appropriate map..
@@ -177,7 +170,7 @@ public class XMLResources
// See if this needs to be processed (is default or product
specific)
Element resElement = (Element)(resDefs.item(i));
String resSelect = resElement.getAttribute("for");
- Map resMap;
+ Map<String, String> resMap;
if ( resSelect.equals("")) {
// default
resMap = defaultStrings;
@@ -200,7 +193,7 @@ public class XMLResources
String resString = resElement.getFirstChild().getNodeValue();
// Do parameter replacements for this string resource.
- Iterator paramNames = parameters.keySet().iterator();
+ Iterator<String> paramNames = parameters.keySet().iterator();
while ( paramNames.hasNext() ) {
String paramName = (String)paramNames.next();
String paramValue = (String)parameters.get(paramName);
@@ -243,9 +236,7 @@ public class XMLResources
* @return the selector tag that will be used to select custom resources
*
*/
- private String match(String select, Element matchersElement)
- throws MalformedPerl5PatternException
- {
+ private String match(String select, Element matchersElement) {
String selectTagName = select;
NodeList matchers = matchersElement.getElementsByTagName("matcher");
@@ -253,15 +244,11 @@ public class XMLResources
// Get the values for this matcher element.
Element matcher = (Element)matchers.item(i);
String matchName = matcher.getAttribute("for");
- StringBuffer selectTagPatternBuffer =
- new StringBuffer(64)
- .append("/")
- .append(matcher.getAttribute("match"))
- .append("/i");
+ Pattern selectTagPattern =
Pattern.compile(matcher.getAttribute("match"), Pattern.CASE_INSENSITIVE);
// If the select string matches the pattern, use the match
// name from this matcher.
- if ( m_perl5Util.match(selectTagPatternBuffer.toString(),
selectTagName) ) {
+ if ( selectTagPattern.matcher(selectTagName).find() ) {
return matchName;
}
}
@@ -338,7 +325,7 @@ public class XMLResources
* replaced where found in the input strings
* @return the requested resource
*/
- public String getString(String name, Map parameters)
+ public String getString(String name, Map<String, String> parameters)
{
return replaceParameters(getString(name), parameters);
}
@@ -351,7 +338,7 @@ public class XMLResources
* replaced where found in the input strings
* @return the requested resource
*/
- public String getString(String name, Map parameters, boolean required)
+ public String getString(String name, Map<String, String> parameters,
boolean required)
{
return replaceParameters(getString(name, required), parameters);
}
@@ -364,11 +351,11 @@ public class XMLResources
* replaced where found in the input strings
* @return the requested resource
*/
- static public String replaceParameters(String str, Map parameters)
+ static public String replaceParameters(String str, Map<String, String>
parameters)
{
if (str != null && parameters != null) {
// Do parameter replacements for this string resource.
- Iterator paramNames = parameters.keySet().iterator();
+ Iterator<String> paramNames = parameters.keySet().iterator();
StringBuffer replaceBuffer = new StringBuffer(64);
while ( paramNames.hasNext() ) {
String paramName = (String)paramNames.next();
Modified:
james/server/trunk/util/src/main/java/org/apache/james/util/sql/SqlResources.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/util/src/main/java/org/apache/james/util/sql/SqlResources.java?rev=1058135&r1=1058134&r2=1058135&view=diff
==============================================================================
---
james/server/trunk/util/src/main/java/org/apache/james/util/sql/SqlResources.java
(original)
+++
james/server/trunk/util/src/main/java/org/apache/james/util/sql/SqlResources.java
Wed Jan 12 13:38:24 2011
@@ -20,8 +20,6 @@
package org.apache.james.util.sql;
-import org.apache.oro.text.perl.MalformedPerl5PatternException;
-import org.apache.oro.text.perl.Perl5Util;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -37,6 +35,7 @@ import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.regex.Pattern;
/**
@@ -65,11 +64,6 @@ public class SqlResources
static private Map<String, String> stringTable =
java.util.Collections.synchronizedMap(new HashMap<String, String>());
/**
- * A Perl5 regexp matching helper class
- */
- private Perl5Util m_perl5Util = new Perl5Util();
-
- /**
* Configures a DbResources object to provide SQL statements from a file.
*
* SQL statements returned may be specific to the particular type
@@ -146,7 +140,6 @@ public class SqlResources
String dbProduct = null;
if ( dbMatcherElement != null ) {
dbProduct = matchDbConnection(conn, dbMatcherElement);
- m_perl5Util = null; // release the PERL matcher!
}
// Now get the options valid for the database product used.
@@ -285,7 +278,7 @@ public class SqlResources
*/
private String matchDbConnection(Connection conn,
Element dbMatchersElement)
- throws MalformedPerl5PatternException, SQLException
+ throws SQLException
{
String dbProductName = conn.getMetaData().getDatabaseProductName();
@@ -295,15 +288,11 @@ public class SqlResources
// Get the values for this matcher element.
Element dbMatcher = (Element)dbMatchers.item(i);
String dbMatchName = dbMatcher.getAttribute("db");
- StringBuilder dbProductPatternBuffer =
- new StringBuilder(64)
- .append("/")
- .append(dbMatcher.getAttribute("databaseProductName"))
- .append("/i");
+ Pattern dbProductPattern =
Pattern.compile(dbMatcher.getAttribute("databaseProductName"),
Pattern.CASE_INSENSITIVE);
// If the connection databaseProcuctName matches the pattern,
// use the match name from this matcher.
- if ( m_perl5Util.match(dbProductPatternBuffer.toString(),
dbProductName) ) {
+ if ( dbProductPattern.matcher(dbProductName).find() ) {
return dbMatchName;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]