Author: felixk
Date: Tue Apr 5 06:59:49 2011
New Revision: 1088908
URL: http://svn.apache.org/viewvc?rev=1088908&view=rev
Log:
Parameterize / add type safety (see MAILETSTANDARD-8)
Added:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java
(with props)
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java
(with props)
Modified:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
Added:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java
URL:
http://svn.apache.org/viewvc/james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java?rev=1088908&view=auto
==============================================================================
---
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java
(added)
+++
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java
Tue Apr 5 06:59:49 2011
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.james.transport.mailets;
+
+import java.util.regex.Pattern;
+
+/**
+ * A data helper bean holding patterns, substitutions and flags
+ */
+public class PatternBean {
+
+ private Pattern patterns = null;
+ private String substitutions = null;
+ private Integer flag = null;
+
+ public PatternBean(Pattern patterns, String substitutions, Integer flag) {
+ super();
+ this.patterns = patterns;
+ this.substitutions = substitutions;
+ this.flag = flag;
+ }
+
+ public Pattern getPatterns() {
+ return patterns;
+ }
+
+ public void setPatterns(Pattern patterns) {
+ this.patterns = patterns;
+ }
+
+ public String getSubstitutions() {
+ return substitutions;
+ }
+
+ public void setSubstitutions(String substitutions) {
+ this.substitutions = substitutions;
+ }
+
+ public Integer getFlag() {
+ return flag;
+ }
+
+ public void setFlag(Integer flag) {
+ this.flag = flag;
+ }
+
+}
\ No newline at end of file
Propchange:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java
URL:
http://svn.apache.org/viewvc/james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java?rev=1088908&view=auto
==============================================================================
---
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java
(added)
+++
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java
Tue Apr 5 06:59:49 2011
@@ -0,0 +1,58 @@
+/****************************************************************
+ * 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.james.transport.mailets;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * A data helper bean holding a lists of patterns, substitutions and flags
+ */
+public class PatternList {
+
+ private List<Pattern> patterns = new ArrayList<Pattern>();
+ private List<String> substitutions = new ArrayList<String>();
+ private List<Integer> flags = new ArrayList<Integer>();
+
+ public List<Pattern> getPatterns() {
+ return patterns;
+ }
+
+ public void setPatterns(List<Pattern> patterns) {
+ this.patterns = patterns;
+ }
+
+ public List<String> getSubstitutions() {
+ return substitutions;
+ }
+
+ public void setSubstitutions(List<String> substitutions) {
+ this.substitutions = substitutions;
+ }
+
+ public List<Integer> getFlags() {
+ return flags;
+ }
+
+ public void setFlags(List<Integer> flags) {
+ this.flags = flags;
+ }
+}
\ No newline at end of file
Propchange:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/PatternList.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java
URL:
http://svn.apache.org/viewvc/james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java?rev=1088908&r1=1088907&r2=1088908&view=diff
==============================================================================
---
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java
(original)
+++
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/ReplaceContent.java
Tue Apr 5 06:59:49 2011
@@ -121,7 +121,7 @@ public class ReplaceContent extends Gene
* @return an array containing Pattern and Substitution of the input stream
* @throws MailetException
*/
- protected static Object[] getPattern(String line) throws MailetException {
+ protected static PatternBean getPattern(String line) throws
MailetException {
String[] pieces = StringUtils.split(line, "/");
if (pieces.length < 3) throw new MailetException("Invalid expression:
" + line);
int options = 0;
@@ -136,33 +136,29 @@ public class ReplaceContent extends Gene
if (pieces[1].indexOf("\\r") >= 0) pieces[1] =
pieces[1].replaceAll("\\\\r", "\r");
if (pieces[1].indexOf("\\n") >= 0) pieces[1] =
pieces[1].replaceAll("\\\\n", "\n");
if (pieces[1].indexOf("\\t") >= 0) pieces[1] =
pieces[1].replaceAll("\\\\t", "\t");
-
- return new Object[] {Pattern.compile(pieces[0], options), pieces[1] ,
new Integer(flags)};
+
+ return new PatternBean (Pattern.compile(pieces[0], options), pieces[1]
, new Integer(flags));
}
- protected static List[] getPatternsFromString(String pattern) throws
MailetException {
+ protected static PatternList getPatternsFromString(String pattern) throws
MailetException {
pattern = pattern.trim();
if (pattern.length() < 2 && !pattern.startsWith("/") &&
!pattern.endsWith("/")) throw new MailetException("Invalid parameter value: " +
PARAMETER_NAME_SUBJECT_PATTERN);
pattern = pattern.substring(1, pattern.length() - 1);
String[] patternArray = StringUtils.split(pattern, "/,/");
- List patterns = new ArrayList();
- List substitutions = new ArrayList();
- List flags = new ArrayList();
+ PatternList patternList= new PatternList();
for (int i = 0; i < patternArray.length; i++) {
- Object[] o = getPattern(patternArray[i]);
- patterns.add(o[0]);
- substitutions.add(o[1]);
- flags.add(o[2]);
+ PatternBean o = getPattern(patternArray[i]);
+ patternList.getPatterns().add(o.getPatterns());
+ patternList.getSubstitutions().add(o.getSubstitutions());
+ patternList.getFlags().add(o.getFlag());
}
- return new List[] {patterns, substitutions, flags};
+ return patternList;
}
- protected static List[] getPatternsFromStream(InputStream stream, String
charset) throws MailetException, IOException {
- List patterns = new ArrayList();
- List substitutions = new ArrayList();
- List flags = new ArrayList();
+ protected static PatternList getPatternsFromStream(InputStream stream,
String charset) throws MailetException, IOException {
+ PatternList patternList= new PatternList();
BufferedReader reader = new BufferedReader(charset != null ? new
InputStreamReader(stream, charset) : new InputStreamReader(stream));
//BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(new FileOutputStream("q:\\correzioniout"), "utf-8"));
@@ -171,23 +167,21 @@ public class ReplaceContent extends Gene
line = line.trim();
if (line.length() > 0 && !line.startsWith("#")) {
if (line.length() < 2 && !line.startsWith("/") &&
!line.endsWith("/")) throw new MailetException("Invalid expression: " + line);
- Object[] o = getPattern(line.substring(1, line.length() - 1));
- patterns.add(o[0]);
- substitutions.add(o[1]);
- flags.add(o[2]);
+ PatternBean o = getPattern(line.substring(1, line.length() -
1));
+ patternList.getPatterns().add(o.getPatterns());
+ patternList.getSubstitutions().add(o.getSubstitutions());
+ patternList.getFlags().add(o.getFlag());
}
}
reader.close();
- return new List[] {patterns, substitutions, flags};
+ return patternList;
}
/**
* @param filepar File path list (or resources if the path starts with #)
comma separated
*/
- private List[] getPatternsFromFileList(String filepar) throws
MailetException, IOException {
- List patterns = new ArrayList();
- List substitutions = new ArrayList();
- List flags = new ArrayList();
+ private PatternList getPatternsFromFileList(String filepar) throws
MailetException, IOException {
+ PatternList patternList= new PatternList();
String[] files = filepar.split(",");
for (int i = 0; i < files.length; i++) {
files[i] = files[i].trim();
@@ -205,14 +199,14 @@ public class ReplaceContent extends Gene
if (f.isFile()) is = new FileInputStream(f);
}
if (is != null) {
- List[] o = getPatternsFromStream(is, charset);
- patterns.addAll(o[0]);
- substitutions.addAll(o[1]);
- flags.addAll(o[2]);
+ PatternList o = getPatternsFromStream(is, charset);
+ patternList.getPatterns().addAll(o.getPatterns());
+ patternList.getSubstitutions().addAll(o.getSubstitutions());
+ patternList.getFlags().addAll(o.getFlags());
is.close();
}
}
- return new List[] {patterns, substitutions, flags};
+ return patternList;
}
protected static String applyPatterns(Pattern[] patterns, String[]
substitutions, Integer[] pflags, String text, int debug, GenericMailet
logOwner) {
@@ -241,43 +235,43 @@ public class ReplaceContent extends Gene
private ReplaceConfig initPatterns() throws MailetException {
try {
- List bodyPatternsList = new ArrayList();
- List bodySubstitutionsList = new ArrayList();
- List bodyFlagsList = new ArrayList();
- List subjectPatternsList = new ArrayList();
- List subjectSubstitutionsList = new ArrayList();
- List subjectFlagsList = new ArrayList();
+ List<Pattern> bodyPatternsList = new ArrayList<Pattern>();
+ List<String> bodySubstitutionsList = new ArrayList<String>();
+ List<Integer> bodyFlagsList = new ArrayList<Integer>();
+ List<Pattern> subjectPatternsList = new ArrayList<Pattern>();
+ List<String> subjectSubstitutionsList = new ArrayList<String>();
+ List<Integer> subjectFlagsList = new ArrayList<Integer>();
String pattern = getInitParameter(PARAMETER_NAME_SUBJECT_PATTERN);
if (pattern != null) {
- List[] o = getPatternsFromString(pattern);
- subjectPatternsList.addAll(o[0]);
- subjectSubstitutionsList.addAll(o[1]);
- subjectFlagsList.addAll(o[2]);
+ PatternList o = getPatternsFromString(pattern);
+ subjectPatternsList.addAll(o.getPatterns());
+ subjectSubstitutionsList.addAll(o.getSubstitutions());
+ subjectFlagsList.addAll(o.getFlags());
}
pattern = getInitParameter(PARAMETER_NAME_BODY_PATTERN);
if (pattern != null) {
- List[] o = getPatternsFromString(pattern);
- bodyPatternsList.addAll(o[0]);
- bodySubstitutionsList.addAll(o[1]);
- bodyFlagsList.addAll(o[2]);
+ PatternList o = getPatternsFromString(pattern);
+ bodyPatternsList.addAll(o.getPatterns());
+ bodySubstitutionsList.addAll(o.getSubstitutions());
+ bodyFlagsList.addAll(o.getFlags());
}
String filepar =
getInitParameter(PARAMETER_NAME_SUBJECT_PATTERNFILE);
if (filepar != null) {
- List[] o = getPatternsFromFileList(filepar);
- subjectPatternsList.addAll(o[0]);
- subjectSubstitutionsList.addAll(o[1]);
- subjectFlagsList.addAll(o[2]);
+ PatternList o = getPatternsFromFileList(filepar);
+ subjectPatternsList.addAll(o.getPatterns());
+ subjectSubstitutionsList.addAll(o.getSubstitutions());
+ subjectFlagsList.addAll(o.getFlags());
}
filepar = getInitParameter(PARAMETER_NAME_BODY_PATTERNFILE);
if (filepar != null) {
- List[] o = getPatternsFromFileList(filepar);
- bodyPatternsList.addAll(o[0]);
- bodySubstitutionsList.addAll(o[1]);
- bodyFlagsList.addAll(o[2]);
+ PatternList o = getPatternsFromFileList(filepar);
+ bodyPatternsList.addAll(o.getPatterns());
+ bodySubstitutionsList.addAll(o.getSubstitutions());
+ bodyFlagsList.addAll(o.getFlags());
}
ReplaceConfig rConfig = new ReplaceConfig();
Modified:
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
URL:
http://svn.apache.org/viewvc/james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/StripAttachment.java?rev=1088908&r1=1088907&r2=1088908&view=diff
==============================================================================
---
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
(original)
+++
james/mailet/standard/trunk/src/main/java/org/apache/james/transport/mailets/StripAttachment.java
Tue Apr 5 06:59:49 2011
@@ -182,12 +182,11 @@ public class StripAttachment extends Gen
getInitParameter(DECODE_FILENAME_PARAMETER_NAME),
decodeFilename);
if (getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME) != null)
{
- List[] pl = ReplaceContent
+ PatternList pl = ReplaceContent
.getPatternsFromString(getInitParameter(REPLACE_FILENAME_PATTERN_PARAMETER_NAME));
- replaceFilenamePatterns = (Pattern[]) pl[0].toArray(new
Pattern[0]);
- replaceFilenameSubstitutions = (String[]) pl[1]
- .toArray(new String[0]);
- replaceFilenameFlags = (Integer[]) pl[2].toArray(new Integer[0]);
+ replaceFilenamePatterns = pl.getPatterns().toArray(new Pattern[0]);
+ replaceFilenameSubstitutions = pl.getSubstitutions().toArray(new
String[0]);
+ replaceFilenameFlags = pl.getFlags().toArray(new Integer[0]);
}
String toLog = "StripAttachment is initialised with regex pattern ["
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]