sdeboy 2004/03/24 19:39:24
Modified: src/java/org/apache/log4j/rule NotEqualsRule.java
PartialTextMatchRule.java InequalityRule.java
ExistsRule.java EqualsRule.java LikeRule.java
Log:
updated rules to throw illegal arg exception if an unsupported field is provided to
the rule
(the msg from the illegal arg is displayed as the tooltip in the find/refine focus
field).
Revision Changes Path
1.5 +20 -9 logging-log4j/src/java/org/apache/log4j/rule/NotEqualsRule.java
Index: NotEqualsRule.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/NotEqualsRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NotEqualsRule.java 27 Feb 2004 16:47:34 -0000 1.4
+++ NotEqualsRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 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.
@@ -21,31 +21,42 @@
import java.util.Stack;
+
/**
* A Rule class implementing not equals against two strings.
- *
+ *
* @author Scott Deboy <[EMAIL PROTECTED]>
*/
public class NotEqualsRule extends AbstractRule {
- private static final LoggingEventFieldResolver resolver =
LoggingEventFieldResolver.getInstance();
+ private static final LoggingEventFieldResolver resolver =
+ LoggingEventFieldResolver.getInstance();
private final String field;
private final String value;
private NotEqualsRule(String field, String value) {
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException(
+ "Invalid NOT EQUALS rule - " + field + " is not a supported field");
+ }
+
this.field = field;
this.value = value;
}
public static Rule getRule(String field, String value) {
- return new NotEqualsRule(field, value);
+ return new NotEqualsRule(field, value);
}
-
+
public static Rule getRule(Stack stack) {
if (stack.size() < 2) {
- throw new IllegalArgumentException("Invalid NOT EQUALS rule - expected two
parameters but received " + stack.size());
- }
+ throw new IllegalArgumentException(
+ "Invalid NOT EQUALS rule - expected two parameters but received "
+ + stack.size());
+ }
+
String p2 = stack.pop().toString();
String p1 = stack.pop().toString();
+
return new NotEqualsRule(p1, p2);
}
1.5 +22 -12
logging-log4j/src/java/org/apache/log4j/rule/PartialTextMatchRule.java
Index: PartialTextMatchRule.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rule/PartialTextMatchRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PartialTextMatchRule.java 27 Feb 2004 16:47:34 -0000 1.4
+++ PartialTextMatchRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 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.
@@ -21,29 +21,39 @@
import java.util.Stack;
+
/**
- * A Rule class implementing case-insensitive partial-text matches against two
strings.
- *
+ * A Rule class implementing case-insensitive partial-text matches against two
strings.
+ *
* @author Scott Deboy <[EMAIL PROTECTED]>
*/
public class PartialTextMatchRule extends AbstractRule {
- private static final LoggingEventFieldResolver resolver =
LoggingEventFieldResolver.getInstance();
+ private static final LoggingEventFieldResolver resolver =
+ LoggingEventFieldResolver.getInstance();
private final String field;
private final String value;
private PartialTextMatchRule(String field, String value) {
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException(
+ "Invalid partial text rule - " + field + " is not a supported field");
+ }
+
this.field = field;
this.value = value;
}
-
+
public static Rule getRule(String field, String value) {
- return new PartialTextMatchRule(field, value);
+ return new PartialTextMatchRule(field, value);
}
public static Rule getRule(Stack stack) {
- if (stack.size() < 2) {
- throw new IllegalArgumentException("invalid partial text rule - expected
two parameters but received " + stack.size());
- }
+ if (stack.size() < 2) {
+ throw new IllegalArgumentException(
+ "invalid partial text rule - expected two parameters but received "
+ + stack.size());
+ }
+
String p2 = stack.pop().toString();
String p1 = stack.pop().toString();
@@ -54,6 +64,6 @@
Object p2 = resolver.getValue(field, event);
return ((p2 != null) && (value != null)
- && (p2.toString().toLowerCase().indexOf(value.toLowerCase()) > -1));
+ && (p2.toString().toLowerCase().indexOf(value.toLowerCase()) > -1));
}
}
1.5 +4 -0 logging-log4j/src/java/org/apache/log4j/rule/InequalityRule.java
Index: InequalityRule.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/rule/InequalityRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- InequalityRule.java 27 Feb 2004 16:47:34 -0000 1.4
+++ InequalityRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -39,6 +39,10 @@
private InequalityRule(
String inequalitySymbol, String field, String value) {
this.inequalitySymbol = inequalitySymbol;
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException("Invalid " + inequalitySymbol + " rule -
" + field + " is not a supported field");
+ }
+
this.field = field;
this.value = value;
}
1.5 +20 -11 logging-log4j/src/java/org/apache/log4j/rule/ExistsRule.java
Index: ExistsRule.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/ExistsRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ExistsRule.java 27 Feb 2004 16:47:33 -0000 1.4
+++ ExistsRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 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.
@@ -21,27 +21,36 @@
import java.util.Stack;
+
/**
* A Rule class implementing a not null (and not empty string) check.
- *
+ *
* @author Scott Deboy <[EMAIL PROTECTED]>
*/
public class ExistsRule extends AbstractRule {
- private static final LoggingEventFieldResolver resolver =
LoggingEventFieldResolver.getInstance();
+ private static final LoggingEventFieldResolver resolver =
+ LoggingEventFieldResolver.getInstance();
private final String field;
private ExistsRule(String field) {
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException(
+ "Invalid EXISTS rule - " + field + " is not a supported field");
+ }
+
this.field = field;
}
public static Rule getRule(String field) {
- return new ExistsRule(field);
+ return new ExistsRule(field);
}
-
+
public static Rule getRule(Stack stack) {
- if (stack.size() < 1) {
- throw new IllegalArgumentException("Invalid EXISTS rule - expected one
parameter but received " + stack.size());
- }
+ if (stack.size() < 1) {
+ throw new IllegalArgumentException(
+ "Invalid EXISTS rule - expected one parameter but received "
+ + stack.size());
+ }
return new ExistsRule(stack.pop().toString());
}
@@ -49,6 +58,6 @@
public boolean evaluate(LoggingEvent event) {
Object p2 = resolver.getValue(field, event);
- return (!(p2 == null || (p2 != null && p2.toString().equals(""))));
+ return (!((p2 == null) || ((p2 != null) && p2.toString().equals(""))));
}
}
1.5 +20 -10 logging-log4j/src/java/org/apache/log4j/rule/EqualsRule.java
Index: EqualsRule.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/EqualsRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EqualsRule.java 27 Feb 2004 16:47:33 -0000 1.4
+++ EqualsRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 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.
@@ -21,38 +21,48 @@
import java.util.Stack;
+
/**
* A Rule class which returns the result of performing equals against two strings.
- *
+ *
* @author Scott Deboy <[EMAIL PROTECTED]>
*/
-
public class EqualsRule extends AbstractRule {
- private static final LoggingEventFieldResolver resolver =
LoggingEventFieldResolver.getInstance();
+ private static final LoggingEventFieldResolver resolver =
+ LoggingEventFieldResolver.getInstance();
private final String value;
private final String field;
private EqualsRule(String field, String value) {
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException(
+ "Invalid EQUALS rule - " + field + " is not a supported field");
+ }
+
this.field = field;
this.value = value;
}
public static Rule getRule(Stack stack) {
if (stack.size() < 2) {
- throw new IllegalArgumentException("Invalid EQUALS rule - expected two
parameters but received " + stack.size());
- }
+ throw new IllegalArgumentException(
+ "Invalid EQUALS rule - expected two parameters but received "
+ + stack.size());
+ }
+
String p2 = stack.pop().toString();
String p1 = stack.pop().toString();
return new EqualsRule(p1, p2);
}
-
+
public static Rule getRule(String p1, String p2) {
- return new EqualsRule(p1, p2);
+ return new EqualsRule(p1, p2);
}
public boolean evaluate(LoggingEvent event) {
Object p2 = resolver.getValue(field, event);
+
return ((p2 != null) && p2.toString().equals(value));
}
}
1.5 +5 -0 logging-log4j/src/java/org/apache/log4j/rule/LikeRule.java
Index: LikeRule.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/LikeRule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LikeRule.java 27 Feb 2004 16:47:34 -0000 1.4
+++ LikeRule.java 25 Mar 2004 03:39:24 -0000 1.5
@@ -38,6 +38,10 @@
private final String field;
private LikeRule(String field, Pattern pattern) {
+ if (!resolver.isField(field)) {
+ throw new IllegalArgumentException("Invalid LIKE rule - " + field + " is
not a supported field");
+ }
+
this.field = field;
this.pattern = pattern;
}
@@ -59,6 +63,7 @@
try {
pattern1 = compiler.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK);
} catch (MalformedPatternException e) {
+ throw new IllegalArgumentException("Invalid LIKE rule - " + e.getMessage());
}
return new LikeRule(field, pattern1);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]