You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/01/08 21:20:20 UTC

[01/13] incubator-freemarker git commit: merging the commit to 2.3-gae

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 6750d92be -> fbd6fa5f9


merging the commit to 2.3-gae


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/d66cf48d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/d66cf48d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/d66cf48d

Branch: refs/heads/2.3-gae
Commit: d66cf48dbaf31428dd41abfe88a2f79b98f647d5
Parents: 6166efe
Author: Pradeep <pr...@trimble.com>
Authored: Sat Oct 24 01:33:15 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 17:21:42 2016 +0530

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java      | 12 ++++++---
 .../java/freemarker/core/BuiltInExtForNode.java | 21 ++++++++++++++++
 .../freemarker/core/BuiltInExtForNodes.java     | 26 ++++++++++++++++++++
 .../java/freemarker/core/BuiltinVariable.java   |  6 ++++-
 .../java/freemarker/ext/dom/ElementModel.java   | 14 +++++++++++
 src/main/java/freemarker/ext/dom/NodeModel.java | 23 +++++++++++++++--
 .../template/TemplateNodeModelExt.java          | 17 +++++++++++++
 7 files changed, 113 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index ab796b0..63f2574 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -62,6 +62,8 @@ import freemarker.core.BuiltInsForSequences.seq_index_ofBI;
 import freemarker.core.BuiltInsForSequences.sortBI;
 import freemarker.core.BuiltInsForSequences.sort_byBI;
 import freemarker.core.BuiltInsForStringsMisc.evalBI;
+import freemarker.core.BuiltInExtForNodes.previousSiblingBI;
+import freemarker.core.BuiltInExtForNodes.nextSiblingBI;
 import freemarker.template.Configuration;
 import freemarker.template.TemplateDateModel;
 import freemarker.template.TemplateModel;
