You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/07/25 02:16:56 UTC
svn commit: r679628 - in
/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node:
MatchNode.java OtherwiseNode.java SelectNode.java WhenNode.java
Author: reinhard
Date: Thu Jul 24 17:16:56 2008
New Revision: 679628
URL: http://svn.apache.org/viewvc?rev=679628&view=rev
Log:
. fix bug with empty matching but empty when nodes
. tidy up InvocationResult handling
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/main/java/org/apache/cocoon/corona/sitemap/node/OtherwiseNode.java
cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/SelectNode.java
cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/WhenNode.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=679628&r1=679627&r2=679628&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 Jul 24 17:16:56 2008
@@ -67,6 +67,8 @@
private MatcherContext matcherContext;
+ private Map<String, String> matches;
+
/**
* {@inheritDoc}
*
@@ -74,14 +76,6 @@
*/
@Override
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 <handle-errors>.");
- }
- return InvocationResult.NONE;
- }
-
// try to resolve the test value in the case that it is an expression
String testValue = invocation.resolveParameter(this.value);
if (testValue == null) {
@@ -91,32 +85,40 @@
// create the matching context based on the used matching attributes (regexp, equals, etc.)
this.matcherContext = this.lookupMatcherContext();
if (this.matcherContext == null) {
- throw new RuntimeException(
- "Use on of the matching attributes: wildcard, equals, regexp, starts-with, ends-with, contains");
+ throw new MatchingAttributeException("Use on of the matching attributes: "
+ + "wildcard, equals, regexp, starts-with, ends-with, contains");
}
- // invoke the matcher and execute the children afterwards
- Map<String, String> matches = this.matcherContext.match(testValue);
- if (matches == null) {
- // do not ask our children, there was no match
+ this.matches = this.matcherContext.match(testValue);
+ if (this.matches == null) {
+ // do not ask the children, there was no match
return InvocationResult.NONE;
}
- invocation.pushSitemapParameters(this.name, matches);
+ // invoke the child nodes
+ invocation.pushSitemapParameters(this.name, this.matches);
InvocationResult invocationResult = super.invoke(invocation);
invocation.popSitemapParameters();
+ // check if there has been some processing in the child nodes
if (invocationResult.isContinued()) {
+ // stop here if the invocation contains a complete pipeline
if (invocation.hasCompletePipeline()) {
return InvocationResult.COMPLETED;
- } else {
- return InvocationResult.CONTINUE;
}
+
+ // continue with the next sibling node
+ return InvocationResult.CONTINUE;
}
+ // although this match node has matched, there was no processing in the child nodes
return InvocationResult.NONE;
}
+ protected boolean isMatching() {
+ return this.matches != null;
+ }
+
/**
* Find out what matching attribute (pattern, wildcard, equals, etc.) is used, check that it's not more than one
* that is used and throw an exception otherwise.
@@ -149,28 +151,11 @@
String message = "Only one matching attribute (regexp, equals, contains, wildcard, pattern) can be set: "
+ matcherContextList;
this.logger.error(message);
- throw new RuntimeException(message);
+ throw new MatchingAttributeException(message);
}
return matcherContextList.isEmpty() ? null : matcherContextList.getFirst();
}
- protected boolean hasHandleErrorsParent(SitemapNode parent) {
- SitemapNode currentNode = parent;
-
- while (currentNode != null) {
- if (currentNode instanceof ErrorNode) {
- return true;
- }
- currentNode = currentNode.getParent();
- }
-
- return false;
- }
-
- public boolean isInMatchingMode() {
- return this.matcherContext != null;
- }
-
public void setValue(String value) {
this.value = value;
}
@@ -209,4 +194,11 @@
return "matcher=" + this.matcher + ", expression=" + this.expression;
}
}
+
+ private static class MatchingAttributeException extends RuntimeException {
+
+ public MatchingAttributeException(String message) {
+ super(message);
+ }
+ }
}
\ No newline at end of file
Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/OtherwiseNode.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/OtherwiseNode.java?rev=679628&r1=679627&r2=679628&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/OtherwiseNode.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/OtherwiseNode.java Thu Jul 24 17:16:56 2008
@@ -18,6 +18,8 @@
*/
package org.apache.cocoon.corona.sitemap.node;
+import java.util.HashMap;
+
import org.apache.cocoon.corona.sitemap.Invocation;
@Node(name = "otherwise")
@@ -32,15 +34,19 @@
public InvocationResult invoke(Invocation invocation) {
this.checkParent();
- InvocationResult result = super.invoke(invocation);
+ // execute the child nodes
+ invocation.pushSitemapParameters(null, new HashMap<String, Object>());
+ super.invoke(invocation);
+ invocation.popSitemapParameters();
+
+ // if the pipeline has been finished within the otherwise section,
+ // stop the execution
if (invocation.hasCompletePipeline()) {
return InvocationResult.COMPLETED;
}
- if (result.isContinued()) {
- return InvocationResult.BREAK;
- }
- return InvocationResult.NONE;
+ // send the BREAK signal
+ return InvocationResult.BREAK;
}
protected void checkParent() {
Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/SelectNode.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/SelectNode.java?rev=679628&r1=679627&r2=679628&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/SelectNode.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/SelectNode.java Thu Jul 24 17:16:56 2008
@@ -36,19 +36,13 @@
public InvocationResult invoke(Invocation invocation) {
InvocationResult invocationResult = super.invoke(invocation);
- if (invocationResult == InvocationResult.BREAK) {
- if (invocation.hasCompletePipeline()) {
- return InvocationResult.COMPLETED;
- }
-
- return InvocationResult.CONTINUE;
+ // a complete pipeline has been built
+ if (invocation.hasCompletePipeline()) {
+ return InvocationResult.COMPLETED;
}
- if (invocationResult.isContinued()) {
- if (invocation.hasCompletePipeline()) {
- return InvocationResult.COMPLETED;
- }
-
+ // one of the child nodes (when/otherwise) matched
+ if (invocationResult == InvocationResult.BREAK) {
return InvocationResult.CONTINUE;
}
Modified: cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/WhenNode.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/WhenNode.java?rev=679628&r1=679627&r2=679628&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/WhenNode.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-sitemap/src/main/java/org/apache/cocoon/corona/sitemap/node/WhenNode.java Thu Jul 24 17:16:56 2008
@@ -28,16 +28,25 @@
this.checkParent();
InvocationResult result = super.invoke(invocation);
+
+ // if a complete pipeline has been built, stop here
if (invocation.hasCompletePipeline()) {
return InvocationResult.COMPLETED;
}
- if (result.isContinued()) {
+ // if the when node is matching, send the break signal because any of the sibling nodes (when/otherwise) should
+ // be executed
+ if (this.isMatching()) {
return InvocationResult.BREAK;
}
+
+ // the when node is not matching
return result;
}
+ /**
+ * Check if the parent is a select node.
+ */
protected void checkParent() {
if (this.getParent() instanceof SelectNode) {
SelectNode parentMatchNode = (SelectNode) this.getParent();