From ecec63b55bf12bef19b2b316071d065b068746ea Mon Sep 17 00:00:00 2001
From: Torsten Werner <twerner@debian.org>
Date: Wed, 4 Aug 2010 03:02:05 +0200
Subject: [PATCH] disable jython extension

Freemarker 2.3.16 fails to build against jython 2.5 because the PyJavaInstance
class has been removed. See
<https://sourceforge.net/tracker/index.php?func=detail&aid=2831150&group_id=794&atid=100794>
for the upstream bug.
---
 build.xml                                       |    1 -
 src/freemarker/ext/jython/JythonHashModel.java  |    4 +-
 src/freemarker/ext/jython/JythonModelCache.java |   45 +----------------------
 3 files changed, 3 insertions(+), 47 deletions(-)

Index: b/build.xml
===================================================================
--- a/build.xml
+++ b/build.xml
@@ -554,7 +554,6 @@
         <antcall target="compile-commons-logging"/>
         <antcall target="compile-jdk14"/>
         <antcall target="compile-jdk15"/>
-        <antcall target="compile-jython"/>
         <antcall target="compile-dom4j"/>
         <antcall target="compile-jdom"/>
         <antcall target="compile-xalan"/>
Index: b/src/freemarker/ext/jython/JythonHashModel.java
===================================================================
--- a/src/freemarker/ext/jython/JythonHashModel.java
+++ b/src/freemarker/ext/jython/JythonHashModel.java
@@ -137,7 +137,7 @@
         {
             throw new TemplateModelException(e);
         }
-        throw new TemplateModelException("'?keys' is not supported as there is no 'keys' nor 'keySet' attribute on an instance of " + object.getType().getFullName());
+        throw new TemplateModelException("'?keys' is not supported as there is no 'keys' nor 'keySet' attribute");
     }
 
     /**
@@ -157,6 +157,6 @@
         {
             throw new TemplateModelException(e);
         }
-        throw new TemplateModelException("'?values' is not supported as there is no 'values' attribute on an instance of " + object.getType().getFullName());
+        throw new TemplateModelException("'?values' is not supported as there is no 'values' attribute");
     }
 }
Index: b/src/freemarker/ext/jython/JythonModelCache.java
===================================================================
--- a/src/freemarker/ext/jython/JythonModelCache.java
+++ b/src/freemarker/ext/jython/JythonModelCache.java
@@ -10,7 +10,6 @@
 import org.python.core.PyDictionary;
 import org.python.core.PyFloat;
 import org.python.core.PyInteger;
-import org.python.core.PyJavaInstance;
 import org.python.core.PyLong;
 import org.python.core.PyNone;
 import org.python.core.PyObject;
@@ -35,48 +34,6 @@
     }
     
     protected TemplateModel create(Object obj) {
-        boolean asHash = false;
-        boolean asSequence = false;
-        if(obj instanceof PyJavaInstance) {
-            Object jobj = ((PyJavaInstance)obj).__tojava__(java.lang.Object.class);
-            // FreeMarker-aware, Jython-wrapped Java objects are left intact 
-            if(jobj instanceof TemplateModel) {
-                return (TemplateModel)jobj; 
-            }
-            if(jobj instanceof Map) {
-                asHash = true;
-            }
-            if (jobj instanceof Date) {
-                return new DateModel((Date) jobj, BeansWrapper.getDefaultInstance());
-            }
-            else if(jobj instanceof Collection) {
-                asSequence = true;
-                // FIXME: This is an ugly hack, but AFAIK, there's no better
-                // solution if we want to have Sets and other non-List
-                // collections managed by this layer, as Jython quite clearly
-                // doesn't support sets.  
-                if(!(jobj instanceof List)) {
-                    obj = new ArrayList((Collection)jobj); 
-                }
-            }
-        }
-        
-        // If it's not a PyObject, first make a PyObject out of it.
-        if(!(obj instanceof PyObject)) {
-            obj = Py.java2py(obj);
-        }
-        if(asHash || obj instanceof PyDictionary || obj instanceof PyStringMap) {
-            return JythonHashModel.FACTORY.create(obj, wrapper);
-        }
-        if(asSequence || obj instanceof PySequence) {
-            return JythonSequenceModel.FACTORY.create(obj, wrapper);
-        }
-        if(obj instanceof PyInteger || obj instanceof PyLong || obj instanceof PyFloat) {
-            return JythonNumberModel.FACTORY.create(obj, wrapper);
-        }
-        if(obj instanceof PyNone) {
-            return null;
-        }
-        return JythonModel.FACTORY.create(obj, wrapper);
+        throw new RuntimeException("Jython support is broken!");
     }
 }
