[jbpm-commits] JBoss JBPM SVN: r4546 - in jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal: wire/binding and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Apr 14 05:11:49 EDT 2009
Author: alex.guizar at jboss.com
Date: 2009-04-14 05:11:49 -0400 (Tue, 14 Apr 2009)
New Revision: 4546
Modified:
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java
jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java
Log:
revisit pattern binding and address filtering
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java 2009-04-14 08:51:49 UTC (rev 4545)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/email/impl/AddressFilter.java 2009-04-14 09:11:49 UTC (rev 4546)
@@ -30,7 +30,7 @@
if (addresses != null) {
// Loop over for addresses to decide what to keep.
for (InternetAddress address : addresses) {
- if (keepAddress(address)) {
+ if (includeAddress(address) && !excludeAddress(address)) {
filteredAddresses.add(address);
}
}
@@ -38,29 +38,30 @@
return filteredAddresses;
}
- /***
- * Determine in a given address is included or excluded based on regex.
+ /**
+ * Determines whether the given address is included, based on regular expressions.
*
- * @param address Email Address to validate against regex.
- * @return If the includes is provided, and the address matches an include pattern, returns true,
- * false otherwise.
+ * @param address email address to match against regex
+ * @return <code>false</code> if include patterns are present and the address does not match any
+ * pattern, <code>true</code> otherwise
*/
- protected boolean keepAddress(InternetAddress address) {
- return includeAddress(address) && !excludeAddress(address);
- }
-
protected boolean includeAddress(InternetAddress address) {
if (includePatterns == null || includePatterns.isEmpty()) return true;
-
for (Pattern pattern : includePatterns) {
if (pattern.matcher(address.toString()).matches()) return true;
}
return false;
}
+ /**
+ * Determines whether the given address is excluded, based on regular expressions.
+ *
+ * @param address email address to match against regex
+ * @return <code>true</code> if exclude patterns are present and the address matches a pattern,
+ * <code>false</code> otherwise
+ */
protected boolean excludeAddress(InternetAddress address) {
- if (excludePatterns == null || excludePatterns.isEmpty()) return false;
-
+ if (excludePatterns == null) return false;
for (Pattern pattern : excludePatterns) {
if (pattern.matcher(address.toString()).matches()) return true;
}
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java 2009-04-14 08:51:49 UTC (rev 4545)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/MailSessionBinding.java 2009-04-14 09:11:49 UTC (rev 4546)
@@ -65,7 +65,7 @@
// includes
List<Descriptor> includeDescriptors = new ArrayList<Descriptor>();
for (Element includeElement : XmlUtil.elements(filterElement, "include")) {
- includeDescriptors.add(new PatternDescriptor(XmlUtil.getContentText(includeElement), 0));
+ includeDescriptors.add(parsePattern(includeElement, parse, parser));
}
ListDescriptor includesDescriptor = new ListDescriptor();
includesDescriptor.setValueDescriptors(includeDescriptors);
@@ -73,7 +73,7 @@
// excludes
List<Descriptor> excludeDescriptors = new ArrayList<Descriptor>();
for (Element excludeElement : XmlUtil.elements(filterElement, "exclude")) {
- excludeDescriptors.add(new PatternDescriptor(XmlUtil.getContentText(excludeElement), 0));
+ excludeDescriptors.add(parsePattern(excludeElement, parse, parser));
}
ListDescriptor excludesDescriptor = new ListDescriptor();
excludesDescriptor.setValueDescriptors(excludeDescriptors);
@@ -116,4 +116,22 @@
return sessionDescriptor;
}
+ protected Descriptor parsePattern(Element patternElement, Parse parse, Parser parser) {
+ PatternDescriptor patternDescriptor =
+ new PatternDescriptor(XmlUtil.getContentText(patternElement));
+ // literal
+ String literalAttr = XmlUtil.attribute(patternElement, "literal");
+ if (literalAttr != null) {
+ Boolean literal = XmlUtil.parseBooleanValue(literalAttr);
+ if (literal != null) patternDescriptor.setLiteral(literal);
+ }
+ // canonEq
+ String canonEqAttr = XmlUtil.attribute(patternElement, "canonEq");
+ if (canonEqAttr != null) {
+ Boolean canonEq = XmlUtil.parseBooleanValue(canonEqAttr);
+ if (canonEq != null) patternDescriptor.setCanonEq(canonEq);
+ }
+ return patternDescriptor;
+ }
+
}
Modified: jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java
===================================================================
--- jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java 2009-04-14 08:51:49 UTC (rev 4545)
+++ jbpm4/branches/email/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/PatternDescriptor.java 2009-04-14 09:11:49 UTC (rev 4546)
@@ -30,21 +30,40 @@
*/
public class PatternDescriptor extends AbstractDescriptor {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- protected String regex;
- protected int flags;
+ protected String regex;
+ protected boolean literal;
+ protected boolean canonEq;
- public PatternDescriptor() {
- }
+ public PatternDescriptor() {
+ }
- public PatternDescriptor(String regex, int flags) {
- this.regex = regex;
- this.flags = flags;
- }
+ public PatternDescriptor(String regex) {
+ this.regex = regex;
+ }
- public Object construct(WireContext wireContext) {
- return Pattern.compile(regex, flags);
- }
+ public boolean isLiteral() {
+ return literal;
+ }
+ public void setLiteral(boolean literal) {
+ this.literal = literal;
+ }
+
+ public boolean isCanonEq() {
+ return canonEq;
+ }
+
+ public void setCanonEq(boolean canonEq) {
+ this.canonEq = canonEq;
+ }
+
+ public Object construct(WireContext wireContext) {
+ int flags = 0;
+ if (literal) flags |= Pattern.LITERAL;
+ if (canonEq) flags |= Pattern.CANON_EQ;
+ return Pattern.compile(regex, flags);
+ }
+
}
More information about the jbpm-commits
mailing list