Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT

file stats: | LOC: | 35 |  | Methods: | 2
| NCLOC: | 27 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

MatchesFunction.java

75%

90.9%

100%

88.2%

1 |  | package net.sourceforge.pmd.jaxen;
2 |  |
3 |  | import org.apache.oro.text.perl.Perl5Util;
4 |  | import org.jaxen.Context;
5 |  | import org.jaxen.Function;
6 |  | import org.jaxen.FunctionCallException;
7 |  | import org.jaxen.SimpleFunctionContext;
8 |  | import org.jaxen.XPathFunctionContext;
9 |  |
10 |  | import java.util.List;
11 |  |
12 |  | public class MatchesFunction implements Function {
13 |  |
14 | 126 | public static void registerSelfInSimpleContext() {
15 |  | // see http://jaxen.org/extensions.html
16 | 126 | ((SimpleFunctionContext) XPathFunctionContext.getInstance()).registerFunction(null, "matches", new MatchesFunction());
17 |  | }
18 |  |
19 | 6 | public Object call(Context context, List args) throws FunctionCallException {
20 | 6 | if (args.isEmpty()) {
21 | 0 | return Boolean.FALSE;
22 |  | }
23 | 6 | List attributes = (List) args.get(0);
24 | 6 | Attribute attr = (Attribute) attributes.get(0);
25 | 6 | String testString = attr.getValue();
26 | 6 | String regularExpression = '/' + (String) args.get(1) + '/';
27 |  |
28 |  | // see http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html#package_description
29 | 6 | Perl5Util regexp = new Perl5Util();
30 | 6 | if (regexp.match(regularExpression, testString)) {
31 | 3 | return context.getNodeSet();
32 |  | }
33 | 3 | return Boolean.FALSE;
34 |  | }
35 |  | }