cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r672620 - in /cocoon/whiteboard/corona/trunk/corona-sitemap/src: main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java
Date Sun, 29 Jun 2008 11:49:29 GMT
Author: reinhard
Date: Sun Jun 29 04:49:29 2008
New Revision: 672620

URL: http://svn.apache.org/viewvc?rev=672620&view=rev
Log:
encapsulate matching process in matcherContext

Modified:
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java?rev=672620&r1=672619&r2=672620&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/MatchNode.java
Sun Jun 29 04:49:29 2008
@@ -101,7 +101,7 @@
         }
 
         // if there are matching attributes, invoke the matcher and execute the children
afterwards
-        Map<String, String> matches = this.matcherContext.matcher.match(this.matcherContext.value,
testValue);
+        Map<String, String> matches = this.matcherContext.match(testValue);
         if (matches == null) {
             // do not ask our children, there was no match
             return InvocationResult.NONE;
@@ -178,20 +178,32 @@
 
     protected static class MatcherContext {
 
-        public Matcher matcher;
-        public String value;
+        private static final Log LOG = LogFactory.getLog(MatcherContext.class);
 
-        public MatcherContext(Matcher matcher, String testValue) {
+        private Matcher matcher;
+        private String expression;
+
+        public MatcherContext(Matcher matcher, String expression) {
             super();
             this.matcher = matcher;
-            this.value = testValue;
+            this.expression = expression;
+        }
+
+        public Map<String, String> match(String testValue) {
+            Map<String, String> result = this.matcher.match(this.expression, testValue);
+
+            if (LOG.isDebugEnabled()) {
+                String message = "Matching: expression=" + this.expression + ", testValue="
+ testValue + ", result="
+                        + result;
+                LOG.debug(message);
+            }
+
+            return result;
         }
 
         @Override
         public String toString() {
-            // TODO Auto-generated method stub
-            return "matcher=" + this.matcher + ", testValue=" + this.value;
+            return "matcher=" + this.matcher + ", expression=" + this.expression;
         }
     }
-
-}
+}
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java?rev=672620&r1=672619&r2=672620&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/test/java/org/apache/cocoon/corona/sitemap/node/MatchNodeTest.java
Sun Jun 29 04:49:29 2008
@@ -1,12 +1,12 @@
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
+ * 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
+ * the License. You may obtain a copy of the License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -32,7 +32,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "endsWith", ".xml");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc.xml");
+        Map<String, String> matches = matcherContext.match("abc.xml");
         assertTrue(matches.containsValue("abc.xml"));
         assertTrue(matches.containsValue("abc"));
         assertEquals(2, matches.size());
@@ -43,7 +43,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "startsWith", "abc");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/44");
+        Map<String, String> matches = matcherContext.match("abc/44");
         assertTrue(matches.containsValue("abc/44"));
         assertTrue(matches.containsValue("/44"));
         assertEquals(2, matches.size());
@@ -54,7 +54,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "regexp", "([a-zA-Z\\-]+)/(.*)");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/44");
+        Map<String, String> matches = matcherContext.match("abc/44");
         assertTrue(matches.containsValue("abc/44"));
         assertTrue(matches.containsValue("abc"));
         assertTrue(matches.containsValue("44"));
@@ -66,7 +66,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "regexp", "([a-zA-Z\\-]+)/(.*)");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/44");
+        Map<String, String> matches = matcherContext.match("abc/44");
         assertTrue(matches.containsValue("abc/44"));
         assertTrue(matches.containsValue("abc"));
         assertTrue(matches.containsValue("44"));
@@ -78,7 +78,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "contains", "123");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"000123456");
+        Map<String, String> matches = matcherContext.match("000123456");
         assertTrue(matches.containsValue("000123456"));
         assertEquals(1, matches.size());
     }
@@ -88,7 +88,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "equals", "123");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"123");
+        Map<String, String> matches = matcherContext.match("123");
         assertTrue(matches.containsValue("123"));
         assertEquals(1, matches.size());
     }
@@ -98,7 +98,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "wildcard", "abc/*/*");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/def/ghi");
+        Map<String, String> matches = matcherContext.match("abc/def/ghi");
         assertTrue(matches.containsValue("abc/def/ghi"));
         assertTrue(matches.containsValue("def"));
         assertTrue(matches.containsValue("ghi"));
@@ -110,7 +110,7 @@
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "wildcard", "abc/*/*");
         MatcherContext matcherContext = matchNode.lookupMatcherContext();
-        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/def/ghi");
+        Map<String, String> matches = matcherContext.match("abc/def/ghi");
         assertTrue(matches.containsValue("abc/def/ghi"));
         assertTrue(matches.containsValue("def"));
         assertTrue(matches.containsValue("ghi"));



Mime
View raw message