cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject svn commit: r106437 - /cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
Date Wed, 24 Nov 2004 17:35:48 GMT
Author: unico
Date: Wed Nov 24 09:35:45 2004
New Revision: 106437

URL: http://svn.apache.org/viewcvs?view=rev&rev=106437
Log:
jxtg validity should be combination of evaluated validity and the template source's validity
Modified:
   cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java?view=diff&rev=106437&p1=cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java&r1=106436&p2=cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java&r2=106437
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java	Wed Nov 24
09:35:45 2004
@@ -3212,11 +3212,15 @@
 	public SourceValidity getValidity() {
     	JXTExpression validityExpr = (JXTExpression)getCurrentTemplateProperty(VALIDITY);
         try {
-			return (SourceValidity)getValue(validityExpr, globalJexlContext, jxpathContext);
+            final SourceValidity sourceValidity = this.inputSource.getValidity();
+            final SourceValidity templateValidity = (SourceValidity) getValue(validityExpr,
globalJexlContext, jxpathContext);
+            if (sourceValidity != null && templateValidity != null) {
+                return new JXSourceValidity(sourceValidity, templateValidity);
+            }
 		} catch (Exception e) {
-			getLogger().error( "error evaluating cache key", e );
-			return null;
+			getLogger().error( "error evaluating cache validity", e );
 		}
+		return null;
 	}
 	
 	private Object getCurrentTemplateProperty(String propertyName) {
@@ -3239,7 +3243,7 @@
         Node node = builder.getDocument().getDocumentElement();
         return node.getChildNodes();
 	}
-	
+
 	static final class JXCacheKey implements Serializable {
 	    private final String templateUri;
 	    private final Serializable templateKey;
@@ -3262,4 +3266,50 @@
 	        return false;
 	    }
 	}
+
+    static final class JXSourceValidity implements SourceValidity, Serializable {
+        private final SourceValidity sourceValidity;
+        private final SourceValidity templateValidity;
+        private JXSourceValidity(SourceValidity sourceValidity, SourceValidity templateValidity)
{
+            this.sourceValidity = sourceValidity;
+            this.templateValidity = templateValidity;
+        }
+
+        public int isValid() {
+            switch (sourceValidity.isValid()) {
+                case SourceValidity.INVALID: return SourceValidity.INVALID;
+                case SourceValidity.UNKNOWN: {
+                    if (templateValidity.isValid() == SourceValidity.INVALID) {
+                        return SourceValidity.INVALID;
+                    }
+                    else {
+                        return SourceValidity.UNKNOWN;
+                    }
+                }
+                case SourceValidity.VALID: return templateValidity.isValid();
+            }
+            return SourceValidity.UNKNOWN;
+        }
+
+        public int isValid(SourceValidity otherValidity) {
+            if (otherValidity instanceof JXSourceValidity) {
+                JXSourceValidity otherJXValidity = (JXSourceValidity) otherValidity;
+                switch (sourceValidity.isValid(otherJXValidity.sourceValidity)) {
+                	case SourceValidity.INVALID: return SourceValidity.INVALID;
+                	case SourceValidity.UNKNOWN: {
+                	    if (templateValidity.isValid(otherJXValidity.templateValidity) == SourceValidity.INVALID)
{
+                	        return SourceValidity.INVALID;
+                	    }
+                	    else {
+                	        return SourceValidity.UNKNOWN;
+                	    }
+                	}
+                	case SourceValidity.VALID: return templateValidity.isValid(otherJXValidity.templateValidity);
+                }
+            }
+            return 0;
+        }
+
+    }
+
 }

Mime
View raw message