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 <[email protected]>
Authored: Tue Oct 27 22:18:37 2015 +0530
Committer: Pradeep <[email protected]>
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;
-}

Reply via email to