From 515dc95746aa33bf1472b917d924af3c0bc2dae1 Mon Sep 17 00:00:00 2001 From: Brett Ryan Date: Thu, 9 Jul 2015 01:19:47 +1000 Subject: [PATCH 1/3] Correct NPE with Attribute#toString. --- tiles-api/src/main/java/org/apache/tiles/Attribute.java | 2 +- tiles-api/src/test/java/org/apache/tiles/AttributeTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tiles-api/src/main/java/org/apache/tiles/Attribute.java b/tiles-api/src/main/java/org/apache/tiles/Attribute.java index ee0652cb1..b12cb567e 100644 --- a/tiles-api/src/main/java/org/apache/tiles/Attribute.java +++ b/tiles-api/src/main/java/org/apache/tiles/Attribute.java @@ -289,7 +289,7 @@ public String toString() { if (value != null) { return value.toString(); } - return null; + return "null"; } /** diff --git a/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java b/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java index 68105f315..ce09b51c1 100644 --- a/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java +++ b/tiles-api/src/test/java/org/apache/tiles/AttributeTest.java @@ -203,7 +203,7 @@ public void testToString() { roles.add("role2"); assertEquals("my.value", attribute.toString()); attribute.setValue(null); - assertNull(attribute.toString()); + assertEquals(attribute.toString(), "null"); } /** From 41759e82bbc1b4ec15878caba6bf6b659d256886 Mon Sep 17 00:00:00 2001 From: Brett Ryan Date: Thu, 9 Jul 2015 01:26:21 +1000 Subject: [PATCH 2/3] Added support for list attributes to have expressions. - This will certainly need review as the current implementation breaks current behavior with relation to attributes from list attributes being exposed to the view, while simple attributes are not. - This implementation maps everything to the objects represented type where possible, though due to current requirements elements must remain to be an attribute wrapping the value. - Attribute#getExpression is evaluated and set against a cloned version of Attribute#setValue. --- .../evaluator/AbstractAttributeEvaluator.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tiles-core/src/main/java/org/apache/tiles/evaluator/AbstractAttributeEvaluator.java b/tiles-core/src/main/java/org/apache/tiles/evaluator/AbstractAttributeEvaluator.java index 82542a690..ceb5cd047 100644 --- a/tiles-core/src/main/java/org/apache/tiles/evaluator/AbstractAttributeEvaluator.java +++ b/tiles-core/src/main/java/org/apache/tiles/evaluator/AbstractAttributeEvaluator.java @@ -18,11 +18,18 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.tiles.evaluator; +import java.util.ArrayList; +import java.util.List; import org.apache.tiles.Attribute; import org.apache.tiles.Expression; +import org.apache.tiles.ListAttribute; import org.apache.tiles.request.Request; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Abstract class to link a correct evaluation of an attribute, by evaluating @@ -33,7 +40,10 @@ */ public abstract class AbstractAttributeEvaluator implements AttributeEvaluator { + private static final Logger log = LoggerFactory.getLogger(AbstractAttributeEvaluator.class); + /** {@inheritDoc} */ + @Override public Object evaluate(Attribute attribute, Request request) { if (attribute == null) { throw new IllegalArgumentException("The attribute cannot be null"); @@ -44,11 +54,49 @@ public Object evaluate(Attribute attribute, Request request) { if (retValue == null) { Expression expression = attribute.getExpressionObject(); if (expression != null) { + log.debug("Evaluating expression: [attribute={},expression={}]", attribute, expression); retValue = evaluate(attribute.getExpressionObject() .getExpression(), request); } + } else if (retValue instanceof List) { + log.debug("Evaluating list for expressions: {}", retValue); + retValue = evaluateList((List) retValue, request); } + log.debug("Returning result: {}", retValue); return retValue; } + + private List evaluateList(List src, Request request) { + List res = new ArrayList(); + for (Object val : src) { + if (val instanceof ListAttribute) { + log.debug("Evaluating list entry (ListAttribute): {}", val); + res.add(evaluateList(((ListAttribute) val).getValue(), request)); + } else if (val instanceof Attribute) { + log.debug("Evaluating list entry (Attribute): {}", val); + Attribute att = (Attribute) val; + if (att.getValue() != null) { + res.add(att.getValue() instanceof List + ? evaluateList((List) att.getValue(), request) + : att); + } else { + Expression expression = att.getExpressionObject(); + if (expression != null) { + log.debug("Evaluating list entry expression: {}", expression); + att = att.clone(); + att.setValue(evaluate(expression.getExpression(), request)); + res.add(att); + } else { + res.add(att); + } + } + } else { + log.debug("Evaluating list entry ({}): {}", val.getClass(), val); + res.add(val); + } + } + return res; + } + } From be97c75393f9d72cfebe717146db88608427429d Mon Sep 17 00:00:00 2001 From: Brett Ryan Date: Mon, 15 Jun 2015 09:49:29 +1000 Subject: [PATCH 3/3] Added git ignore/attributes. --- .gitattributes | 30 ++++++++++++++++++++++++++++++ .gitignore | 25 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..4eebd49bc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,30 @@ +# Handle line endings automatically for files detected as text +# and leave all files detected as binary untouched. +* text=auto + +# +# The above will handle all files NOT found below +# +# These files are text and should be normalized (Convert crlf => lf) +*.css text +*.df text +*.java text +*.js text +*.json text +*.jsp text +*.properties text +*.sql text +*.svg text +*.tld text +*.txt text +*.xml text + +# These files are binary and should be left untouched +# (binary is a macro for -text -diff) +*.dll binary +*.gif binary +*.ico binary +*.jar binary +*.png binary +*.so binary + diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..0163e1860 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/target/ +/tiles-api/target/ +/tiles-core/target/ +/tiles-template/target/ +/tiles-servlet/target/ +/tiles-jsp/target/ +/tiles-freemarker/target/ +/tiles-velocity/target/ +/tiles-el/target/ +/tiles-ognl/target/ +/tiles-mvel/target/ +/tiles-compat/target/ +/tiles-extras/target/ +/tiles-test-pom/tiles-test-db/target/ +/tiles-test-pom/tiles-test-alt/target/ +/tiles-test-pom/target/ +/tiles-test-pom/tiles-test-common/target/ +/tiles-test-pom/tiles-test/target/ +/assembly/target/ +*~ +*.bak +*.swp +*.log +.DS_Store +pom.xml.versionsBackup