cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r669799 - in /cocoon/whiteboard/corona/trunk/corona-sitemap/src: main/java/org/apache/cocoon/corona/sitemap/matcher/ main/java/org/apache/cocoon/corona/sitemap/node/ test/java/org/apache/cocoon/corona/sitemap/node/
Date Fri, 20 Jun 2008 06:27:09 GMT
Author: reinhard
Date: Thu Jun 19 23:27:09 2008
New Revision: 669799

URL: http://svn.apache.org/viewvc?rev=669799&view=rev
Log:
add startsWith and endsWith matching attributes

Added:
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
  (with props)
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
  (with props)
Modified:
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java
    cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/AbstractSitemapNode.java
    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

Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java?rev=669799&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
Thu Jun 19 23:27:09 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.cocoon.corona.sitemap.matcher;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class EndsWithMatcher implements Matcher {
+
+    public Map<String, String> match(String expression, String testValue) {
+        if (testValue == null) {
+            return null;
+        }
+
+        if (testValue.endsWith(expression)) {
+            Map<String, String> result = new HashMap<String, String>();
+            result.put("0", testValue);
+            String left = testValue.substring(0, testValue.length() - expression.length());
+            result.put("1", left);
+            return result;
+        }
+
+        return null;
+    }
+
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EndsWithMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java?rev=669799&r1=669798&r2=669799&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java
Thu Jun 19 23:27:09 2008
@@ -20,5 +20,5 @@
 
 public interface Matcher {
 
-    Map<String, String> match(String testValue, String expression);
+    Map<String, String> match(String expression, String testValue);
 }

Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java?rev=669799&view=auto
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
(added)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
Thu Jun 19 23:27:09 2008
@@ -0,0 +1,40 @@
+/*
+ * 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.cocoon.corona.sitemap.matcher;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StartsWithMatcher implements Matcher {
+
+    public Map<String, String> match(String expression, String testValue) {
+        if (testValue == null) {
+            return null;
+        }
+
+        if (testValue.startsWith(expression)) {
+            Map<String, String> result = new HashMap<String, String>();
+            result.put("0", testValue);
+            String right = testValue.substring(expression.length());
+            result.put("1", right);
+            return result;
+        }
+
+        return null;
+    }
+
+}

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/StartsWithMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/AbstractSitemapNode.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/AbstractSitemapNode.java?rev=669799&r1=669798&r2=669799&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/AbstractSitemapNode.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/AbstractSitemapNode.java
Thu Jun 19 23:27:09 2008
@@ -125,9 +125,13 @@
                 try {
                     parameterField.set(this, value);
                 } catch (IllegalArgumentException e) {
-                    this.logger.error("Failed to set parameter field " + key, e);
+                    String message = "Failed to set parameter field " + key;
+                    this.logger.error(message, e);
+                    throw new RuntimeException(message, e);
                 } catch (IllegalAccessException e) {
-                    this.logger.error("Failed to set parameter field " + key, e);
+                    String message = "Failed to set parameter field " + key;
+                    this.logger.error(message, e);
+                    throw new RuntimeException(message, e);
                 }
                 continue;
             }

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=669799&r1=669798&r2=669799&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
Thu Jun 19 23:27:09 2008
@@ -23,9 +23,11 @@
 
 import org.apache.cocoon.corona.sitemap.Invocation;
 import org.apache.cocoon.corona.sitemap.matcher.ContainsMatcher;
+import org.apache.cocoon.corona.sitemap.matcher.EndsWithMatcher;
 import org.apache.cocoon.corona.sitemap.matcher.EqualsMatcher;
 import org.apache.cocoon.corona.sitemap.matcher.Matcher;
 import org.apache.cocoon.corona.sitemap.matcher.RegexpMatcher;
+import org.apache.cocoon.corona.sitemap.matcher.StartsWithMatcher;
 import org.apache.cocoon.corona.sitemap.matcher.WildcardMatcher;
 import org.apache.cocoon.corona.sitemap.node.annotations.Parameter;
 import org.apache.commons.logging.Log;
@@ -57,6 +59,12 @@
     @Parameter
     private String wildcard;
 
+    @Parameter
+    private String startsWith;
+
+    @Parameter
+    private String endsWith;
+
     private MatcherContext matcherContext;
 
     /**
@@ -128,6 +136,12 @@
         if (this.wildcard != null) {
             matcherContextList.add(new MatcherContext(new WildcardMatcher(), this.wildcard));
         }
+        if (this.startsWith != null) {
+            matcherContextList.add(new MatcherContext(new StartsWithMatcher(), this.startsWith));
+        }
+        if (this.endsWith != null) {
+            matcherContextList.add(new MatcherContext(new EndsWithMatcher(), this.endsWith));
+        }
         if (matcherContextList.size() > 1) {
             String message = "Only one matching attribute (regexp, equals, contains, wildcard,
pattern) can be set: "
                     + matcherContextList;

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=669799&r1=669798&r2=669799&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
Thu Jun 19 23:27:09 2008
@@ -28,6 +28,28 @@
 public class MatchNodeTest {
 
     @Test
+    public void endsWithMatchingAttribute() throws Exception {
+        MatchNode matchNode = new MatchNode();
+        PrivateAccessor.setField(matchNode, "endsWith", ".xml");
+        MatcherContext matcherContext = matchNode.lookupMatcherContext();
+        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc.xml");
+        assertTrue(matches.containsValue("abc.xml"));
+        assertTrue(matches.containsValue("abc"));
+        assertEquals(2, matches.size());
+    }
+
+    @Test
+    public void startsWithMatchingAttribute() throws Exception {
+        MatchNode matchNode = new MatchNode();
+        PrivateAccessor.setField(matchNode, "startsWith", "abc");
+        MatcherContext matcherContext = matchNode.lookupMatcherContext();
+        Map<String, String> matches = matcherContext.matcher.match(matcherContext.value,
"abc/44");
+        assertTrue(matches.containsValue("abc/44"));
+        assertTrue(matches.containsValue("/44"));
+        assertEquals(2, matches.size());
+    }
+
+    @Test
     public void regexpMatchingAttribute() throws Exception {
         MatchNode matchNode = new MatchNode();
         PrivateAccessor.setField(matchNode, "regexp", "([a-zA-Z\\-]+)/(.*)");



Mime
View raw message