@@ -81,9 +83,10 @@ abstract class BuiltIn extends Expression implements Cloneable {
 
     static final Set<String> CAMEL_CASE_NAMES = new TreeSet<String>();
     static final Set<String> SNAKE_CASE_NAMES = new TreeSet<String>();
-    
-    static final int NUMBER_OF_BIS = 259;
-    static final HashMap<String, BuiltIn> BUILT_INS_BY_NAME = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
+
+    static final int NUMBER_OF_BIS = 261;
+    static final HashMap builtins = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
+
     static {
         // Note that you must update NUMBER_OF_BIS if you add new items here!
         
@@ -246,6 +249,8 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("number_to_time", "numberToTime", new number_to_dateBI(TemplateDateModel.TIME));
         putBI("number_to_datetime", "numberToDatetime", new number_to_dateBI(TemplateDateModel.DATETIME));
         putBI("parent", new parentBI());
+        putBI("previousSibling", new previousSiblingBI());
+        putBI("nextSibling", new nextSiblingBI());
         putBI("item_parity", "itemParity", new BuiltInsForLoopVariables.item_parityBI());
         putBI("item_parity_cap", "itemParityCap", new BuiltInsForLoopVariables.item_parity_capBI());
         putBI("reverse", new reverseBI());
@@ -284,6 +289,7 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("matches", new BuiltInsForStringsRegexp.matchesBI());
         putBI("groups", new BuiltInsForStringsRegexp.groupsBI());
         putBI("replace", new BuiltInsForStringsRegexp.replace_reBI());
+
         
         if (NUMBER_OF_BIS < BUILT_INS_BY_NAME.size()) {
             throw new AssertionError("Update NUMBER_OF_BIS! Should be: " + BUILT_INS_BY_NAME.size());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/core/BuiltInExtForNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInExtForNode.java b/src/main/java/freemarker/core/BuiltInExtForNode.java
new file mode 100644
index 0000000..7e859b8
--- /dev/null
+++ b/src/main/java/freemarker/core/BuiltInExtForNode.java
@@ -0,0 +1,21 @@
+package freemarker.core;
+
+import freemarker.template.*;
+
+/**
+ * Created by Pmuruge on 10/23/2015.
+ */
+public abstract class BuiltInExtForNode extends BuiltIn {
+    @Override
+    TemplateModel _eval(Environment env)
+            throws TemplateException {
+        TemplateModel model = target.eval(env);
+        if (model instanceof TemplateNodeModelExt) {
+            return calculateResult((TemplateNodeModelExt) model, env);
+        } else {
+            throw new NonNodeException(target, model, env);
+        }
+    }
+    abstract TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env)
+            throws TemplateModelException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/core/BuiltInExtForNodes.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInExtForNodes.java b/src/main/java/freemarker/core/BuiltInExtForNodes.java
new file mode 100644
index 0000000..eeb20a8
--- /dev/null
+++ b/src/main/java/freemarker/core/BuiltInExtForNodes.java
@@ -0,0 +1,26 @@
+package freemarker.core;
+
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNodeModelExt;
+
+/**
+ * Created by Pmuruge on 10/23/2015.
+ */
+public class BuiltInExtForNodes {
+
+    static class previousSiblingBI extends BuiltInExtForNode {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getPreviousSibling();
+        }
+    }
+
+    static class nextSiblingBI extends  BuiltInExtForNode {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getNextSibling();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/core/BuiltinVariable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java
index 5b0f4d2..0afea07 100644
--- a/src/main/java/freemarker/core/BuiltinVariable.java
+++ b/src/main/java/freemarker/core/BuiltinVariable.java
@@ -72,6 +72,8 @@ final class BuiltinVariable extends Expression {
     static final String URL_ESCAPING_CHARSET_CC = "urlEscapingCharset";
     static final String URL_ESCAPING_CHARSET = "url_escaping_charset";
     static final String NOW = "now";
+    static final String PREVIOUS_SIBLING = "previous";
+    static final String NEXT_SIBLING = "next";
     
     static final String[] SPEC_VAR_NAMES = new String[] {
         AUTO_ESC_CC,
@@ -107,7 +109,9 @@ final class BuiltinVariable extends Expression {
         URL_ESCAPING_CHARSET_CC,
         URL_ESCAPING_CHARSET,
         VARS,
-        VERSION
+        VERSION,
+        PREVIOUS_SIBLING,
+        NEXT_SIBLING
     };
 
     private final String name;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index fb6fccd..95e13fc 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -89,6 +89,20 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                 nu.outputContent(node.getAttributes(), buf);
                 return new SimpleScalar(buf.toString().trim());
             }
+            if (key.equals("@@previous")) {
+                XPathSupport xps = getXPathSupport();
+                if (xps != null) {
+                    return xps.executeQuery(node, "preceding-sibling::*[position()=1]");
+                }
+            }
+            if (key.equals("@@next")) {
+                XPathSupport xps = getXPathSupport();
+                if (xps != null) {
+                    TemplateModel next = xps.executeQuery(node, "following-sibling::*[position()=1]");
+                    System.out.println(next.toString());
+                    return next;
+                }
+            }
             if (StringUtil.isXMLID(key.substring(1))) {
                 Attr att = getAttribute(key.substring(1));
                 if (att == null) { 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/ext/dom/NodeModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/NodeModel.java b/src/main/java/freemarker/ext/dom/NodeModel.java
index c338664..c518333 100644
--- a/src/main/java/freemarker/ext/dom/NodeModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeModel.java
@@ -59,6 +59,7 @@ import freemarker.template.TemplateHashModel;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateNodeModel;
+import freemarker.template.TemplateNodeModelExt;
 import freemarker.template.TemplateNumberModel;
 import freemarker.template.TemplateSequenceModel;
 
@@ -75,7 +76,7 @@ import freemarker.template.TemplateSequenceModel;
  * then), but should be used to represent a node set of exactly 1 node.
  */
 abstract public class NodeModel
-implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel,
+implements TemplateNodeModel, TemplateNodeModelExt, TemplateHashModel, TemplateSequenceModel,
     AdapterTemplateModel, WrapperTemplateModel, _UnexpectedTypeErrorExplainerTemplateModel {
 
     static private final Logger LOG = Logger.getLogger("freemarker.dom");
@@ -109,6 +110,8 @@ implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel,
     final Node node;
     private TemplateSequenceModel children;
     private NodeModel parent;
+    private NodeModel previousSibling;
+    private NodeModel nextSibling;
     
     /**
      * Sets the DOM Parser implementation to be used when building NodeModel
@@ -307,7 +310,23 @@ implements TemplateNodeModel, TemplateHashModel, TemplateSequenceModel,
         }
         return parent;
     }
-    
+
+    public TemplateNodeModel getPreviousSibling() throws TemplateModelException {
+        if (previousSibling == null) {
+            Node previous = node.getPreviousSibling();
+            previousSibling = wrap(previous);
+        }
+        return previousSibling;
+    }
+
+    public TemplateNodeModel getNextSibling() throws TemplateModelException {
+        if (nextSibling == null) {
+            Node next = node.getNextSibling();
+            nextSibling = wrap(next);
+        }
+        return nextSibling;
+    }
+
     public TemplateSequenceModel getChildNodes() {
         if (children == null) {
             children = new NodeListModel(node.getChildNodes(), this);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d66cf48d/src/main/java/freemarker/template/TemplateNodeModelExt.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateNodeModelExt.java b/src/main/java/freemarker/template/TemplateNodeModelExt.java
new file mode 100644
index 0000000..d2c8be0
--- /dev/null
+++ b/src/main/java/freemarker/template/TemplateNodeModelExt.java
@@ -0,0 +1,17 @@
+package freemarker.template;
+
+/**
+ * Created by Pmuruge on 10/22/2015.
+ */
+public interface TemplateNodeModelExt extends TemplateNodeModel {
+
+    /**
+     * @return the immediate Previous Sibling of this node
+     */
+    TemplateNodeModel getPreviousSibling() throws TemplateModelException;
+
+    /**
+     * @return the immediate next Sibling of this node
+     */
+    TemplateNodeModel getNextSibling() throws TemplateModelException;
+}


[05/13] incubator-freemarker git commit: remove the author name

Posted by dd...@apache.org.
remove the author name


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/9e73d008
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/9e73d008
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/9e73d008

Branch: refs/heads/2.3-gae
Commit: 9e73d008fc8e4f15453f4029e5ae30e822f1ccb2
Parents: ada5afe
Author: Pradeep <pr...@trimble.com>
Authored: Tue Nov 3 11:40:16 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:20:23 2016 +0530

----------------------------------------------------------------------
 src/test/java/freemarker/core/SiblingTest.java | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/9e73d008/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index cda5430..b38cec0 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -13,8 +13,23 @@ import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
-/**
- * Created by Pmuruge on 10/29/2015.
+/*
+ * 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.
  */
 public class SiblingTest extends TemplateTest {
 


[10/13] incubator-freemarker git commit: Renaming as _significant for @@previous and @@next

Posted by dd...@apache.org.
Renaming as _significant for @@previous and @@next


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/cd45f545
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/cd45f545
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/cd45f545

Branch: refs/heads/2.3-gae
Commit: cd45f545851c7ae443f20eff8398a88ef42a203a
Parents: d40d29c
Author: Pradeep <pr...@trimble.com>
Authored: Sun Dec 13 14:13:49 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:21:07 2016 +0530

----------------------------------------------------------------------
 src/main/java/freemarker/ext/dom/ElementModel.java |  4 ++--
 src/test/java/freemarker/core/SiblingTest.java     | 12 ++++++------
 2 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cd45f545/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 628430c..6fa29ba 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -91,7 +91,7 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                 nu.outputContent(node.getAttributes(), buf);
                 return new SimpleScalar(buf.toString().trim());
             }
-            if (key.equals("@@previous")) {
+            if (key.equals("@@previous_significant")) {
                 Node previousSibling = node.getPreviousSibling();
                 while(previousSibling != null && !this.isSignificantNode(previousSibling)) {
                     previousSibling = previousSibling.getPreviousSibling();
@@ -102,7 +102,7 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                     return wrap(previousSibling);
                 }
             }
-            if (key.equals("@@next")) {
+            if (key.equals("@@next_significant")) {
                 Node nextSibling = node.getNextSibling();
                 while(nextSibling != null && !this.isSignificantNode(nextSibling)) {
                     nextSibling = nextSibling.getNextSibling();

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/cd45f545/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index 81158c8..e646782 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -84,20 +84,20 @@ public class SiblingTest extends TemplateTest {
 
     @Test
     public void testSignificantPreviousSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.name.@@previous}";
+        String ftl = "${doc.person.name.@@previous_significant}";
         assertOutput(ftl, "male");
     }
 
 
     @Test
     public void testSignificantNextSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.name.@@next}";
+        String ftl = "${doc.person.name.@@next_significant}";
         assertOutput(ftl, "12th August");
     }
 
     @Test
     public void testNullSignificantPreviousSibling() throws IOException, TemplateException {
-        String ftl = "<#if doc.person.phone.@@next?size == 0>" +
+        String ftl = "<#if doc.person.phone.@@next_significant?size == 0>" +
                 "Next is null" +
                 "<#else>" +
                 "Next is not null" +
@@ -108,19 +108,19 @@ public class SiblingTest extends TemplateTest {
 
     @Test
     public void testSkippingCommentNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.profession.@@previous}";
+        String ftl = "${doc.person.profession.@@previous_significant}";
         assertOutput(ftl, "Chennai, India");
     }
 
     @Test
     public void testSkippingEmptyCdataNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.hobby.@@previous}";
+        String ftl = "${doc.person.hobby.@@previous_significant}";
         assertOutput(ftl, "Software Engineer");
     }
 
     @Test
     public void testValidCdataNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.phone.@@previous}";
+        String ftl = "${doc.person.phone.@@previous_significant}";
         assertOutput(ftl, "\n    this is a valid cdata\n    ");
     }
 }


[13/13] incubator-freemarker git commit: Adjustments to PR #9 "Sibling related changes"

Posted by dd...@apache.org.
Adjustments to PR #9 "Sibling related changes"


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/fbd6fa5f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/fbd6fa5f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/fbd6fa5f

Branch: refs/heads/2.3-gae
Commit: fbd6fa5f945db29f09d2ec3ea8d2661da5104365
Parents: ddc6a5c
Author: ddekany <dd...@apache.org>
Authored: Sun Jan 8 21:59:19 2017 +0100
Committer: ddekany <dd...@apache.org>
Committed: Sun Jan 8 22:19:52 2017 +0100

----------------------------------------------------------------------
 .../java/freemarker/core/BuiltInForNodeEx.java  |  9 +-
 .../java/freemarker/core/BuiltinVariable.java   |  2 -
 .../core/NonExtendedNodeException.java          | 64 +++++++++++++
 .../java/freemarker/ext/dom/ElementModel.java   |  7 +-
 src/main/java/freemarker/ext/dom/NodeModel.java |  6 +-
 .../template/TemplateNodeModelEx.java           | 19 ++--
 .../freemarker/template/utility/ClassUtil.java  |  5 +-
 src/test/java/freemarker/core/SiblingTest.java  | 97 ++++++++------------
 .../freemarker/core/siblingDataModel.xml        | 18 ++++
 9 files changed, 146 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/core/BuiltInForNodeEx.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInForNodeEx.java b/src/main/java/freemarker/core/BuiltInForNodeEx.java
index 8bfe6b6..79ba429 100644
--- a/src/main/java/freemarker/core/BuiltInForNodeEx.java
+++ b/src/main/java/freemarker/core/BuiltInForNodeEx.java
@@ -6,9 +6,9 @@
  * 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
@@ -22,13 +22,12 @@ import freemarker.template.*;
 
 public abstract class BuiltInForNodeEx extends BuiltIn {
     @Override
-    TemplateModel _eval(Environment env)
-            throws TemplateException {
+    TemplateModel _eval(Environment env) throws TemplateException {
         TemplateModel model = target.eval(env);
         if (model instanceof TemplateNodeModelEx) {
             return calculateResult((TemplateNodeModelEx) model, env);
         } else {
-            throw new NonNodeException(target, model, env);
+            throw new NonExtendedNodeException(target, model, env);
         }
     }
     abstract TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env)

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/core/BuiltinVariable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java
index 1ceb64e..5b0f4d2 100644
--- a/src/main/java/freemarker/core/BuiltinVariable.java
+++ b/src/main/java/freemarker/core/BuiltinVariable.java
@@ -72,8 +72,6 @@ final class BuiltinVariable extends Expression {
     static final String URL_ESCAPING_CHARSET_CC = "urlEscapingCharset";
     static final String URL_ESCAPING_CHARSET = "url_escaping_charset";
     static final String NOW = "now";
-    static final String PREVIOUS_SIBLING = "previous";
-    static final String NEXT_SIBLING = "next";
     
     static final String[] SPEC_VAR_NAMES = new String[] {
         AUTO_ESC_CC,

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/core/NonExtendedNodeException.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/NonExtendedNodeException.java b/src/main/java/freemarker/core/NonExtendedNodeException.java
new file mode 100644
index 0000000..3377257
--- /dev/null
+++ b/src/main/java/freemarker/core/NonExtendedNodeException.java
@@ -0,0 +1,64 @@
+/*
+ * 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 freemarker.core;
+
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateNodeModelEx;
+
+/**
+ * Indicates that a {@link TemplateNodeModelEx} value was expected, but the value had a different type.
+ * 
+ * @since 2.3.26
+ */
+public class NonExtendedNodeException extends UnexpectedTypeException {
+
+    private static final Class<?>[] EXPECTED_TYPES = new Class[] { TemplateNodeModelEx.class };
+    
+    public NonExtendedNodeException(Environment env) {
+        super(env, "Expecting extended node value here");
+    }
+
+    public NonExtendedNodeException(String description, Environment env) {
+        super(env, description);
+    }
+
+    NonExtendedNodeException(Environment env, _ErrorDescriptionBuilder description) {
+        super(env, description);
+    }
+
+    NonExtendedNodeException(
+            Expression blamed, TemplateModel model, Environment env)
+            throws InvalidReferenceException {
+        super(blamed, model, "extended node", EXPECTED_TYPES, env);
+    }
+
+    NonExtendedNodeException(
+            Expression blamed, TemplateModel model, String tip,
+            Environment env)
+            throws InvalidReferenceException {
+        super(blamed, model, "extended node", EXPECTED_TYPES, tip, env);
+    }
+
+    NonExtendedNodeException(
+            Expression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException {
+        super(blamed, model, "extended node", EXPECTED_TYPES, tips, env);
+    }    
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 6fa29ba..a72e55c 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -34,9 +34,10 @@ import freemarker.template.TemplateSequenceModel;
 import freemarker.template.utility.StringUtil;
 
 import java.util.ArrayList;
+import java.util.Collections;
 
 class ElementModel extends NodeModel implements TemplateScalarModel {
-    private final static ArrayList EMPTY_ARRAYLIST = new ArrayList();
+
     public ElementModel(Element element) {
         super(element);
     }
@@ -97,7 +98,7 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                     previousSibling = previousSibling.getPreviousSibling();
                 }
                 if(previousSibling == null) {
-                    return new NodeListModel(EMPTY_ARRAYLIST, null);
+                    return new NodeListModel(Collections.emptyList(), null);
                 } else {
                     return wrap(previousSibling);
                 }
@@ -108,7 +109,7 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                     nextSibling = nextSibling.getNextSibling();
                 }
                 if(nextSibling == null) {
-                    return new NodeListModel(EMPTY_ARRAYLIST, null);
+                    return new NodeListModel(Collections.emptyList(), null);
                 }
                 else {
                     return wrap(nextSibling);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/ext/dom/NodeModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/NodeModel.java b/src/main/java/freemarker/ext/dom/NodeModel.java
index e5ed1ed..4198e2f 100644
--- a/src/main/java/freemarker/ext/dom/NodeModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeModel.java
@@ -76,7 +76,7 @@ import freemarker.template.TemplateSequenceModel;
  * then), but should be used to represent a node set of exactly 1 node.
  */
 abstract public class NodeModel
-implements TemplateNodeModel, TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
+implements TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
     AdapterTemplateModel, WrapperTemplateModel, _UnexpectedTypeErrorExplainerTemplateModel {
 
     static private final Logger LOG = Logger.getLogger("freemarker.dom");
@@ -311,7 +311,7 @@ implements TemplateNodeModel, TemplateNodeModelEx, TemplateHashModel, TemplateSe
         return parent;
     }
 
-    public TemplateNodeModel getPreviousSibling() throws TemplateModelException {
+    public TemplateNodeModelEx getPreviousSibling() throws TemplateModelException {
         if (previousSibling == null) {
             Node previous = node.getPreviousSibling();
             previousSibling = wrap(previous);
@@ -319,7 +319,7 @@ implements TemplateNodeModel, TemplateNodeModelEx, TemplateHashModel, TemplateSe
         return previousSibling;
     }
 
-    public TemplateNodeModel getNextSibling() throws TemplateModelException {
+    public TemplateNodeModelEx getNextSibling() throws TemplateModelException {
         if (nextSibling == null) {
             Node next = node.getNextSibling();
             nextSibling = wrap(next);

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/template/TemplateNodeModelEx.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateNodeModelEx.java b/src/main/java/freemarker/template/TemplateNodeModelEx.java
index 0375048..ca7d21d 100644
--- a/src/main/java/freemarker/template/TemplateNodeModelEx.java
+++ b/src/main/java/freemarker/template/TemplateNodeModelEx.java
@@ -6,9 +6,9 @@
  * 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
@@ -19,15 +19,22 @@
 
 package freemarker.template;
 
+import freemarker.ext.dom.NodeModel;
+
+/**
+ * A {@link NodeModel} that supports navigating to the previous and next sibling nodes.
+ * 
+ * @since 2.3.26
+ */
 public interface TemplateNodeModelEx extends TemplateNodeModel {
 
     /**
-     * @return the immediate Previous Sibling of this node
+     * @return The immediate previous sibling of this node, or {@code null} if there's no such node.
      */
-    TemplateNodeModel getPreviousSibling() throws TemplateModelException;
+    TemplateNodeModelEx getPreviousSibling() throws TemplateModelException;
 
     /**
-     * @return the immediate next Sibling of this node
+     * @return The immediate next sibling of this node, or {@code null} if there's no such node.
      */
-    TemplateNodeModel getNextSibling() throws TemplateModelException;
+    TemplateNodeModelEx getNextSibling() throws TemplateModelException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/main/java/freemarker/template/utility/ClassUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/utility/ClassUtil.java b/src/main/java/freemarker/template/utility/ClassUtil.java
index fe8d753..7a767bd 100644
--- a/src/main/java/freemarker/template/utility/ClassUtil.java
+++ b/src/main/java/freemarker/template/utility/ClassUtil.java
@@ -50,6 +50,7 @@ import freemarker.template.TemplateMethodModelEx;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelIterator;
 import freemarker.template.TemplateNodeModel;
+import freemarker.template.TemplateNodeModelEx;
 import freemarker.template.TemplateNumberModel;
 import freemarker.template.TemplateScalarModel;
 import freemarker.template.TemplateSequenceModel;
@@ -190,7 +191,9 @@ public class ClassUtil {
     private static void appendTemplateModelTypeName(StringBuilder sb, Set typeNamesAppended, Class cl) {
         int initalLength = sb.length();
         
-        if (TemplateNodeModel.class.isAssignableFrom(cl)) {
+        if (TemplateNodeModelEx.class.isAssignableFrom(cl)) {
+            appendTypeName(sb, typeNamesAppended, "extended node");
+        } else if (TemplateNodeModel.class.isAssignableFrom(cl)) {
             appendTypeName(sb, typeNamesAppended, "node");
         }
         

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index e646782..d27b1bd 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -1,21 +1,3 @@
-package freemarker.core;
-
-import freemarker.ext.dom.NodeModel;
-import freemarker.template.TemplateException;
-import freemarker.test.TemplateTest;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -24,9 +6,9 @@ import java.util.Map;
  * 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
@@ -34,52 +16,53 @@ import java.util.Map;
  * specific language governing permissions and limitations
  * under the License.
  */
+
+package freemarker.core;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import freemarker.ext.dom.NodeModel;
+import freemarker.template.TemplateException;
+import freemarker.test.TemplateTest;
+
 public class SiblingTest extends TemplateTest {
 
     @Before
-    public void setUp() {
-        try {
-            InputSource is = new InputSource(getClass().getResourceAsStream("siblingDataModel.xml"));
-            addToDataModel("doc", NodeModel.parse(is) );
-        } catch (Exception e) {
-            System.out.println("Exception while parsing the dataModel xml");
-            e.printStackTrace();
-        }
+    public void setUp() throws SAXException, IOException, ParserConfigurationException {
+        InputSource is = new InputSource(getClass().getResourceAsStream("siblingDataModel.xml"));
+        addToDataModel("doc", NodeModel.parse(is));
     }
 
     @Test
-    public void testEmptyPreviousSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.name?previousSibling}";
-        assertOutput(ftl, "\n    ");
+    public void testBlankPreviousSibling() throws IOException, TemplateException {
+        assertOutput("${doc.person.name?previousSibling}", "\n    ");
     }
 
     @Test
-    public void testNonEmptyPreviousSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.address?previousSibling}";
-        assertOutput(ftl, "12th August");
+    public void testNonBlankPreviousSibling() throws IOException, TemplateException {
+        assertOutput("${doc.person.address?previousSibling}", "12th August");
     }
 
     @Test
-    public void testEmptyNextSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.name?nextSibling}";
-        assertOutput(ftl, "\n    ");
+    public void testBlankNextSibling() throws IOException, TemplateException {
+        assertOutput("${doc.person.name?nextSibling}", "\n    ");
     }
 
     @Test
-    public void testNonEmptyNextSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.dob?nextSibling}";
-        assertOutput(ftl, "Chennai, India");
+    public void testNonBlankNextSibling() throws IOException, TemplateException {
+        assertOutput("${doc.person.dob?nextSibling}", "Chennai, India");
     }
 
-
     @Test
     public void testNullPreviousSibling() throws IOException, TemplateException {
-        String ftl = "<#if doc.person?previousSibling??> " +
-                        "previous is not null" +
-                      "<#else>" +
-                         "previous is null" +
-                    "</#if>";
-        assertOutput(ftl, "previous is null");
+        assertOutput("${doc.person?previousSibling?? ?c}", "false");
     }
 
     @Test
@@ -97,30 +80,22 @@ public class SiblingTest extends TemplateTest {
 
     @Test
     public void testNullSignificantPreviousSibling() throws IOException, TemplateException {
-        String ftl = "<#if doc.person.phone.@@next_significant?size == 0>" +
-                "Next is null" +
-                "<#else>" +
-                "Next is not null" +
-                "</#if>";
-        assertOutput(ftl, "Next is null");
+        assertOutput("${doc.person.phone.@@next_significant?size}", "0");
 
     }
 
     @Test
     public void testSkippingCommentNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.profession.@@previous_significant}";
-        assertOutput(ftl, "Chennai, India");
+        assertOutput("${doc.person.profession.@@previous_significant}", "Chennai, India");
     }
 
     @Test
-    public void testSkippingEmptyCdataNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.hobby.@@previous_significant}";
-        assertOutput(ftl, "Software Engineer");
+    public void testSkippingEmptyCDataNode() throws IOException, TemplateException {
+        assertOutput("${doc.person.hobby.@@previous_significant}", "Software Engineer");
     }
 
     @Test
-    public void testValidCdataNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.phone.@@previous_significant}";
-        assertOutput(ftl, "\n    this is a valid cdata\n    ");
+    public void testValidCDataNode() throws IOException, TemplateException {
+        assertOutput("${doc.person.phone.@@previous_significant}", "\n    this is a valid cdata\n    ");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fbd6fa5f/src/test/resources/freemarker/core/siblingDataModel.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/siblingDataModel.xml b/src/test/resources/freemarker/core/siblingDataModel.xml
index 5a48103..bdb3e45 100644
--- a/src/test/resources/freemarker/core/siblingDataModel.xml
+++ b/src/test/resources/freemarker/core/siblingDataModel.xml
@@ -1,4 +1,22 @@
 <?xml version="1.0"?>
+<!--
+  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.
+-->
 <person>
     <gender>male</gender>
     <name>pradeep</name>


[07/13] incubator-freemarker git commit: DataModel changes and Significant Node check has been changed, Return a list of empty node if null in @@previous and @@next

Posted by dd...@apache.org.
DataModel changes and Significant Node check has been changed, Return a list of empty node if null in @@previous and @@next


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/fb1f3bfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/fb1f3bfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/fb1f3bfc

Branch: refs/heads/2.3-gae
Commit: fb1f3bfca67ab89594b147946ae348f47797d442
Parents: 0ad0188
Author: Pradeep <pr...@trimble.com>
Authored: Thu Dec 10 13:41:58 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:20:43 2016 +0530

----------------------------------------------------------------------
 build.xml                                       |  6 +--
 .../java/freemarker/ext/dom/ElementModel.java   | 30 ++++++++---
 src/test/java/freemarker/core/SiblingTest.java  | 53 ++++++++++++++++++--
 .../freemarker/core/siblingDataModel.xml        |  5 ++
 4 files changed, 80 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fb1f3bfc/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 2d1caba..9b0ec6a 100644
--- a/build.xml
+++ b/build.xml
@@ -397,7 +397,7 @@
   <target name="test" depends="compileTest" description="Run test cases">
     <mkdir dir="build/junit-reports" />
     <ivy:cachepath conf="run.test" pathid="ivy.dep.run.test" />
-    <junit haltonfailure="on" fork="true" forkmode="once">
+    <junit haltonfailure="on" fork="true" forkmode="once" showoutput="yes">
       <classpath>
         <pathelement path="build/test-classes" />
         <pathelement path="build/classes" />
@@ -407,11 +407,11 @@
       <formatter type="xml" />
       <batchtest todir="build/junit-reports">
         <fileset dir="src/test/java">
-          <include name="**/*Test.java" />
-          <include name="**/*TestSuite.java" />
+          <include name="**/SiblingTest.java" />
           <exclude name="**/Abstract*.java" />
         </fileset>
       </batchtest>
+        <formatter type="brief" usefile="false"/>
     </junit>
   </target>
   

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fb1f3bfc/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 41844d7..11d1c04 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -33,8 +33,10 @@ import freemarker.template.TemplateScalarModel;
 import freemarker.template.TemplateSequenceModel;
 import freemarker.template.utility.StringUtil;
 
+import java.util.ArrayList;
+
 class ElementModel extends NodeModel implements TemplateScalarModel {
-    
+    private final static ArrayList EMPTY_ARRAYLIST = new ArrayList();
     public ElementModel(Element element) {
         super(element);
     }
@@ -91,17 +93,26 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
             }
             if (key.equals("@@previous")) {
                 Node previousSibling = node.getPreviousSibling();
-                while(!this.isSignificantNode(previousSibling)) {
+                while(previousSibling != null && !this.isSignificantNode(previousSibling)) {
                     previousSibling = previousSibling.getPreviousSibling();
                 }
-                return wrap(previousSibling);
+                if(previousSibling == null) {
+                    return new NodeListModel(EMPTY_ARRAYLIST, null);
+                } else {
+                    return wrap(previousSibling);
+                }
             }
             if (key.equals("@@next")) {
                 Node nextSibling = node.getNextSibling();
-                while(!this.isSignificantNode(nextSibling)) {
+                while(nextSibling != null && !this.isSignificantNode(nextSibling)) {
                     nextSibling = nextSibling.getNextSibling();
                 }
-                return wrap(nextSibling);
+                if(nextSibling == null) {
+                    return new NodeListModel(EMPTY_ARRAYLIST, null);
+                }
+                else {
+                    return wrap(nextSibling);
+                }
             }
             if (StringUtil.isXMLID(key.substring(1))) {
                 Attr att = getAttribute(key.substring(1));
@@ -122,10 +133,15 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
     }
 
     public boolean isSignificantNode(Node node) throws TemplateModelException {
-        boolean isEmpty =  node.getTextContent().trim().isEmpty();
-        boolean significantNode = !isEmpty;
+        boolean significantNode = false;
+        if(node != null) {
+            boolean isEmpty = StringUtil.isTrimmableToEmpty(node.getTextContent().toCharArray());
+            boolean isPINode = node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE;
+            significantNode = !(isEmpty || isPINode);
+        }
         return significantNode;
     }
+
     public String getAsString() throws TemplateModelException {
         NodeList nl = node.getChildNodes();
         String result = "";

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fb1f3bfc/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index 0db4df8..afbb880 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -47,7 +47,7 @@ public class SiblingTest extends TemplateTest {
         }
     }
 
-    @Test
+   @Test
     public void testEmptyPreviousSibling() throws IOException, TemplateException {
         String ftl = "${doc.person.name?previousSibling}";
         assertOutput(ftl, "\n    ");
@@ -71,15 +71,60 @@ public class SiblingTest extends TemplateTest {
         assertOutput(ftl, "Chennai, India");
     }
 
+
     @Test
-    public void testSignificantNextSibling() throws IOException, TemplateException {
-        String ftl = "${doc.person.name.@@next}";
-        assertOutput(ftl, "12th August");
+    public void testNullPreviousSibling() throws IOException, TemplateException {
+        String ftl = "<#if doc.person?previousSibling??> " +
+                        "previous is not null" +
+                      "<#else>" +
+                         "previous is null" +
+                    "</#if>";
+        assertOutput(ftl, "previous is null");
+
     }
 
     @Test
     public void testSignificantPreviousSibling() throws IOException, TemplateException {
         String ftl = "${doc.person.name.@@previous}";
         assertOutput(ftl, "male");
+
+    }
+
+
+    @Test
+    public void testSignificantNextSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.name.@@next}";
+        assertOutput(ftl, "12th August");
+
     }
+
+    @Test
+    public void testNullSignificantPreviousSibling() throws IOException, TemplateException {
+        String ftl = "<#if doc.person.phone.@@next?size == 0>" +
+                "Next is null" +
+                "<#else>" +
+                "Next is not null" +
+                "</#if>";
+        assertOutput(ftl, "Next is null");
+
+    }
+
+    @Test
+    public void testSkippingCommentNode() throws IOException, TemplateException {
+        String ftl = "${doc.person.profession.@@previous}";
+        assertOutput(ftl, "Chennai, India");
+
+    }
+
+    @Test
+    public void testpreviousSiblingforPINode() throws IOException, TemplateException {
+        String ftl = "${doc.person.profession?previousSibling?previousSibling}";
+        assertOutput(ftl, "Chennai, India");
+    }
+    /*@Test
+    public void testSkippingCdataNode() throws IOException, TemplateException {
+        String ftl = "${doc.person.phone.@@previous}";
+        assertOutput(ftl, "Chennai, India");
+    }*/
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/fb1f3bfc/src/test/resources/freemarker/core/siblingDataModel.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/siblingDataModel.xml b/src/test/resources/freemarker/core/siblingDataModel.xml
index 13f928a..37e8795 100644
--- a/src/test/resources/freemarker/core/siblingDataModel.xml
+++ b/src/test/resources/freemarker/core/siblingDataModel.xml
@@ -3,4 +3,9 @@
     <gender>male</gender>
     <name>pradeep</name>
     <dob>12th August</dob><address>Chennai, India</address>
+    <!--This is a comment Node -->
+    <?xml-stylesheet type="text/css" href="style.css"?>
+    <profession>Software Engineer</profession>
+    <![CDATA[ <a>test<a> ]]>
+    <phone>12345678</phone>
 </person>


[08/13] incubator-freemarker git commit: revert build.xml

Posted by dd...@apache.org.
revert build.xml


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/321e853e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/321e853e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/321e853e

Branch: refs/heads/2.3-gae
Commit: 321e853e55097825201abf44462c7e62f35c069b
Parents: fb1f3bf
Author: Pradeep <pr...@trimble.com>
Authored: Thu Dec 10 13:45:47 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:20:54 2016 +0530

----------------------------------------------------------------------
 build.xml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/321e853e/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index 9b0ec6a..2d1caba 100644
--- a/build.xml
+++ b/build.xml
@@ -397,7 +397,7 @@
   <target name="test" depends="compileTest" description="Run test cases">
     <mkdir dir="build/junit-reports" />
     <ivy:cachepath conf="run.test" pathid="ivy.dep.run.test" />
-    <junit haltonfailure="on" fork="true" forkmode="once" showoutput="yes">
+    <junit haltonfailure="on" fork="true" forkmode="once">
       <classpath>
         <pathelement path="build/test-classes" />
         <pathelement path="build/classes" />
@@ -407,11 +407,11 @@
       <formatter type="xml" />
       <batchtest todir="build/junit-reports">
         <fileset dir="src/test/java">
-          <include name="**/SiblingTest.java" />
+          <include name="**/*Test.java" />
+          <include name="**/*TestSuite.java" />
           <exclude name="**/Abstract*.java" />
         </fileset>
       </batchtest>
-        <formatter type="brief" usefile="false"/>
     </junit>
   </target>
   


[03/13] incubator-freemarker git commit: merged with Branch 2.3-gae

Posted by dd...@apache.org.
merged with Branch 2.3-gae


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/180d1865
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/180d1865
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/180d1865

Branch: refs/heads/2.3-gae
Commit: 180d1865b977e420b69f7a8a0f4709bd371dbb1f
Parents: 51c005e
Author: Pradeep <pr...@trimble.com>
Authored: Tue Oct 27 22:18:37 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:19:06 2016 +0530

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java      | 11 +++---
 .../java/freemarker/core/BuiltInExtForNode.java | 27 ++++++++++---
 .../freemarker/core/BuiltInExtForNodes.java     | 26 -------------
 .../freemarker/core/BuiltInsExtForNode.java     | 41 ++++++++++++++++++++
 .../java/freemarker/core/BuiltinVariable.java   |  5 +--
 .../java/freemarker/ext/dom/ElementModel.java   | 16 ++++----
 src/main/java/freemarker/ext/dom/NodeModel.java |  4 +-
 .../template/TemplateNodeModelEx.java           | 33 ++++++++++++++++
 .../template/TemplateNodeModelExt.java          | 17 --------
 9 files changed, 112 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index 63f2574..ee02625 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -62,8 +62,8 @@ import freemarker.core.BuiltInsForSequences.seq_index_ofBI;
 import freemarker.core.BuiltInsForSequences.sortBI;
 import freemarker.core.BuiltInsForSequences.sort_byBI;
 import freemarker.core.BuiltInsForStringsMisc.evalBI;
-import freemarker.core.BuiltInExtForNodes.previousSiblingBI;
-import freemarker.core.BuiltInExtForNodes.nextSiblingBI;
+import freemarker.core.BuiltInsExtForNode.previousSiblingBI;
+import freemarker.core.BuiltInsExtForNode.nextSiblingBI;
 import freemarker.template.Configuration;
 import freemarker.template.TemplateDateModel;
 import freemarker.template.TemplateModel;
@@ -83,8 +83,7 @@ abstract class BuiltIn extends Expression implements Cloneable {
 
     static final Set<String> CAMEL_CASE_NAMES = new TreeSet<String>();
     static final Set<String> SNAKE_CASE_NAMES = new TreeSet<String>();
-
-    static final int NUMBER_OF_BIS = 261;
+    static final int NUMBER_OF_BIS = 263;
     static final HashMap builtins = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
 
     static {
@@ -249,8 +248,8 @@ abstract class BuiltIn extends Expression implements Cloneable {
         putBI("number_to_time", "numberToTime", new number_to_dateBI(TemplateDateModel.TIME));
         putBI("number_to_datetime", "numberToDatetime", new number_to_dateBI(TemplateDateModel.DATETIME));
         putBI("parent", new parentBI());
-        putBI("previousSibling", new previousSiblingBI());
-        putBI("nextSibling", new nextSiblingBI());
+        putBI("previous_sibling", "previousSibling", new previousSiblingBI());
+        putBI("next_sibling", "nextSibling", new nextSiblingBI());
         putBI("item_parity", "itemParity", new BuiltInsForLoopVariables.item_parityBI());
         putBI("item_parity_cap", "itemParityCap", new BuiltInsForLoopVariables.item_parity_capBI());
         putBI("reverse", new reverseBI());

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/core/BuiltInExtForNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInExtForNode.java b/src/main/java/freemarker/core/BuiltInExtForNode.java
index 7e859b8..00e55fa 100644
--- a/src/main/java/freemarker/core/BuiltInExtForNode.java
+++ b/src/main/java/freemarker/core/BuiltInExtForNode.java
@@ -1,21 +1,36 @@
+/*
+ * 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 freemarker.core;
 
 import freemarker.template.*;
 
-/**
- * Created by Pmuruge on 10/23/2015.
- */
 public abstract class BuiltInExtForNode extends BuiltIn {
     @Override
     TemplateModel _eval(Environment env)
             throws TemplateException {
         TemplateModel model = target.eval(env);
-        if (model instanceof TemplateNodeModelExt) {
-            return calculateResult((TemplateNodeModelExt) model, env);
+        if (model instanceof TemplateNodeModelEx) {
+            return calculateResult((TemplateNodeModelEx) model, env);
         } else {
             throw new NonNodeException(target, model, env);
         }
     }
-    abstract TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env)
+    abstract TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env)
             throws TemplateModelException;
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/core/BuiltInExtForNodes.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInExtForNodes.java b/src/main/java/freemarker/core/BuiltInExtForNodes.java
deleted file mode 100644
index eeb20a8..0000000
--- a/src/main/java/freemarker/core/BuiltInExtForNodes.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package freemarker.core;
-
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.TemplateNodeModelExt;
-
-/**
- * Created by Pmuruge on 10/23/2015.
- */
-public class BuiltInExtForNodes {
-
-    static class previousSiblingBI extends BuiltInExtForNode {
-        @Override
-        TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env) throws TemplateModelException {
-            return nodeModel.getPreviousSibling();
-        }
-    }
-
-    static class nextSiblingBI extends  BuiltInExtForNode {
-        @Override
-        TemplateModel calculateResult(TemplateNodeModelExt nodeModel, Environment env) throws TemplateModelException {
-            return nodeModel.getNextSibling();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/core/BuiltInsExtForNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsExtForNode.java b/src/main/java/freemarker/core/BuiltInsExtForNode.java
new file mode 100644
index 0000000..b675b9a
--- /dev/null
+++ b/src/main/java/freemarker/core/BuiltInsExtForNode.java
@@ -0,0 +1,41 @@
+/*
+ * 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 freemarker.core;
+
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+import freemarker.template.TemplateNodeModelEx;
+
+public class BuiltInsExtForNode {
+
+    static class previousSiblingBI extends BuiltInExtForNode {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getPreviousSibling();
+        }
+    }
+
+    static class nextSiblingBI extends  BuiltInExtForNode {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getNextSibling();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/core/BuiltinVariable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java
index 0afea07..ee1f319 100644
--- a/src/main/java/freemarker/core/BuiltinVariable.java
+++ b/src/main/java/freemarker/core/BuiltinVariable.java
@@ -74,6 +74,7 @@ final class BuiltinVariable extends Expression {
     static final String NOW = "now";
     static final String PREVIOUS_SIBLING = "previous";
     static final String NEXT_SIBLING = "next";
+    private static final BoundCallable PASS_VALUE = new BoundCallable(UnboundCallable.NO_OP_MACRO, null, null);
     
     static final String[] SPEC_VAR_NAMES = new String[] {
         AUTO_ESC_CC,
@@ -109,9 +110,7 @@ final class BuiltinVariable extends Expression {
         URL_ESCAPING_CHARSET_CC,
         URL_ESCAPING_CHARSET,
         VARS,
-        VERSION,
-        PREVIOUS_SIBLING,
-        NEXT_SIBLING
+        VERSION
     };
 
     private final String name;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 95e13fc..99d8e23 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -90,18 +90,18 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
                 return new SimpleScalar(buf.toString().trim());
             }
             if (key.equals("@@previous")) {
-                XPathSupport xps = getXPathSupport();
-                if (xps != null) {
-                    return xps.executeQuery(node, "preceding-sibling::*[position()=1]");
+                Node previousSibling = node.getPreviousSibling();
+                while(previousSibling.getNodeType() != Node.ELEMENT_NODE) {
+                    previousSibling = previousSibling.getPreviousSibling();
                 }
+                return wrap(previousSibling);
             }
             if (key.equals("@@next")) {
-                XPathSupport xps = getXPathSupport();
-                if (xps != null) {
-                    TemplateModel next = xps.executeQuery(node, "following-sibling::*[position()=1]");
-                    System.out.println(next.toString());
-                    return next;
+                Node nextSibling = node.getNextSibling();
+                while(nextSibling.getNodeType() != Node.ELEMENT_NODE) {
+                    nextSibling = nextSibling.getNextSibling();
                 }
+                return wrap(nextSibling);
             }
             if (StringUtil.isXMLID(key.substring(1))) {
                 Attr att = getAttribute(key.substring(1));

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/ext/dom/NodeModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/NodeModel.java b/src/main/java/freemarker/ext/dom/NodeModel.java
index c518333..e5ed1ed 100644
--- a/src/main/java/freemarker/ext/dom/NodeModel.java
+++ b/src/main/java/freemarker/ext/dom/NodeModel.java
@@ -59,7 +59,7 @@ import freemarker.template.TemplateHashModel;
 import freemarker.template.TemplateModel;
 import freemarker.template.TemplateModelException;
 import freemarker.template.TemplateNodeModel;
-import freemarker.template.TemplateNodeModelExt;
+import freemarker.template.TemplateNodeModelEx;
 import freemarker.template.TemplateNumberModel;
 import freemarker.template.TemplateSequenceModel;
 
@@ -76,7 +76,7 @@ import freemarker.template.TemplateSequenceModel;
  * then), but should be used to represent a node set of exactly 1 node.
  */
 abstract public class NodeModel
-implements TemplateNodeModel, TemplateNodeModelExt, TemplateHashModel, TemplateSequenceModel,
+implements TemplateNodeModel, TemplateNodeModelEx, TemplateHashModel, TemplateSequenceModel,
     AdapterTemplateModel, WrapperTemplateModel, _UnexpectedTypeErrorExplainerTemplateModel {
 
     static private final Logger LOG = Logger.getLogger("freemarker.dom");

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/template/TemplateNodeModelEx.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateNodeModelEx.java b/src/main/java/freemarker/template/TemplateNodeModelEx.java
new file mode 100644
index 0000000..0375048
--- /dev/null
+++ b/src/main/java/freemarker/template/TemplateNodeModelEx.java
@@ -0,0 +1,33 @@
+/*
+ * 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 freemarker.template;
+
+public interface TemplateNodeModelEx extends TemplateNodeModel {
+
+    /**
+     * @return the immediate Previous Sibling of this node
+     */
+    TemplateNodeModel getPreviousSibling() throws TemplateModelException;
+
+    /**
+     * @return the immediate next Sibling of this node
+     */
+    TemplateNodeModel getNextSibling() throws TemplateModelException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/180d1865/src/main/java/freemarker/template/TemplateNodeModelExt.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/template/TemplateNodeModelExt.java b/src/main/java/freemarker/template/TemplateNodeModelExt.java
deleted file mode 100644
index d2c8be0..0000000
--- a/src/main/java/freemarker/template/TemplateNodeModelExt.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package freemarker.template;
-
-/**
- * Created by Pmuruge on 10/22/2015.
- */
-public interface TemplateNodeModelExt extends TemplateNodeModel {
-
-    /**
-     * @return the immediate Previous Sibling of this node
-     */
-    TemplateNodeModel getPreviousSibling() throws TemplateModelException;
-
-    /**
-     * @return the immediate next Sibling of this node
-     */
-    TemplateNodeModel getNextSibling() throws TemplateModelException;
-}


[12/13] incubator-freemarker git commit: Merge commit 'refs/pull/9/head' of https://github.com/apache/incubator-freemarker into 2.3-gae

Posted by dd...@apache.org.
Merge commit 'refs/pull/9/head' of https://github.com/apache/incubator-freemarker into 2.3-gae

Summary: Added TemplateNodeModelEx to support getting the previous and next sibling node. Added ?previous_sibling and ?next_sibling. Added @@previous_significant and @@next_significant to XML element nodes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ddc6a5ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ddc6a5ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ddc6a5ca

Branch: refs/heads/2.3-gae
Commit: ddc6a5cadc797e49f27ac4403cda47b6f1dc868a
Parents: 6750d92 8e5e8a2
Author: ddekany <dd...@apache.org>
Authored: Sun Jan 8 10:43:48 2017 +0100
Committer: ddekany <dd...@apache.org>
Committed: Sun Jan 8 21:58:12 2017 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java      |   9 +-
 .../java/freemarker/core/BuiltInForNodeEx.java  |  36 ++++++
 .../java/freemarker/core/BuiltInsForNodes.java  |  22 ++--
 .../java/freemarker/core/BuiltinVariable.java   |   2 +
 .../java/freemarker/ext/dom/ElementModel.java   |  38 +++++-
 src/main/java/freemarker/ext/dom/NodeModel.java |  23 +++-
 .../template/TemplateNodeModelEx.java           |  33 +++++
 src/test/java/freemarker/core/SiblingTest.java  | 126 +++++++++++++++++++
 .../freemarker/core/siblingDataModel.xml        |  13 ++
 9 files changed, 290 insertions(+), 12 deletions(-)
----------------------------------------------------------------------



[04/13] incubator-freemarker git commit: Unit Test for sibling changes

Posted by dd...@apache.org.
Unit Test for sibling changes


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/ada5afed
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/ada5afed
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/ada5afed

Branch: refs/heads/2.3-gae
Commit: ada5afed5c6d1361888f1734976da247e627694d
Parents: 180d186
Author: Pradeep <pr...@trimble.com>
Authored: Tue Nov 3 11:36:31 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:20:13 2016 +0530

----------------------------------------------------------------------
 src/test/java/freemarker/core/SiblingTest.java  | 42 ++++++++++++++++++++
 .../freemarker/core/siblingDataModel.xml        |  6 +++
 2 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ada5afed/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
new file mode 100644
index 0000000..cda5430
--- /dev/null
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -0,0 +1,42 @@
+package freemarker.core;
+
+import freemarker.ext.dom.NodeModel;
+import freemarker.template.TemplateException;
+import freemarker.test.TemplateTest;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by Pmuruge on 10/29/2015.
+ */
+public class SiblingTest extends TemplateTest {
+
+    @Override
+    protected Object getDataModel() {
+        Map dataModel = new HashMap();
+        String dataModelFileUrl = this.getClass().getResource(".").toString() + "/siblingDataModel.xml";
+        try {
+            dataModel.put(
+                    "doc", NodeModel.parse(new File("build/test-classes/freemarker/core/siblingDataModel.xml")));
+        } catch (Exception e) {
+            System.out.println("Exception while parsing the dataModel xml");
+            e.printStackTrace();
+        }
+        return dataModel;
+    }
+    @Test
+    public void testPreviousSibling() throws IOException, TemplateException {
+        String ftl = "<#assign sibling>${doc.person.name?previousSibling}</#assign>" +
+                "${sibling?trim}" ;
+        assertOutput(ftl, "");
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/ada5afed/src/test/resources/freemarker/core/siblingDataModel.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/siblingDataModel.xml b/src/test/resources/freemarker/core/siblingDataModel.xml
new file mode 100644
index 0000000..f743e2e
--- /dev/null
+++ b/src/test/resources/freemarker/core/siblingDataModel.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<person>
+    <gender>male</gender>
+    <name>pradeep</name>
+    <dob>12th August</dob>
+</person>


[09/13] incubator-freemarker git commit: CDATA Test cases added

Posted by dd...@apache.org.
CDATA Test cases added


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/d40d29cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/d40d29cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/d40d29cb

Branch: refs/heads/2.3-gae
Commit: d40d29cb2ed40c7eeff39e48cb396da1b008756d
Parents: 321e853
Author: Pradeep <pr...@trimble.com>
Authored: Sun Dec 13 13:26:17 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:21:00 2016 +0530

----------------------------------------------------------------------
 .../java/freemarker/ext/dom/ElementModel.java   |  3 ++-
 src/test/java/freemarker/core/SiblingTest.java  | 22 ++++++++------------
 .../freemarker/core/siblingDataModel.xml        |  4 +++-
 3 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d40d29cb/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 11d1c04..628430c 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -137,7 +137,8 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
         if(node != null) {
             boolean isEmpty = StringUtil.isTrimmableToEmpty(node.getTextContent().toCharArray());
             boolean isPINode = node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE;
-            significantNode = !(isEmpty || isPINode);
+            boolean isCommentNode = node.getNodeType() == Node.COMMENT_NODE;
+            significantNode = !(isEmpty || isPINode || isCommentNode);
         }
         return significantNode;
     }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d40d29cb/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index afbb880..81158c8 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -47,7 +47,7 @@ public class SiblingTest extends TemplateTest {
         }
     }
 
-   @Test
+    @Test
     public void testEmptyPreviousSibling() throws IOException, TemplateException {
         String ftl = "${doc.person.name?previousSibling}";
         assertOutput(ftl, "\n    ");
@@ -80,14 +80,12 @@ public class SiblingTest extends TemplateTest {
                          "previous is null" +
                     "</#if>";
         assertOutput(ftl, "previous is null");
-
     }
 
     @Test
     public void testSignificantPreviousSibling() throws IOException, TemplateException {
         String ftl = "${doc.person.name.@@previous}";
         assertOutput(ftl, "male");
-
     }
 
 
@@ -95,7 +93,6 @@ public class SiblingTest extends TemplateTest {
     public void testSignificantNextSibling() throws IOException, TemplateException {
         String ftl = "${doc.person.name.@@next}";
         assertOutput(ftl, "12th August");
-
     }
 
     @Test
@@ -113,18 +110,17 @@ public class SiblingTest extends TemplateTest {
     public void testSkippingCommentNode() throws IOException, TemplateException {
         String ftl = "${doc.person.profession.@@previous}";
         assertOutput(ftl, "Chennai, India");
-
     }
 
     @Test
-    public void testpreviousSiblingforPINode() throws IOException, TemplateException {
-        String ftl = "${doc.person.profession?previousSibling?previousSibling}";
-        assertOutput(ftl, "Chennai, India");
+    public void testSkippingEmptyCdataNode() throws IOException, TemplateException {
+        String ftl = "${doc.person.hobby.@@previous}";
+        assertOutput(ftl, "Software Engineer");
     }
-    /*@Test
-    public void testSkippingCdataNode() throws IOException, TemplateException {
-        String ftl = "${doc.person.phone.@@previous}";
-        assertOutput(ftl, "Chennai, India");
-    }*/
 
+    @Test
+    public void testValidCdataNode() throws IOException, TemplateException {
+        String ftl = "${doc.person.phone.@@previous}";
+        assertOutput(ftl, "\n    this is a valid cdata\n    ");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/d40d29cb/src/test/resources/freemarker/core/siblingDataModel.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/siblingDataModel.xml b/src/test/resources/freemarker/core/siblingDataModel.xml
index 37e8795..5a48103 100644
--- a/src/test/resources/freemarker/core/siblingDataModel.xml
+++ b/src/test/resources/freemarker/core/siblingDataModel.xml
@@ -6,6 +6,8 @@
     <!--This is a comment Node -->
     <?xml-stylesheet type="text/css" href="style.css"?>
     <profession>Software Engineer</profession>
-    <![CDATA[ <a>test<a> ]]>
+    <![CDATA[    ]]>
+    <hobby>gardening</hobby>
+    <![CDATA[this is a valid cdata]]>
     <phone>12345678</phone>
 </person>


[11/13] incubator-freemarker git commit: removing the unwanted additions due to merge

Posted by dd...@apache.org.
removing the unwanted additions due to merge


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/8e5e8a2a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/8e5e8a2a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/8e5e8a2a

Branch: refs/heads/2.3-gae
Commit: 8e5e8a2ab570bad61e5cc2fd93bf3c9eaabd3484
Parents: cd45f54
Author: Pradeep <pr...@trimble.com>
Authored: Mon Jan 11 21:29:33 2016 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 21:29:33 2016 +0530

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java         | 2 +-
 src/main/java/freemarker/core/BuiltinVariable.java | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8e5e8a2a/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index c9d93d5..5edcb20 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -84,7 +84,7 @@ abstract class BuiltIn extends Expression implements Cloneable {
     static final Set<String> CAMEL_CASE_NAMES = new TreeSet<String>();
     static final Set<String> SNAKE_CASE_NAMES = new TreeSet<String>();
     static final int NUMBER_OF_BIS = 263;
-    static final HashMap builtins = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
+    static final HashMap<String, BuiltIn> BUILT_INS_BY_NAME = new HashMap(NUMBER_OF_BIS * 3 / 2 + 1, 1f);
 
     static {
         // Note that you must update NUMBER_OF_BIS if you add new items here!

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/8e5e8a2a/src/main/java/freemarker/core/BuiltinVariable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltinVariable.java b/src/main/java/freemarker/core/BuiltinVariable.java
index ee1f319..1ceb64e 100644
--- a/src/main/java/freemarker/core/BuiltinVariable.java
+++ b/src/main/java/freemarker/core/BuiltinVariable.java
@@ -74,7 +74,6 @@ final class BuiltinVariable extends Expression {
     static final String NOW = "now";
     static final String PREVIOUS_SIBLING = "previous";
     static final String NEXT_SIBLING = "next";
-    private static final BoundCallable PASS_VALUE = new BoundCallable(UnboundCallable.NO_OP_MACRO, null, null);
     
     static final String[] SPEC_VAR_NAMES = new String[] {
         AUTO_ESC_CC,


[02/13] incubator-freemarker git commit: Hiding the formdatamodel, changes related to fm online redirecting

Posted by dd...@apache.org.
Hiding the formdatamodel, changes related to fm online redirecting


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/51c005ef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/51c005ef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/51c005ef

Branch: refs/heads/2.3-gae
Commit: 51c005ef49c3cde43d3ae1459655add88d3f78ea
Parents: d66cf48
Author: Pradeep <pr...@trimble.com>
Authored: Mon Oct 26 19:23:04 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 17:21:55 2016 +0530

----------------------------------------------------------------------
 src/manual/en_US/book.xml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/51c005ef/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 0ea368d..df345c8 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -451,7 +451,10 @@
             that in the <link linkend="example.first">very first
             example</link> you want to greet your boss, Big Joe, differently
             than other users:</para>
-
+              <programlisting role="formDataModel">
+                  user=John
+                  latestProduct = {"url": "https://test.com", "name": "test"}
+              </programlisting>
             <programlisting role="template">&lt;html&gt;
 &lt;head&gt;
   &lt;title&gt;Welcome!&lt;/title&gt;
@@ -464,7 +467,6 @@
   &lt;a href="${latestProduct.url}"&gt;${latestProduct.name}&lt;/a&gt;!
 &lt;/body&gt;
 &lt;/html&gt;</programlisting>
-
             <para>Here you have told FreeMarker that the <quote>, our beloved
             leader</quote> should be there only if the value of the variable
             <literal>user</literal> is equal to the string <literal>"Big


[06/13] incubator-freemarker git commit: Unit tests for Sibling and file renamed as per convention

Posted by dd...@apache.org.
Unit tests for Sibling and file renamed as per convention


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/0ad01886
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/0ad01886
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/0ad01886

Branch: refs/heads/2.3-gae
Commit: 0ad018867388ce67e9d2d7e3cac6494ed89bcc43
Parents: 9e73d00
Author: Pradeep <pr...@trimble.com>
Authored: Sun Dec 6 20:51:24 2015 +0530
Committer: Pradeep <pr...@trimble.com>
Committed: Mon Jan 11 19:20:32 2016 +0530

----------------------------------------------------------------------
 src/main/java/freemarker/core/BuiltIn.java      |  4 +-
 .../java/freemarker/core/BuiltInExtForNode.java | 36 --------------
 .../java/freemarker/core/BuiltInForNodeEx.java  | 36 ++++++++++++++
 .../freemarker/core/BuiltInsExtForNode.java     | 41 ----------------
 .../java/freemarker/core/BuiltInsForNodes.java  | 22 ++++++---
 .../java/freemarker/ext/dom/ElementModel.java   |  9 +++-
 src/test/java/freemarker/core/SiblingTest.java  | 50 +++++++++++++++-----
 .../freemarker/core/siblingDataModel.xml        |  2 +-
 8 files changed, 100 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/core/BuiltIn.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltIn.java b/src/main/java/freemarker/core/BuiltIn.java
index ee02625..c9d93d5 100644
--- a/src/main/java/freemarker/core/BuiltIn.java
+++ b/src/main/java/freemarker/core/BuiltIn.java
@@ -62,8 +62,8 @@ import freemarker.core.BuiltInsForSequences.seq_index_ofBI;
 import freemarker.core.BuiltInsForSequences.sortBI;
 import freemarker.core.BuiltInsForSequences.sort_byBI;
 import freemarker.core.BuiltInsForStringsMisc.evalBI;
-import freemarker.core.BuiltInsExtForNode.previousSiblingBI;
-import freemarker.core.BuiltInsExtForNode.nextSiblingBI;
+import freemarker.core.BuiltInsForNodes.previousSiblingBI;
+import freemarker.core.BuiltInsForNodes.nextSiblingBI;
 import freemarker.template.Configuration;
 import freemarker.template.TemplateDateModel;
 import freemarker.template.TemplateModel;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/core/BuiltInExtForNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInExtForNode.java b/src/main/java/freemarker/core/BuiltInExtForNode.java
deleted file mode 100644
index 00e55fa..0000000
--- a/src/main/java/freemarker/core/BuiltInExtForNode.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 freemarker.core;
-
-import freemarker.template.*;
-
-public abstract class BuiltInExtForNode extends BuiltIn {
-    @Override
-    TemplateModel _eval(Environment env)
-            throws TemplateException {
-        TemplateModel model = target.eval(env);
-        if (model instanceof TemplateNodeModelEx) {
-            return calculateResult((TemplateNodeModelEx) model, env);
-        } else {
-            throw new NonNodeException(target, model, env);
-        }
-    }
-    abstract TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env)
-            throws TemplateModelException;
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/core/BuiltInForNodeEx.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInForNodeEx.java b/src/main/java/freemarker/core/BuiltInForNodeEx.java
new file mode 100644
index 0000000..8bfe6b6
--- /dev/null
+++ b/src/main/java/freemarker/core/BuiltInForNodeEx.java
@@ -0,0 +1,36 @@
+/*
+ * 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 freemarker.core;
+
+import freemarker.template.*;
+
+public abstract class BuiltInForNodeEx extends BuiltIn {
+    @Override
+    TemplateModel _eval(Environment env)
+            throws TemplateException {
+        TemplateModel model = target.eval(env);
+        if (model instanceof TemplateNodeModelEx) {
+            return calculateResult((TemplateNodeModelEx) model, env);
+        } else {
+            throw new NonNodeException(target, model, env);
+        }
+    }
+    abstract TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env)
+            throws TemplateModelException;
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/core/BuiltInsExtForNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsExtForNode.java b/src/main/java/freemarker/core/BuiltInsExtForNode.java
deleted file mode 100644
index b675b9a..0000000
--- a/src/main/java/freemarker/core/BuiltInsExtForNode.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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 freemarker.core;
-
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.TemplateNodeModelEx;
-
-public class BuiltInsExtForNode {
-
-    static class previousSiblingBI extends BuiltInExtForNode {
-        @Override
-        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
-            return nodeModel.getPreviousSibling();
-        }
-    }
-
-    static class nextSiblingBI extends  BuiltInExtForNode {
-        @Override
-        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
-            return nodeModel.getNextSibling();
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/core/BuiltInsForNodes.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsForNodes.java b/src/main/java/freemarker/core/BuiltInsForNodes.java
index 2fc8c54..fa2c6ec 100644
--- a/src/main/java/freemarker/core/BuiltInsForNodes.java
+++ b/src/main/java/freemarker/core/BuiltInsForNodes.java
@@ -22,12 +22,7 @@ package freemarker.core;
 import java.util.List;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import freemarker.template.SimpleScalar;
-import freemarker.template.SimpleSequence;
-import freemarker.template.TemplateMethodModel;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import freemarker.template.TemplateNodeModel;
+import freemarker.template.*;
 import freemarker.template.utility.StringUtil;
 
 /**
@@ -97,7 +92,20 @@ class BuiltInsForNodes {
             return result;
        }
     }
-    
+
+    static class previousSiblingBI extends BuiltInForNodeEx {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getPreviousSibling();
+        }
+    }
+
+    static class nextSiblingBI extends  BuiltInForNodeEx {
+        @Override
+        TemplateModel calculateResult(TemplateNodeModelEx nodeModel, Environment env) throws TemplateModelException {
+            return nodeModel.getNextSibling();
+        }
+    }
     
     // Can't be instantiated
     private BuiltInsForNodes() { }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/main/java/freemarker/ext/dom/ElementModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/dom/ElementModel.java b/src/main/java/freemarker/ext/dom/ElementModel.java
index 99d8e23..41844d7 100644
--- a/src/main/java/freemarker/ext/dom/ElementModel.java
+++ b/src/main/java/freemarker/ext/dom/ElementModel.java
@@ -91,14 +91,14 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
             }
             if (key.equals("@@previous")) {
                 Node previousSibling = node.getPreviousSibling();
-                while(previousSibling.getNodeType() != Node.ELEMENT_NODE) {
+                while(!this.isSignificantNode(previousSibling)) {
                     previousSibling = previousSibling.getPreviousSibling();
                 }
                 return wrap(previousSibling);
             }
             if (key.equals("@@next")) {
                 Node nextSibling = node.getNextSibling();
-                while(nextSibling.getNodeType() != Node.ELEMENT_NODE) {
+                while(!this.isSignificantNode(nextSibling)) {
                     nextSibling = nextSibling.getNextSibling();
                 }
                 return wrap(nextSibling);
@@ -121,6 +121,11 @@ class ElementModel extends NodeModel implements TemplateScalarModel {
         return super.get(key);
     }
 
+    public boolean isSignificantNode(Node node) throws TemplateModelException {
+        boolean isEmpty =  node.getTextContent().trim().isEmpty();
+        boolean significantNode = !isEmpty;
+        return significantNode;
+    }
     public String getAsString() throws TemplateModelException {
         NodeList nl = node.getChildNodes();
         String result = "";

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/test/java/freemarker/core/SiblingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/SiblingTest.java b/src/test/java/freemarker/core/SiblingTest.java
index b38cec0..0db4df8 100644
--- a/src/test/java/freemarker/core/SiblingTest.java
+++ b/src/test/java/freemarker/core/SiblingTest.java
@@ -3,7 +3,10 @@ package freemarker.core;
 import freemarker.ext.dom.NodeModel;
 import freemarker.template.TemplateException;
 import freemarker.test.TemplateTest;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
@@ -33,25 +36,50 @@ import java.util.Map;
  */
 public class SiblingTest extends TemplateTest {
 
-    @Override
-    protected Object getDataModel() {
-        Map dataModel = new HashMap();
-        String dataModelFileUrl = this.getClass().getResource(".").toString() + "/siblingDataModel.xml";
+    @Before
+    public void setUp() {
         try {
-            dataModel.put(
-                    "doc", NodeModel.parse(new File("build/test-classes/freemarker/core/siblingDataModel.xml")));
+            InputSource is = new InputSource(getClass().getResourceAsStream("siblingDataModel.xml"));
+            addToDataModel("doc", NodeModel.parse(is) );
         } catch (Exception e) {
             System.out.println("Exception while parsing the dataModel xml");
             e.printStackTrace();
         }
-        return dataModel;
     }
+
+    @Test
+    public void testEmptyPreviousSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.name?previousSibling}";
+        assertOutput(ftl, "\n    ");
+    }
+
+    @Test
+    public void testNonEmptyPreviousSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.address?previousSibling}";
+        assertOutput(ftl, "12th August");
+    }
+
     @Test
-    public void testPreviousSibling() throws IOException, TemplateException {
-        String ftl = "<#assign sibling>${doc.person.name?previousSibling}</#assign>" +
-                "${sibling?trim}" ;
-        assertOutput(ftl, "");
+    public void testEmptyNextSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.name?nextSibling}";
+        assertOutput(ftl, "\n    ");
     }
 
+    @Test
+    public void testNonEmptyNextSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.dob?nextSibling}";
+        assertOutput(ftl, "Chennai, India");
+    }
 
+    @Test
+    public void testSignificantNextSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.name.@@next}";
+        assertOutput(ftl, "12th August");
+    }
+
+    @Test
+    public void testSignificantPreviousSibling() throws IOException, TemplateException {
+        String ftl = "${doc.person.name.@@previous}";
+        assertOutput(ftl, "male");
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0ad01886/src/test/resources/freemarker/core/siblingDataModel.xml
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/siblingDataModel.xml b/src/test/resources/freemarker/core/siblingDataModel.xml
index f743e2e..13f928a 100644
--- a/src/test/resources/freemarker/core/siblingDataModel.xml
+++ b/src/test/resources/freemarker/core/siblingDataModel.xml
@@ -2,5 +2,5 @@
 <person>
     <gender>male</gender>
     <name>pradeep</name>
-    <dob>12th August</dob>
+    <dob>12th August</dob><address>Chennai, India</address>
 </person>