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/20 16:50:51 UTC
[5/5] incubator-freemarker git commit: Removed legacy extensions:
rhyno, jython, xml (not to be confused with dom), jdom,
ant. Also removed JSP 2.0 support (2.1 is the minimum for now,
but maybe it will be 2.2 later).
Removed legacy extensions: rhyno, jython, xml (not to be confused with dom), jdom, ant. Also removed JSP 2.0 support (2.1 is the minimum for now, but maybe it will be 2.2 later).
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/1588a7f5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/1588a7f5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/1588a7f5
Branch: refs/heads/3
Commit: 1588a7f5a08f87e5416272e59bb20e1024b0f3c3
Parents: 7f9ff74
Author: ddekany <dd...@apache.org>
Authored: Fri Jan 20 13:41:59 2017 +0100
Committer: ddekany <dd...@apache.org>
Committed: Fri Jan 20 17:49:16 2017 +0100
----------------------------------------------------------------------
README | 21 +-
build.xml | 69 +-
ivy.xml | 39 +-
src/main/java/freemarker/core/Configurable.java | 8 +-
src/main/java/freemarker/core/Environment.java | 15 -
src/main/java/freemarker/core/NewBI.java | 13 -
.../freemarker/core/TemplateClassResolver.java | 5 +-
.../freemarker/ext/ant/FreemarkerXmlTask.java | 629 ---------
.../java/freemarker/ext/ant/JythonAntTask.java | 92 --
.../ext/ant/UnlinkedJythonOperations.java | 39 -
.../ext/ant/UnlinkedJythonOperationsImpl.java | 59 -
src/main/java/freemarker/ext/ant/package.html | 27 -
.../java/freemarker/ext/beans/BeansWrapper.java | 21 +-
.../java/freemarker/ext/jdom/NodeListModel.java | 1200 ------------------
src/main/java/freemarker/ext/jdom/package.html | 29 -
.../ext/jsp/FreeMarkerJspFactory2.java | 29 -
.../freemarker/ext/jsp/PageContextFactory.java | 9 +-
.../ext/jsp/_FreeMarkerPageContext2.java | 92 --
.../ext/jsp/_FreeMarkerPageContext21.java | 5 +-
.../freemarker/ext/jython/JythonHashModel.java | 113 --
.../java/freemarker/ext/jython/JythonModel.java | 176 ---
.../freemarker/ext/jython/JythonModelCache.java | 101 --
.../ext/jython/JythonNumberModel.java | 69 -
.../ext/jython/JythonSequenceModel.java | 90 --
.../ext/jython/JythonVersionAdapter.java | 48 -
.../ext/jython/JythonVersionAdapterHolder.java | 74 --
.../freemarker/ext/jython/JythonWrapper.java | 276 ----
.../jython/_Jython20And21VersionAdapter.java | 45 -
.../ext/jython/_Jython22VersionAdapter.java | 45 -
.../ext/jython/_Jython25VersionAdapter.java | 48 -
.../java/freemarker/ext/jython/package.html | 37 -
.../ext/rhino/RhinoFunctionModel.java | 57 -
.../ext/rhino/RhinoScriptableModel.java | 136 --
.../java/freemarker/ext/rhino/RhinoWrapper.java | 87 --
src/main/java/freemarker/ext/rhino/package.html | 28 -
.../ext/servlet/FreemarkerServlet.java | 14 -
.../java/freemarker/ext/xml/Namespaces.java | 85 --
src/main/java/freemarker/ext/xml/Navigator.java | 276 ----
.../java/freemarker/ext/xml/NodeListModel.java | 554 --------
.../java/freemarker/ext/xml/NodeOperator.java | 28 -
.../freemarker/ext/xml/_Dom4jNavigator.java | 246 ----
.../java/freemarker/ext/xml/_DomNavigator.java | 331 -----
.../freemarker/ext/xml/_JaxenNamespaces.java | 29 -
.../java/freemarker/ext/xml/_JdomNavigator.java | 346 -----
src/main/java/freemarker/ext/xml/package.html | 28 -
.../template/DefaultObjectWrapper.java | 35 +-
.../java/freemarker/template/ObjectWrapper.java | 2 +-
.../template/utility/JythonRuntime.java | 74 --
src/manual/en_US/FM3-CHANGE-LOG.txt | 6 +
.../core/ObjectBuilderSettingsTest.java | 23 +-
.../test/templatesuite/expected/transforms.txt | 7 -
.../test/templatesuite/templates/transforms.ftl | 19 -
52 files changed, 48 insertions(+), 5886 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/README
----------------------------------------------------------------------
diff --git a/README b/README
index 2174e85..2098ad3 100644
--- a/README
+++ b/README
@@ -171,28 +171,21 @@ apply it to your development environment:
- Edit "JRE System Library [...]" to "Execution Environment" "JavaSE 1.6"
- Add all jar-s that are directly under the "ide-dependencies" directory
(use the "Add JARs..." and select all those files).
- - On the "Order and Export" tab find dom4j-*.jar, and send it to the
- bottom of the list (becase, an old org.jaxen is included inside
- dom4j-*.jar, which casues compilation errors if it wins over
- jaxen-*.jar).
- Press "Finish"
- Eclipse will indicate many errors at this point; it's expected, read on.
- Project -> Properties -> Java Compiler
- - Set "Compiler Compliance Level" to "1.5" (you will have to uncheck
+ - Set "Compiler Compliance Level" to "1.6" (you will have to uncheck
"Use compliance from execution environment" for that)
- In Errors/Warnings, check in "Enable project specific settings", then set
"Forbidden reference (access rules)" from "Error" to "Warning".
-- You will still have errors on these java files (because different java
- files depend on different versions of the same library, and Eclipse can't
- handle that). Exclude those java files from the Build Path (in the Package
- Explorer, right click on the problematic file -> "Build Path" -> "Exclude").
- _Jython20*.java
- _Jython22*.java
- _FreeMarkerPageContext2.java
- FreeMarkerJspFactory2.java
- Also, close these files if they are open. Now you shouldn't have any errors.
- At Project -> Properties -> Java Code Style -> Formatter, check in "Enable
project specific settings", and then select "FreeMarker" as active profile.
+- At Project -> Properties -> Java Editor -> Save Actions, check "Enable project
+ specific settings", then "Perform the selected actions on save", and have
+ only "Organize imports" and "Additional actions" checked (the list for the
+ last should contain "Add missing @Override annotations",
+ "Add missing @Override annotations to implementations of interface methods",
+ "Add missing @Deprecated annotations", and "Remove unnecessary cast").
- Right click on the project -> Run As -> JUnit Test
It should run without problems (all green).
- It's highly recommened to use the Eclipse FindBugs plugin.
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/build.xml
----------------------------------------------------------------------
diff --git a/build.xml b/build.xml
index dd0be33..096e000 100644
--- a/build.xml
+++ b/build.xml
@@ -245,11 +245,7 @@
freemarker/core/_Java6Impl.java,
freemarker/ext/jsp/**,
freemarker/ext/servlet/**,
- freemarker/cache/WebappTemplateLoader.java,
-
- freemarker/ext/jython/**,
- freemarker/template/utility/JythonRuntime.java,
- freemarker/ext/ant/**"
+ freemarker/cache/WebappTemplateLoader.java"
>
<src>
<pathelement location="build/src-main-java-filtered" />
@@ -272,71 +268,18 @@
verify="yes" stubversion="1.2"
/>
- <ivy:cachepath conf="build.jsp2.0" pathid="ivy.dep.jsp2.0" />
+ <ivy:cachepath conf="build.jsp2.1" pathid="ivy.dep.jsp2.1" />
<javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
includeantruntime="false"
- classpathref="ivy.dep.jsp2.0"
+ classpathref="ivy.dep.jsp2.1"
bootclasspath="${boot.classpath.j2se1.5}"
includes="
freemarker/ext/jsp/**,
freemarker/ext/servlet/**,
freemarker/cache/WebappTemplateLoader.java"
- excludes="
- freemarker/ext/jsp/_FreeMarkerPageContext21.java,
- freemarker/ext/jsp/FreeMarkerJspFactory21.java,
- freemarker/ext/jsp/FreeMarkerJspApplicationContext.java"
- />
-
- <!-- There's no build.jsp2.0, as those classes are part of the common build subset. -->
-
- <ivy:cachepath conf="build.jsp2.1" pathid="ivy.dep.jsp2.1" />
- <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
- debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
- includeantruntime="false"
- classpathref="ivy.dep.jsp2.1"
- bootclasspath="${boot.classpath.j2se1.5}"
- includes="
- freemarker/ext/jsp/_FreeMarkerPageContext21.java,
- freemarker/ext/jsp/FreeMarkerJspFactory21.java,
- freemarker/ext/jsp/FreeMarkerJspApplicationContext.java"
/>
-
- <ivy:cachepath conf="build.jython2.0" pathid="ivy.dep.jython2.0" />
- <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
- debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
- includeantruntime="false"
- classpathref="ivy.dep.jython2.0"
- bootclasspath="${boot.classpath.j2se1.5}"
- includes="
- freemarker/ext/ant/**,
- freemarker/template/utility/JythonRuntime.java,
- freemarker/ext/jython/**"
- excludes="
- freemarker/ext/jython/_Jython22VersionAdapter.java,
- freemarker/ext/jython/_Jython25VersionAdapter.java"
- />
-
- <ivy:cachepath conf="build.jython2.2" pathid="ivy.dep.jython2.2" />
- <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
- debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
- includeantruntime="false"
- classpathref="ivy.dep.jython2.2"
- bootclasspath="${boot.classpath.j2se1.5}"
- includes="
- freemarker/ext/jython/_Jython22VersionAdapter.java"
- />
-
- <ivy:cachepath conf="build.jython2.5" pathid="ivy.dep.jython2.5" />
- <javac srcdir="build/src-main-java-filtered" destdir="build/classes" deprecation="off"
- debug="on" optimize="off" target="1.5" source="1.5" encoding="utf-8"
- includeantruntime="false"
- classpathref="ivy.dep.jython2.5"
- bootclasspath="${boot.classpath.j2se1.5}"
- includes="
- freemarker/ext/jython/_Jython25VersionAdapter.java"
- />
-
+
<rmic base="build/classes" classpathref="ivy.dep"
includes="build/src-main-java-filtered/freemarker/debug/impl/Rmi*Impl.class"
verify="yes" stubversion="1.2"
@@ -711,7 +654,6 @@
<exclude name="**/*.~*" />
<exclude name="**/*.*~" />
<include name="src/**" />
- <include name="examples/**" />
<include name="*.xml" />
<include name="*.sample" />
<include name="*.txt" />
@@ -1062,7 +1004,8 @@ Proceed? </input>
<ivy:report todir="build/deps-report" />
</target>
- <target name="ide-dependencies" description="If your IDE has no Ivy support, this generates ide-lib/*.jar for it">
+ <target name="ide-dependencies" depends="jar"
+ description="If your IDE has no Ivy support, this generates ide-lib/*.jar for it">
<mkdir dir="ide-dependencies" />
<delete includeEmptyDirs="true">
<fileset dir="ide-dependencies">
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/ivy.xml
----------------------------------------------------------------------
diff --git a/ivy.xml b/ivy.xml
index 9598c87..9bcaf23 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -44,27 +44,15 @@
<conf name="build.base" extends="default" visibility="private"
description="for building FreeMarker without dependencies that optinal dependencies"
/>
-
- <conf name="build.jsp2.0" extends="build.base"
- description="for building FreeMarker with JSP 2.0 support"
+
+ <conf name="test" extends="build.base"
+ description="commons for both building and running the FreeMarker test suite"
/>
+
<conf name="build.jsp2.1" extends="build.base"
description="for building FreeMarker with JSP 2.1 support"
/>
- <conf name="build.jython2.0" extends="build.base"
- description="for building FreeMarker with Jython 2.0 support"
- />
- <conf name="build.jython2.2" extends="build.base"
- description="for building FreeMarker with Jython 2.2 support"
- />
- <conf name="build.jython2.5" extends="build.base"
- description="for building FreeMarker with Jython 2.5 support"
- />
-
- <conf name="test" extends="build.jython2.5"
- description="commons for both building and running the FreeMarker test suite"
- />
<conf name="build.test" extends="test"
description="for building FreeMarker test suite"
/>
@@ -76,8 +64,6 @@
description="to be used in IDE-s (maybe with the Ivy plugin)"
/>
- <conf name="retrotranslate" description="for retro-translation" />
-
<conf name="parser" extends="default" description="for generating parser" />
<conf name="manual" description="for generating the manual with Docgen" />
@@ -85,12 +71,6 @@
<conf name="rat" description="for generating the Rat report" />
<conf name="bnd" description="for creating OSGi bundle" />
-
- <conf name="example.servlet" description="servlet-based examples" />
- <conf name="example.webapp1" extends="example.servlet" />
- <conf name="example.webapp2" extends="example.servlet" />
- <conf name="example.struts-webapp" extends="example.servlet" />
- <conf name="example.ant" />
</configurations>
<publications>
<artifact name="freemarker" type="jar" conf="runtime" ext="jar" />
@@ -104,26 +84,15 @@
<!-- The lowerst supported xml-apis version depends on JDK version; prevent any collosion: -->
<exclude org="xml-apis" module="xml-apis" />
</dependency>
- <dependency org="dom4j" name="dom4j" rev="1.3" conf="build.base->default" /> <!-- legacy -->
- <dependency org="jdom" name="jdom" rev="1.0b8" conf="build.base->default" /> <!-- legacy -->
<dependency org="ant" name="ant" rev="1.6.5" conf="build.base->default">
<!-- The lowerst supported xml-apis version depends on JDK version; prevent any collosion: -->
<exclude org="xml-apis" module="xml-apis" />
</dependency>
- <dependency org="javax.servlet.jsp" name="jsp-api" rev="2.0" conf="build.jsp2.0->default; example.struts-webapp->default" />
- <dependency org="javax.servlet" name="servlet-api" rev="2.4" conf="build.jsp2.0->default; example.servlet->default" />
<dependency org="javax.servlet.jsp" name="jsp-api" rev="2.1" conf="build.jsp2.1->default" />
<dependency org="javax.servlet" name="servlet-api" rev="2.5" conf="build.jsp2.1->default" />
- <dependency org="rhino" name="js" rev="1.6R1" conf="build.base->default" />
-
- <!-- We use Jython 2.1 because there was no 2.0 in central; the relevant methods are the same. -->
- <dependency org="jython" name="jython" rev="2.1" conf="build.jython2.0->default" />
- <dependency org="org.python" name="jython" rev="2.2.1" conf="build.jython2.2->default" />
- <dependency org="org.python" name="jython" rev="2.5.0" conf="build.jython2.5->default" />
-
<dependency org="avalon-logkit" name="avalon-logkit" rev="2.0" conf="build.base->default" />
<dependency org="org.slf4j" name="slf4j-api" rev="&slf4j.version;" conf="build.base->default" />
<dependency org="org.slf4j" name="log4j-over-slf4j" rev="&slf4j.version;" conf="build.base->default" />
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/core/Configurable.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Configurable.java b/src/main/java/freemarker/core/Configurable.java
index 8dc4762..a709deb 100644
--- a/src/main/java/freemarker/core/Configurable.java
+++ b/src/main/java/freemarker/core/Configurable.java
@@ -2043,8 +2043,7 @@ public class Configurable {
* {@code "default_2_3_0"} (means the deprecated {@link ObjectWrapper#DEFAULT_WRAPPER})
* {@code "simple"} (means the deprecated {@link ObjectWrapper#SIMPLE_WRAPPER}),
* {@code "beans"} (means the deprecated {@link BeansWrapper#BEANS_WRAPPER}
- * or {@link BeansWrapperBuilder#build()}),
- * {@code "jython"} (means {@link freemarker.ext.jython.JythonWrapper#DEFAULT_WRAPPER})
+ * or {@link BeansWrapperBuilder#build()})
*
* <li><p>{@code "number_format"}: See {@link #setNumberFormat(String)}.
*
@@ -2476,11 +2475,6 @@ public class Configurable {
setObjectWrapper(ObjectWrapper.SIMPLE_WRAPPER);
} else if ("beans".equalsIgnoreCase(value)) {
setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
- } else if ("jython".equalsIgnoreCase(value)) {
- Class clazz = Class.forName(
- "freemarker.ext.jython.JythonWrapper");
- setObjectWrapper(
- (ObjectWrapper) clazz.getField("INSTANCE").get(null));
} else {
setObjectWrapper((ObjectWrapper) _ObjectBuilderSettingEvaluator.eval(
value, ObjectWrapper.class, false, _SettingEvaluationEnvironment.getCurrent()));
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/core/Environment.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/Environment.java b/src/main/java/freemarker/core/Environment.java
index 3e454d6..e1cd94f 100644
--- a/src/main/java/freemarker/core/Environment.java
+++ b/src/main/java/freemarker/core/Environment.java
@@ -44,7 +44,6 @@ import java.util.TimeZone;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import freemarker.cache.TemplateNameFormat;
import freemarker.cache._CacheAPI;
-import freemarker.ext.beans.BeansWrapper;
import freemarker.log.Logger;
import freemarker.template.Configuration;
import freemarker.template.MalformedTemplateNameException;
@@ -2732,20 +2731,6 @@ public final class Environment extends Configurable {
return currentNamespace.getTemplate().getDefaultNS();
}
- /**
- * A hook that Jython uses.
- */
- public Object __getitem__(String key) throws TemplateModelException {
- return BeansWrapper.getDefaultInstance().unwrap(getVariable(key));
- }
-
- /**
- * A hook that Jython uses.
- */
- public void __setitem__(String key, Object o) throws TemplateException {
- setGlobalVariable(key, getObjectWrapper().wrap(o));
- }
-
private IdentityHashMap<Object, Object> customStateVariables;
/**
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/core/NewBI.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/NewBI.java b/src/main/java/freemarker/core/NewBI.java
index eddd823..611921c 100644
--- a/src/main/java/freemarker/core/NewBI.java
+++ b/src/main/java/freemarker/core/NewBI.java
@@ -36,15 +36,6 @@ import freemarker.template.TemplateModelException;
*/
class NewBI extends BuiltIn {
- static Class<?> JYTHON_MODEL_CLASS;
- static {
- try {
- JYTHON_MODEL_CLASS = Class.forName("freemarker.ext.jython.JythonModel");
- } catch (Throwable e) {
- JYTHON_MODEL_CLASS = null;
- }
- }
-
@Override
TemplateModel _eval(Environment env)
throws TemplateException {
@@ -67,10 +58,6 @@ class NewBI extends BuiltIn {
throw new _MiscTemplateException(NewBI.this, env,
"Bean Models cannot be instantiated using the ?", key, " built-in");
}
- if (JYTHON_MODEL_CLASS != null && JYTHON_MODEL_CLASS.isAssignableFrom(cl)) {
- throw new _MiscTemplateException(NewBI.this, env,
- "Jython Models cannot be instantiated using the ?", key, " built-in");
- }
}
public Object exec(List arguments) throws TemplateModelException {
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/core/TemplateClassResolver.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateClassResolver.java b/src/main/java/freemarker/core/TemplateClassResolver.java
index ab2a713..80da24f 100644
--- a/src/main/java/freemarker/core/TemplateClassResolver.java
+++ b/src/main/java/freemarker/core/TemplateClassResolver.java
@@ -57,15 +57,14 @@ public interface TemplateClassResolver {
/**
* Same as {@link #UNRESTRICTED_RESOLVER}, except that it doesn't allow
- * resolving {@link ObjectConstructor} and {@link Execute} and {@code freemarker.template.utility.JythonRuntime}.
+ * resolving {@link ObjectConstructor} and {@link Execute}.
*/
TemplateClassResolver SAFER_RESOLVER = new TemplateClassResolver() {
public Class resolve(String className, Environment env, Template template)
throws TemplateException {
if (className.equals(ObjectConstructor.class.getName())
- || className.equals(Execute.class.getName())
- || className.equals("freemarker.template.utility.JythonRuntime")) {
+ || className.equals(Execute.class.getName())) {
throw MessageUtil.newInstantiatingClassNotAllowedException(className, env);
}
try {
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/ant/FreemarkerXmlTask.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/ant/FreemarkerXmlTask.java b/src/main/java/freemarker/ext/ant/FreemarkerXmlTask.java
deleted file mode 100644
index 96b755a..0000000
--- a/src/main/java/freemarker/ext/ant/FreemarkerXmlTask.java
+++ /dev/null
@@ -1,629 +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.ext.ant;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXParseException;
-
-import freemarker.ext.dom.NodeModel;
-import freemarker.ext.xml.NodeListModel;
-import freemarker.template.Configuration;
-import freemarker.template.SimpleHash;
-import freemarker.template.SimpleScalar;
-import freemarker.template.Template;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateNodeModel;
-import freemarker.template.utility.ClassUtil;
-import freemarker.template.utility.SecurityUtilities;
-
-
-/**
- * <p>This is an <a href="http://jakarta.apache.org/ant/" target="_top">Ant</a> task for transforming
- * XML documents using FreeMarker templates. It uses the adapter class
- * {@link NodeListModel}. It will read a set of XML documents, and pass them to
- * the template for processing, building the corresponding output files in the
- * destination directory.</p>
- * <p>It makes the following variables available to the template in the data model:</p>
- * <ul>
- * <li><tt>document</tt>: <em>Deprecated!</em> The DOM tree of the currently processed XML file wrapped
- with the legacy {@link freemarker.ext.xml.NodeListModel}.
- For new projects you should use the <tt>.node</tt> instead, which initially
- contains the DOM Document wrapped with {@link freemarker.ext.dom.NodeModel}.</li>
- * <li><tt>properties</tt>: a {@link freemarker.template.SimpleHash} containing
- * properties of the project that executes the task</li>
- * <li><tt>userProperties</tt>: a {@link freemarker.template.SimpleHash} containing
- * user properties of the project that executes the task</li>
- * <li><tt>project</tt>: the DOM tree of the XML file specified by the
- * <tt>projectfile</tt>. It will not be available if you didn't specify the
- * <tt>projectfile</tt> attribute.</li>
- * <li>further custom models can be instantiated and made available to the
- * templates using the <tt>models</tt> attribute.</li>
- * </ul>
- * <p>It supports the following attributes:</p>
- * <table style="width: auto; border-collapse: collapse" border="1" summary="FreeMarker XML ant task attributes">
- * <tr>
- * <th valign="top" align="left">Attribute</th>
- * <th valign="top" align="left">Description</th>
- * <th valign="top">Required</th>
- * </tr>
- * <tr>
- * <td valign="top">basedir</td>
- * <td valign="top">location of the XML files. Defaults to the project's
- * basedir.</td>
- * <td align="center" valign="top">No</td>
- * </tr>
- * <tr>
- * <td valign="top">destdir</td>
- * <td valign="top">location to store the generated files.</td>
- * <td align="center" valign="top">Yes</td>
- * </tr>
- * <tr>
- * <td valign="top">includes</td>
- * <td valign="top">comma-separated list of patterns of files that must be
- * included; all files are included when omitted.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">includesfile</td>
- * <td valign="top">the name of a file that contains
- * include patterns.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">excludes</td>
- * <td valign="top">comma-separated list of patterns of files that must be
- * excluded; no files (except default excludes) are excluded when omitted.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">excludesfile</td>
- * <td valign="top">the name of a file that contains
- * exclude patterns.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">defaultexcludes</td>
- * <td valign="top">indicates whether default excludes should be used
- * (<code>yes</code> | <code>no</code>); default excludes are used when omitted.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">extension</td>
- * <td valign="top">extension of generated files. Defaults to .html.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">template</td>
- * <td valign="top">name of the FreeMarker template file that will be
- * applied by default to XML files</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">templateDir</td>
- * <td valign="top">location of the FreeMarker template(s) to be used, defaults
- * to the project's baseDir</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">projectfile</td>
- * <td valign="top">path to the project file. The poject file must be an XML file.
- * If omitted, it will not be available to templates </td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">incremental</td>
- * <td valign="top">indicates whether all files should be regenerated (no), or
- * only those that are older than the XML file, the template file, or the
- * project file (yes). Defaults to yes. </td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">encoding</td>
- * <td valign="top">The encoding of the output files. Defaults to platform
- * default encoding.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">templateEncoding</td>
- * <td valign="top">The encoding of the template files. Defaults to platform
- * default encoding.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">validation</td>
- * <td valign="top">Whether to validate the XML input. Defaults to off.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">models</td>
- * <td valign="top">A list of [name=]className pairs separated by spaces,
- * commas, or semicolons that specifies further models that should be
- * available to templates. If name is omitted, the unqualified class name
- * is used as the name. Every class that is specified must implement the
- * TemplateModel interface and have a no-args constructor.</td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * </table>
- *
- * <p>It supports the following nesed elements:</p>
- *
- * <table style="width: auto; border-collapse: collapse" border="1" summary="FreeMarker XML ant task nested elements">
- * <tr>
- * <th valign="top" align="left">Element</th>
- * <th valign="top" align="left">Description</th>
- * <th valign="top">Required</th>
- * </tr>
- * <tr>
- * <td valign="top">prepareModel</td>
- * <td valign="top">
- * This element executes Jython script before the processing of each XML
- * files, that you can use to modify the data model.
- * You either enter the Jython script directly nested into this
- * element, or specify a Jython script file with the <tt>file</tt>
- * attribute.
- * The following variables are added to the Jython runtime's local
- * namespace before the script is invoked:
- * <ul>
- * <li><tt>model</tt>: The data model as <code>java.util.HashMap</code>.
- * You can read and modify the data model with this variable.
- * <li><tt>doc</tt>: The XML document as <code>org.w3c.dom.Document</code>.
- * <li><tt>project</tt>: The project document (if used) as
- * <code>org.w3c.dom.Document</code>.
- * </ul>
- * <i>If this element is used, Jython classes (tried with Jython 2.1)
- * must be available.</i>
- * </td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * <tr>
- * <td valign="top">prepareEnvironment</td>
- * <td valign="top">This element executes Jython script before the processing
- * of each XML files, that you can use to modify the freemarker environment
- * ({@link freemarker.core.Environment}). The script is executed after the
- * <tt>prepareModel</tt> element. The accessible Jython variables are the
- * same as with the <tt>prepareModel</tt> element, except that there is no
- * <tt>model</tt> variable, but there is <tt>env</tt> variable, which is
- * the FreeMarker environment ({@link freemarker.core.Environment}).
- * <i>If this element is used, Jython classes (tried with Jython 2.1)
- * must be available.</i>
- * </td>
- * <td valign="top" align="center">No</td>
- * </tr>
- * </table>
- * @deprecated <a href="http://fmpp.sourceforge.net">FMPP</a> is a more complete solution.
- */
-@Deprecated
-public class FreemarkerXmlTask
-extends
- MatchingTask {
- private JythonAntTask prepareModel;
- private JythonAntTask prepareEnvironment;
- private final DocumentBuilderFactory builderFactory;
- private DocumentBuilder builder;
-
- /** the {@link Configuration} used by this task. */
- private Configuration cfg = new Configuration();
-
- /** the destination directory */
- private File destDir;
-
- /** the base directory */
- private File baseDir;
-
- //Where the templates live
-
- private File templateDir;
-
- /** the template= attribute */
- private String templateName;
-
- /** The template in its parsed form */
- private Template parsedTemplate;
-
- /** last modified of the template sheet */
- private long templateFileLastModified = 0;
-
- /** the projectFile= attribute */
- private String projectAttribute = null;
-
- private File projectFile = null;
-
- /** The DOM tree of the project wrapped into FreeMarker TemplateModel */
- private TemplateModel projectTemplate;
- // The DOM tree wrapped using the freemarker.ext.dom wrapping.
- private TemplateNodeModel projectNode;
- private TemplateModel propertiesTemplate;
- private TemplateModel userPropertiesTemplate;
-
- /** last modified of the project file if it exists */
- private long projectFileLastModified = 0;
-
- /** check the last modified date on files. defaults to true */
- private boolean incremental = true;
-
- /** the default output extension is .html */
- private String extension = ".html";
-
- private String encoding = SecurityUtilities.getSystemProperty("file.encoding", "utf-8");
- private String templateEncoding = encoding;
- private boolean validation = false;
-
- private String models = "";
- private final Map modelsMap = new HashMap();
-
-
-
- /**
- * Constructor creates the SAXBuilder.
- */
- public FreemarkerXmlTask() {
- builderFactory = DocumentBuilderFactory.newInstance();
- builderFactory.setNamespaceAware(true);
- }
-
- /**
- * Set the base directory. Defaults to <tt>.</tt>
- */
- public void setBasedir(File dir) {
- baseDir = dir;
- }
-
- /**
- * Set the destination directory into which the generated
- * files should be copied to
- * @param dir the name of the destination directory
- */
- public void setDestdir(File dir) {
- destDir = dir;
- }
-
- /**
- * Set the output file extension. <tt>.html</tt> by default.
- */
- public void setExtension(String extension) {
- this.extension = extension;
- }
-
- public void setTemplate(String templateName) {
- this.templateName = templateName;
- }
-
- public void setTemplateDir(File templateDir) throws BuildException {
- this.templateDir = templateDir;
- try {
- cfg.setDirectoryForTemplateLoading(templateDir);
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
-
- /**
- * Set the path to the project XML file
- */
- public void setProjectfile(String projectAttribute) {
- this.projectAttribute = projectAttribute;
- }
-
- /**
- * Turn on/off incremental processing. On by default
- */
- public void setIncremental(String incremental) {
- this.incremental = !(incremental.equalsIgnoreCase("false") || incremental.equalsIgnoreCase("no") || incremental.equalsIgnoreCase("off"));
- }
-
- /**
- * Set encoding for generated files. Defaults to platform default encoding.
- */
- public void setEncoding(String encoding) {
- this.encoding = encoding;
- }
-
- public void setTemplateEncoding(String inputEncoding) {
- this.templateEncoding = inputEncoding;
- }
-
- /**
- * Sets whether to validate the XML input.
- */
- public void setValidation(boolean validation) {
- this.validation = validation;
- }
-
- public void setModels(String models) {
- this.models = models;
- }
-
- @Override
- public void execute() throws BuildException {
- DirectoryScanner scanner;
- String[] list;
-
- if (baseDir == null) {
- baseDir = getProject().getBaseDir();
- }
- if (destDir == null ) {
- String msg = "destdir attribute must be set!";
- throw new BuildException(msg, getLocation());
- }
-
- File templateFile = null;
-
- if (templateDir == null) {
- if (templateName != null) {
- templateFile = new File(templateName);
- if (!templateFile.isAbsolute()) {
- templateFile = new File(getProject().getBaseDir(), templateName);
- }
- templateDir = templateFile.getParentFile();
- templateName = templateFile.getName();
- } else {
- templateDir = baseDir;
- }
- setTemplateDir(templateDir);
- } else if (templateName != null) {
- if (new File(templateName).isAbsolute()) {
- throw new BuildException("Do not specify an absolute location for the template as well as a templateDir");
- }
- templateFile = new File(templateDir, templateName);
- }
- if (templateFile != null) {
- templateFileLastModified = templateFile.lastModified();
- }
-
- try {
- if (templateName != null) {
- parsedTemplate = cfg.getTemplate(templateName, templateEncoding);
- }
- } catch (IOException ioe) {
- throw new BuildException(ioe.toString());
- }
- // get the last modification of the template
- log("Transforming into: " + destDir.getAbsolutePath(), Project.MSG_INFO);
-
- // projectFile relative to baseDir
- if (projectAttribute != null && projectAttribute.length() > 0) {
- projectFile = new File(baseDir, projectAttribute);
- if (projectFile.isFile())
- projectFileLastModified = projectFile.lastModified();
- else {
- log ("Project file is defined, but could not be located: " +
- projectFile.getAbsolutePath(), Project.MSG_INFO );
- projectFile = null;
- }
- }
-
- generateModels();
-
- // find the files/directories
- scanner = getDirectoryScanner(baseDir);
-
- propertiesTemplate = wrapMap(project.getProperties());
- userPropertiesTemplate = wrapMap(project.getUserProperties());
-
- builderFactory.setValidating(validation);
- try {
- builder = builderFactory.newDocumentBuilder();
- } catch (ParserConfigurationException e) {
- throw new BuildException("Could not create document builder", e, getLocation());
- }
-
- // get a list of files to work on
- list = scanner.getIncludedFiles();
-
-
- for (int i = 0; i < list.length; ++i) {
- process(baseDir, list[i], destDir);
- }
- }
-
- public void addConfiguredJython(JythonAntTask jythonAntTask) {
- this.prepareEnvironment = jythonAntTask;
- }
-
- public void addConfiguredPrepareModel(JythonAntTask prepareModel) {
- this.prepareModel = prepareModel;
- }
-
- public void addConfiguredPrepareEnvironment(JythonAntTask prepareEnvironment) {
- this.prepareEnvironment = prepareEnvironment;
- }
-
- /**
- * Process an XML file using FreeMarker
- */
- private void process(File baseDir, String xmlFile, File destDir)
- throws BuildException {
- File outFile = null;
- File inFile = null;
- try {
- // the current input file relative to the baseDir
- inFile = new File(baseDir,xmlFile);
- // the output file relative to basedir
- outFile = new File(destDir,
- xmlFile.substring(0,
- xmlFile.lastIndexOf('.')) + extension);
-
- // only process files that have changed
- if (!incremental ||
- (inFile.lastModified() > outFile.lastModified() ||
- templateFileLastModified > outFile.lastModified() ||
- projectFileLastModified > outFile.lastModified())) {
- ensureDirectoryFor(outFile);
-
- //-- command line status
- log("Input: " + xmlFile, Project.MSG_INFO );
-
- if (projectTemplate == null && projectFile != null) {
- Document doc = builder.parse(projectFile);
- projectTemplate = new NodeListModel(builder.parse(projectFile));
- projectNode = NodeModel.wrap(doc);
- }
-
- // Build the file DOM
- Document docNode = builder.parse(inFile);
-
- TemplateModel document = new NodeListModel(docNode);
- TemplateNodeModel docNodeModel = NodeModel.wrap(docNode);
- HashMap root = new HashMap();
- root.put("document", document);
- insertDefaults(root);
-
- // Process the template and write out
- // the result as the outFile.
- Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), encoding));
- try {
- if (parsedTemplate == null) {
- throw new BuildException("No template file specified in build script or in XML file");
- }
- if (prepareModel != null) {
- Map vars = new HashMap();
- vars.put("model", root);
- vars.put("doc", docNode);
- if (projectNode != null) {
- vars.put("project", ((NodeModel) projectNode).getNode());
- }
- prepareModel.execute(vars);
- }
- freemarker.core.Environment env = parsedTemplate.createProcessingEnvironment(root, writer);
- env.setCurrentVisitorNode(docNodeModel);
- if (prepareEnvironment != null) {
- Map vars = new HashMap();
- vars.put("env", env);
- vars.put("doc", docNode);
- if (projectNode != null) {
- vars.put("project", ((NodeModel) projectNode).getNode());
- }
- prepareEnvironment.execute(vars);
- }
- env.process();
- writer.flush();
- } finally {
- writer.close();
- }
-
- log("Output: " + outFile, Project.MSG_INFO );
-
- }
- } catch (SAXParseException spe) {
- Throwable rootCause = spe;
- if (spe.getException() != null)
- rootCause = spe.getException();
- log("XML parsing error in " + inFile.getAbsolutePath(), Project.MSG_ERR);
- log("Line number " + spe.getLineNumber());
- log("Column number " + spe.getColumnNumber());
- throw new BuildException(rootCause, getLocation());
- } catch (Throwable e) {
- if (outFile != null ) {
- if (!outFile.delete() && outFile.exists()) {
- log("Failed to delete " + outFile, Project.MSG_WARN);
- }
- }
- e.printStackTrace();
- throw new BuildException(e, getLocation());
- }
- }
-
- private void generateModels() {
- StringTokenizer modelTokenizer = new StringTokenizer(models, ",; ");
- while (modelTokenizer.hasMoreTokens()) {
- String modelSpec = modelTokenizer.nextToken();
- String name = null;
- String clazz = null;
-
- int sep = modelSpec.indexOf('=');
- if (sep == -1) {
- // No explicit name - use unqualified class name
- clazz = modelSpec;
- int dot = clazz.lastIndexOf('.');
- if (dot == -1) {
- // clazz in the default package
- name = clazz;
- } else {
- name = clazz.substring(dot + 1);
- }
- } else {
- name = modelSpec.substring(0, sep);
- clazz = modelSpec.substring(sep + 1);
- }
- try {
- modelsMap.put(name, ClassUtil.forName(clazz).newInstance());
- } catch (Exception e) {
- throw new BuildException(e);
- }
- }
- }
-
- /**
- * create directories as needed
- */
- private void ensureDirectoryFor( File targetFile ) throws BuildException {
- File directory = new File( targetFile.getParent() );
- if (!directory.exists()) {
- if (!directory.mkdirs()) {
- throw new BuildException("Unable to create directory: "
- + directory.getAbsolutePath(), getLocation());
- }
- }
- }
-
- private static TemplateModel wrapMap(Map table) {
- SimpleHash model = new SimpleHash();
- for (Iterator it = table.entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = (Map.Entry) it.next();
- model.put(String.valueOf(entry.getKey()), new SimpleScalar(String.valueOf(entry.getValue())));
- }
- return model;
- }
-
- protected void insertDefaults(Map root) {
- root.put("properties", propertiesTemplate);
- root.put("userProperties", userPropertiesTemplate);
- if (projectTemplate != null) {
- root.put("project", projectTemplate);
- root.put("project_node", projectNode);
- }
- if (modelsMap.size() > 0) {
- for (Iterator it = modelsMap.entrySet().iterator(); it.hasNext(); ) {
- Map.Entry entry = (Map.Entry) it.next();
- root.put(entry.getKey(), entry.getValue());
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/ant/JythonAntTask.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/ant/JythonAntTask.java b/src/main/java/freemarker/ext/ant/JythonAntTask.java
deleted file mode 100644
index 3308b71..0000000
--- a/src/main/java/freemarker/ext/ant/JythonAntTask.java
+++ /dev/null
@@ -1,92 +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.ext.ant;
-
-import java.io.File;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.ProjectHelper;
-import org.apache.tools.ant.Task;
-
-import freemarker.template.utility.ClassUtil;
-
-/**
- * Used internally, public for technical reasons only.
- *
- * <p>This is an Ant sub-task of the {@link FreemarkerXmlTask} task.
- *
- * <p><b>Warning! It must not be statically linked with Jython classes</b>,
- * so users can use the XML ant task even if Jython is not installed.
- */
-public class JythonAntTask extends Task {
-
- private File scriptFile;
- private String script = "";
- private UnlinkedJythonOperations jythonOps;
-
- public void setFile(File scriptFile) throws BuildException {
- ensureJythonOpsExists();
- this.scriptFile = scriptFile;
- }
-
- public void addText(String text) {
- script += text;
- }
-
- public void execute(Map vars) throws BuildException {
- if (scriptFile != null) {
- ensureJythonOpsExists();
- jythonOps.execute(scriptFile, vars);
- }
- if (script.trim().length() > 0) {
- ensureJythonOpsExists();
- String finalScript = ProjectHelper.replaceProperties(
- project, script, project.getProperties());
- jythonOps.execute(finalScript, vars);
- }
- }
-
- private void ensureJythonOpsExists() {
- if (jythonOps == null) {
- Class clazz;
- try {
- clazz = ClassUtil.forName(
- "freemarker.ext.ant.UnlinkedJythonOperationsImpl");
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(
- "A ClassNotFoundException has been thrown when trying "
- + "to get the "
- + "freemarker.ext.ant.UnlinkedJythonOperationsImpl class. "
- + "The error message was: " + e.getMessage());
- }
- try {
- jythonOps
- = (UnlinkedJythonOperations) clazz.newInstance();
- } catch (Exception e) {
- throw new RuntimeException(
- "An exception has been thrown when trying "
- + "to create a freemarker.ext.ant.JythonAntTask "
- + "object. The exception was: " + e);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/ant/UnlinkedJythonOperations.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/ant/UnlinkedJythonOperations.java b/src/main/java/freemarker/ext/ant/UnlinkedJythonOperations.java
deleted file mode 100644
index 7113482..0000000
--- a/src/main/java/freemarker/ext/ant/UnlinkedJythonOperations.java
+++ /dev/null
@@ -1,39 +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.ext.ant;
-
-import java.io.File;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-
-/**
- * This is an interface to do Jython operations, which has no dependecy on
- * Jython classes (hence "unlinked").
- *
- * @see JythonAntTask
- */
-interface UnlinkedJythonOperations {
-
- void execute(String script, Map variables) throws BuildException;
-
- void execute(File file, Map variables) throws BuildException;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/ant/UnlinkedJythonOperationsImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/ant/UnlinkedJythonOperationsImpl.java b/src/main/java/freemarker/ext/ant/UnlinkedJythonOperationsImpl.java
deleted file mode 100644
index b586716..0000000
--- a/src/main/java/freemarker/ext/ant/UnlinkedJythonOperationsImpl.java
+++ /dev/null
@@ -1,59 +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.ext.ant;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.tools.ant.BuildException;
-import org.python.util.PythonInterpreter;
-
-/**
- * Used internally, public for technical reasons only.
- */
-public class UnlinkedJythonOperationsImpl implements UnlinkedJythonOperations {
-
- public void execute(String script, Map vars) throws BuildException {
- PythonInterpreter pi = createInterpreter(vars);
- pi.exec(script);
- }
-
- public void execute(File file, Map vars) throws BuildException {
- PythonInterpreter pi = createInterpreter(vars);
- try {
- pi.execfile(file.getCanonicalPath());
- } catch (IOException e) {
- throw new BuildException(e);
- }
- }
-
- private PythonInterpreter createInterpreter(Map vars) {
- PythonInterpreter pi = new PythonInterpreter();
- Iterator it = vars.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry ent = (Map.Entry) it.next();
- pi.set((String) ent.getKey(), ent.getValue());
- }
- return pi;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/ant/package.html
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/ant/package.html b/src/main/java/freemarker/ext/ant/package.html
deleted file mode 100644
index 16d3343..0000000
--- a/src/main/java/freemarker/ext/ant/package.html
+++ /dev/null
@@ -1,27 +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.
--->
-<html>
-<head>
-</head>
-<BODY>
-<p>
-<a href="http://jakarta.apache.org/ant" target="_blank">Ant task</a> to transform XML files
-with a template; a more powerful alternative is <a href="http://fmpp.sourceforge.net/" target="_blank">FMPP</a>.
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1588a7f5/src/main/java/freemarker/ext/beans/BeansWrapper.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/BeansWrapper.java b/src/main/java/freemarker/ext/beans/BeansWrapper.java
index f840c95..28da1e4 100644
--- a/src/main/java/freemarker/ext/beans/BeansWrapper.java
+++ b/src/main/java/freemarker/ext/beans/BeansWrapper.java
@@ -94,18 +94,6 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
@Deprecated
static final Object CAN_NOT_UNWRAP = ObjectWrapperAndUnwrapper.CANT_UNWRAP_TO_TARGET_CLASS;
- private static final Class<?> ITERABLE_CLASS;
- static {
- Class<?> iterable;
- try {
- iterable = Class.forName("java.lang.Iterable");
- } catch (ClassNotFoundException e) {
- // We're running on a pre-1.5 JRE
- iterable = null;
- }
- ITERABLE_CLASS = iterable;
- }
-
private static final Constructor<?> ENUMS_MODEL_CTOR = enumsModelCtor();
/**
@@ -1040,12 +1028,11 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
}
// This is for transparent interop with other wrappers (and ourselves)
- // Passing the targetClass allows i.e. a Jython-aware method that declares a
- // PyObject as its argument to receive a PyObject from a JythonModel
+ // Passing the targetClass allows e.g. a Jython-aware method that declares a
+ // PyObject as its argument to receive a PyObject from a Jython-aware TemplateModel
// passed as an argument to TemplateMethodModelEx etc.
if (model instanceof AdapterTemplateModel) {
- Object wrapped = ((AdapterTemplateModel) model).getAdaptedObject(
- targetClass);
+ Object wrapped = ((AdapterTemplateModel) model).getAdaptedObject(targetClass);
if (targetClass == Object.class || targetClass.isInstance(wrapped)) {
return wrapped;
}
@@ -1124,7 +1111,7 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
}
}
- if (Collection.class == targetClass || ITERABLE_CLASS == targetClass) {
+ if (Collection.class == targetClass || Iterable.class == targetClass) {
if (model instanceof TemplateCollectionModel) {
return new CollectionAdapter((TemplateCollectionModel) model,
this);