Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 48480 invoked from network); 18 Jun 2008 17:10:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jun 2008 17:10:07 -0000 Received: (qmail 56493 invoked by uid 500); 18 Jun 2008 17:10:09 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 56450 invoked by uid 500); 18 Jun 2008 17:10:09 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 56441 invoked by uid 99); 18 Jun 2008 17:10:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jun 2008 10:10:09 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jun 2008 17:09:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5925B238895D; Wed, 18 Jun 2008 10:09:46 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r669228 - 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: Wed, 18 Jun 2008 17:09:45 -0000 To: cvs@cocoon.apache.org From: reinhard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080618170946.5925B238895D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reinhard Date: Wed Jun 18 10:09:45 2008 New Revision: 669228 URL: http://svn.apache.org/viewvc?rev=669228&view=rev Log: introduce a matcher interface (a first step towards the support of custom matcher implementations) Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java (with props) cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java (with props) cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java (with props) cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java (with props) cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java (with props) 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 Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java?rev=669228&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java (added) +++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java Wed Jun 18 10:09:45 2008 @@ -0,0 +1,38 @@ +/* + * 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 ContainsMatcher implements Matcher { + + public Map match(String expression, String testValue) { + if (testValue == null) { + return null; + } + + if (testValue.contains(expression)) { + Map result = new HashMap(); + result.put("0", testValue); + return result; + } + + return null; + } + +} Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/ContainsMatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java?rev=669228&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java (added) +++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java Wed Jun 18 10:09:45 2008 @@ -0,0 +1,38 @@ +/* + * 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 EqualsMatcher implements Matcher { + + public Map match(String expression, String testValue) { + if (testValue == null) { + return null; + } + + if (testValue.equals(expression)) { + Map result = new HashMap(); + result.put("0", testValue); + return result; + } + + return null; + } + +} Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/EqualsMatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: 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=669228&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java (added) +++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java Wed Jun 18 10:09:45 2008 @@ -0,0 +1,24 @@ +/* + * 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.Map; + +public interface Matcher { + + Map match(String testValue, String expression); +} Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/Matcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java?rev=669228&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java (added) +++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java Wed Jun 18 10:09:45 2008 @@ -0,0 +1,56 @@ +/* + * 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; +import java.util.regex.Pattern; + +public class RegexpMatcher implements Matcher { + + private static Map patterns = new HashMap(); + + public Map match(String expression, String testValue) { + if (testValue == null) { + return null; + } + + Pattern pattern = patterns.get(expression); + if (pattern == null) { + pattern = Pattern.compile(expression); + patterns.put(expression, pattern); + } + + java.util.regex.Matcher matcher = null; + if (testValue.startsWith("/")) { + matcher = pattern.matcher(testValue.substring(1)); + } else { + matcher = pattern.matcher(testValue); + } + + if (matcher.matches()) { + Map result = new HashMap(); + for (int i = 0; i <= matcher.groupCount(); i++) { + result.put(Integer.toString(i), matcher.group(i)); + } + return result; + } + + return null; + } + +} Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/RegexpMatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java?rev=669228&view=auto ============================================================================== --- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java (added) +++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java Wed Jun 18 10:09:45 2008 @@ -0,0 +1,37 @@ +/* + * 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.Map; + +import org.apache.cocoon.corona.sitemap.util.WildcardMatcherHelper; + +public class WildcardMatcher implements Matcher { + + public Map match(String expression, String testValue) { + if (testValue == null) { + return null; + } + + if (testValue.startsWith("/")) { + return WildcardMatcherHelper.match(expression, testValue.substring(1)); + } + + return WildcardMatcherHelper.match(expression, testValue); + } + +} Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/matcher/WildcardMatcher.java ------------------------------------------------------------------------------ svn:mime-type = text/plain 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=669228&r1=669227&r2=669228&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 Wed Jun 18 10:09:45 2008 @@ -18,15 +18,16 @@ */ package org.apache.cocoon.corona.sitemap.node; -import java.util.HashMap; +import java.util.LinkedList; import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.cocoon.corona.sitemap.Invocation; +import org.apache.cocoon.corona.sitemap.matcher.ContainsMatcher; +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.WildcardMatcher; import org.apache.cocoon.corona.sitemap.node.annotations.Parameter; -import org.apache.cocoon.corona.sitemap.util.WildcardMatcherHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,8 +36,6 @@ private final Log logger = LogFactory.getLog(this.getClass()); - private static final Map patterns = new HashMap(); - @Parameter private String name; @@ -58,7 +57,7 @@ @Parameter private String wildcard; - private boolean inMatchingMode; + private MatcherContext matcherContext; /** * {@inheritDoc} @@ -69,8 +68,8 @@ public InvocationResult invoke(Invocation invocation) { if (invocation.isErrorInvocation() && !this.hasHandleErrorsParent(this.getParent())) { if (this.logger.isDebugEnabled()) { - this.logger - .debug("Stop here because it's an error invocation and this node is defined outside of ."); + this.logger.debug("Stop here because it's an error invocation " + + "and this node is defined outside of ."); } return InvocationResult.NONE; } @@ -81,12 +80,9 @@ testValue = invocation.getRequestURI(); } - // find out the matching method - Map matchingAttribute = this.prepareMatching(); - this.inMatchingMode = matchingAttribute.size() == 1; - + this.matcherContext = this.lookupMatcherContext(); // if there are NO matching attributes (regexp, equals, ...) set, execute the children - if (!this.inMatchingMode) { + if (this.matcherContext == null) { InvocationResult invocationResult = super.invoke(invocation); if (invocationResult.isProcessed()) { @@ -97,7 +93,7 @@ } // if there are matching attributes, invoke the matcher and execute the children afterwards - Map matches = this.getMatches(matchingAttribute, testValue); + Map matches = this.matcherContext.matcher.match(this.matcherContext.value, testValue); if (matches == null) { // do not ask our children, there was no match return InvocationResult.NONE; @@ -114,166 +110,48 @@ return InvocationResult.NONE; } - protected boolean hasHandleErrorsParent(SitemapNode parent) { - SitemapNode currentNode = parent; - - while (currentNode != null) { - if (currentNode instanceof ErrorNode) { - return true; - } - currentNode = currentNode.getParent(); - } - - return false; - } - - protected Map getMatches(Map matchingAttributes, String value) { - String matchingAttributeType = null; - String matchingAttributeValue = null; - Map matches = null; - if (matchingAttributes.size() == 1) { - for (Entry attribute : matchingAttributes.entrySet()) { - matchingAttributeType = attribute.getKey(); - matchingAttributeValue = attribute.getValue(); - } - - if ("wildcard".equals(matchingAttributeType)) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Invoking wildcard matcher: test=" + value + ", wildcard=" - + matchingAttributeValue); - } - - matches = getWildcardMatches(value, matchingAttributeValue); - } else if ("regexp".equals(matchingAttributeType)) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Invoking regexp matcher: test=" + value + ", regexp=" + matchingAttributeValue); - } - - matches = getReqexpMatches(value, matchingAttributeValue); - } else if ("contains".equals(matchingAttributeType)) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Invoking contains matcher: test=" + value + ", contains=" - + matchingAttributeValue); - } - - matches = getContainsMatches(value, matchingAttributeValue); - } else if ("pattern".equals(matchingAttributeType)) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Invoking wildcard matcher: test=" + value + ", pattern=" - + matchingAttributeValue); - } - - matches = getWildcardMatches(value, matchingAttributeValue); - } else if ("equals".equals(matchingAttributeType)) { - if (this.logger.isDebugEnabled()) { - this.logger.debug("Invoking equals matcher: test=" + value + ", equals=" + matchingAttributeValue); - } - - matches = getEqualsMatches(value, matchingAttributeValue); - } - } - - return matches; - } - - protected Map prepareMatching() { + protected MatcherContext lookupMatcherContext() { // determine the matching type and check if there are conflicting match attributes - Map matchingAttributes = new HashMap(); + LinkedList matcherContextList = new LinkedList(); if (this.pattern != null) { - matchingAttributes.put("pattern", this.pattern); + matcherContextList.add(new MatcherContext(new WildcardMatcher(), this.pattern)); } if (this.regexp != null) { - matchingAttributes.put("regexp", this.regexp); + matcherContextList.add(new MatcherContext(new RegexpMatcher(), this.regexp)); } if (this.equals != null) { - matchingAttributes.put("equals", this.equals); + matcherContextList.add(new MatcherContext(new EqualsMatcher(), this.equals)); } if (this.contains != null) { - matchingAttributes.put("contains", this.contains); + matcherContextList.add(new MatcherContext(new ContainsMatcher(), this.contains)); } if (this.wildcard != null) { - matchingAttributes.put("wildcard", this.wildcard); + matcherContextList.add(new MatcherContext(new WildcardMatcher(), this.wildcard)); } - if (matchingAttributes.size() > 1) { + if (matcherContextList.size() > 1) { String message = "Only one matching attribute (regexp, equals, contains, wildcard, pattern) can be set: " - + matchingAttributes; + + matcherContextList; this.logger.error(message); throw new RuntimeException(message); } - return matchingAttributes; + return matcherContextList.isEmpty() ? null : matcherContextList.getFirst(); } - private static Map getContainsMatches(String value, String matchingAttributeValue) { - if (value == null) { - return null; - } - - if (value.contains(matchingAttributeValue)) { - Map result = new HashMap(); - result.put("0", value); - return result; - } - - return null; - } - - private static Map getEqualsMatches(String value, String matchingAttributeValue) { - if (value == null) { - return null; - } - - if (value.equals(matchingAttributeValue)) { - Map result = new HashMap(); - result.put("0", value); - return result; - } - - return null; - } - - private static Map getReqexpMatches(String value, String matchingAttributeValue) { - if (value == null) { - return null; - } - - Pattern pattern = patterns.get(matchingAttributeValue); - if (pattern == null) { - pattern = Pattern.compile(matchingAttributeValue); - patterns.put(matchingAttributeValue, pattern); - } - - Matcher matcher = null; - if (value.startsWith("/")) { - matcher = pattern.matcher(value.substring(1)); - } else { - matcher = pattern.matcher(value); - } + protected boolean hasHandleErrorsParent(SitemapNode parent) { + SitemapNode currentNode = parent; - if (matcher.matches()) { - Map result = new HashMap(); - for (int i = 0; i <= matcher.groupCount(); i++) { - result.put(Integer.toString(i), matcher.group(i)); + while (currentNode != null) { + if (currentNode instanceof ErrorNode) { + return true; } - return result; - } - - return null; - } - - private static Map getWildcardMatches(String value, String wildcard) { - if (value == null) { - return null; - } - - if (value.startsWith("/")) { - return WildcardMatcherHelper.match(wildcard, value.substring(1)); + currentNode = currentNode.getParent(); } - return WildcardMatcherHelper.match(wildcard, value); + return false; } public boolean isInMatchingMode() { - return this.inMatchingMode; + return this.matcherContext != null; } public void setValue(String value) { @@ -283,4 +161,23 @@ public String getValue() { return this.value; } + + protected static class MatcherContext { + + public Matcher matcher; + public String value; + + public MatcherContext(Matcher matcher, String testValue) { + super(); + this.matcher = matcher; + this.value = testValue; + } + + @Override + public String toString() { + // TODO Auto-generated method stub + return "matcher=" + this.matcher + ", testValue=" + this.value; + } + } + } 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=669228&r1=669227&r2=669228&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 Wed Jun 18 10:09:45 2008 @@ -22,6 +22,7 @@ import junitx.util.PrivateAccessor; +import org.apache.cocoon.corona.sitemap.node.MatchNode.MatcherContext; import org.junit.Test; public class MatchNodeTest { @@ -30,7 +31,8 @@ public void regexpMatchingAttribute() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "regexp", "([a-zA-Z\\-]+)/(.*)"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "abc/44"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "abc/44"); assertTrue(matches.containsValue("abc/44")); assertTrue(matches.containsValue("abc")); assertTrue(matches.containsValue("44")); @@ -41,7 +43,8 @@ public void regexpMatchingAttributeWithSlash() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "regexp", "([a-zA-Z\\-]+)/(.*)"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "/abc/44"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "abc/44"); assertTrue(matches.containsValue("abc/44")); assertTrue(matches.containsValue("abc")); assertTrue(matches.containsValue("44")); @@ -52,7 +55,8 @@ public void containsMatchingAttribute() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "contains", "123"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "000123456"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "000123456"); assertTrue(matches.containsValue("000123456")); assertEquals(1, matches.size()); } @@ -61,7 +65,8 @@ public void equalsMatchingAttribute() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "equals", "123"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "123"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "123"); assertTrue(matches.containsValue("123")); assertEquals(1, matches.size()); } @@ -70,7 +75,8 @@ public void wildcardMatchingPathAttribute() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "wildcard", "abc/*/*"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "abc/def/ghi"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "abc/def/ghi"); assertTrue(matches.containsValue("abc/def/ghi")); assertTrue(matches.containsValue("def")); assertTrue(matches.containsValue("ghi")); @@ -81,7 +87,8 @@ public void wildcardMatchingPathAttributeWithSlash() throws Exception { MatchNode matchNode = new MatchNode(); PrivateAccessor.setField(matchNode, "wildcard", "abc/*/*"); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "/abc/def/ghi"); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + Map matches = matcherContext.matcher.match(matcherContext.value, "abc/def/ghi"); assertTrue(matches.containsValue("abc/def/ghi")); assertTrue(matches.containsValue("def")); assertTrue(matches.containsValue("ghi")); @@ -91,8 +98,8 @@ @Test public void noMatchingAttribute() { MatchNode matchNode = new MatchNode(); - Map matches = matchNode.getMatches(matchNode.prepareMatching(), "123"); - assertNull("If there is no match, null has to be returned.", matches); + MatcherContext matcherContext = matchNode.lookupMatcherContext(); + assertNull("If there is no match attribute, no matcher can be found.", matcherContext); } @Test @@ -101,7 +108,7 @@ PrivateAccessor.setField(matchNode, "pattern", "123"); PrivateAccessor.setField(matchNode, "equals", "123"); try { - matchNode.getMatches(matchNode.prepareMatching(), "123"); + matchNode.lookupMatcherContext(); fail(); } catch (Exception e) { // expected