You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2007/12/17 12:39:36 UTC

svn commit: r604840 [1/3] - in /incubator/sling/trunk/scripting: freemarker/ freemarker/src/main/java/org/apache/sling/scripting/freemarker/ freemarker/src/main/resources/ freemarker/src/main/resources/META-INF/ freemarker/src/main/resources/META-INF/s...

Author: fmeschbe
Date: Mon Dec 17 03:39:32 2007
New Revision: 604840

URL: http://svn.apache.org/viewvc?rev=604840&view=rev
Log:
SLING-110 Migrate former SlingScriptEngine implementations to Java Scripting

Added:
    incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngineFactory.java
    incubator/sling/trunk/scripting/freemarker/src/main/resources/
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE.freemarker
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/NOTICE
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/
    incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngine.java
      - copied, changed from r603540, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavasSriptEngine.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java
      - copied, changed from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java
      - copied, changed from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableNode.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java
      - copied, changed from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
    incubator/sling/trunk/scripting/javascript/src/main/resources/
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE.rhino
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/NOTICE
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/services/
    incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
    incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngineFactory.java
    incubator/sling/trunk/scripting/ruby/src/main/resources/
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/LICENSE
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/LICENSE.jruby
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/NOTICE
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/services/
    incubator/sling/trunk/scripting/ruby/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
    incubator/sling/trunk/scripting/velocity/src/main/java/org/apache/sling/scripting/velocity/VelocityTemplatesScriptEngineFactory.java
    incubator/sling/trunk/scripting/velocity/src/main/resources/
    incubator/sling/trunk/scripting/velocity/src/main/resources/META-INF/
    incubator/sling/trunk/scripting/velocity/src/main/resources/META-INF/LICENSE
    incubator/sling/trunk/scripting/velocity/src/main/resources/META-INF/NOTICE
    incubator/sling/trunk/scripting/velocity/src/main/resources/META-INF/services/
    incubator/sling/trunk/scripting/velocity/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
Removed:
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavasSriptEngine.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableNode.java
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java
Modified:
    incubator/sling/trunk/scripting/freemarker/pom.xml
    incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngine.java
    incubator/sling/trunk/scripting/javascript/pom.xml
    incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
    incubator/sling/trunk/scripting/ruby/pom.xml
    incubator/sling/trunk/scripting/ruby/src/main/java/org/apache/sling/scripting/ruby/ErbScriptEngine.java
    incubator/sling/trunk/scripting/velocity/pom.xml
    incubator/sling/trunk/scripting/velocity/src/main/java/org/apache/sling/scripting/velocity/VelocityTemplatesScriptEngine.java

Modified: incubator/sling/trunk/scripting/freemarker/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/pom.xml?rev=604840&r1=604839&r2=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/pom.xml (original)
+++ incubator/sling/trunk/scripting/freemarker/pom.xml Mon Dec 17 03:39:32 2007
@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!--
-  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.
+    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.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -64,8 +64,22 @@
                 <configuration>
                     <instructions>
                         <Private-Package>
-                            org.apache.sling.scripting.freemarker.*
+                            org.apache.sling.scripting.freemarker
                         </Private-Package>
+
+                        <Embed-Dependency>freemarker</Embed-Dependency>
+                        <Import-Package>
+                            javax.servlet.jsp.*; javax.swing.*;
+                            org.apache.log; org.apache.log4j;
+                            org.apache.tools.ant.*;
+                            org.apache.xml.utils; org.apache.xpath.*;
+                            org.dom4j.*; org.jaxen.*; org.jdom.*;
+                            org.mozilla.javascript;
+                            org.python.*;resolution:=optional, *
+                        </Import-Package>
+                        
+                        <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>
+                        <ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
                     </instructions>
                 </configuration>
             </plugin>
@@ -79,13 +93,22 @@
             <version>2.0.0-incubator-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.api</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
-	    <dependency>
-	        <groupId>freemarker</groupId>
-	        <artifactId>freemarker</artifactId>
-	        <version>2.3.6</version>
- 	    </dependency>
+        <dependency>
+            <groupId>freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>2.3.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
     </dependencies>
 </project>

Modified: incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngine.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngine.java?rev=604840&r1=604839&r2=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngine.java (original)
+++ incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngine.java Mon Dec 17 03:39:32 2007
@@ -17,16 +17,24 @@
 package org.apache.sling.scripting.freemarker;
 
 import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import java.io.Writer;
-import java.util.Map;
 
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
-import org.apache.sling.api.HttpStatusCodeException;
-import org.apache.sling.api.SlingException;
-import org.apache.sling.api.scripting.SlingScript;
-import org.apache.sling.api.scripting.SlingScriptEngine;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import freemarker.template.Configuration;
 import freemarker.template.Template;
@@ -34,57 +42,43 @@
 /**
  * A ScriptEngine that uses {@link http://freemarker.org/ FreeMarker} templates
  * to render a Resource in HTML.
- *
- * @scr.component
- * @scr.property name="service.vendor" value="The Apache Software Foundation"
- * @scr.property name="service.description" value="Sling FreeMarker Script Engine"
- * @scr.service interface="org.apache.sling.api.scripting.SlingScriptEngine"
  */
-public class FreemarkerScriptEngine implements SlingScriptEngine {
-
-    public final static String FREEMARKER_SCRIPT_EXTENSION = "ftl";
+public class FreemarkerScriptEngine extends AbstractSlingScriptEngine {
+    private static final Logger log = LoggerFactory.getLogger(FreemarkerScriptEngine.class);
 
     private final Configuration configuration;
 
-    public FreemarkerScriptEngine() {
+    public FreemarkerScriptEngine(ScriptEngineFactory factory) {
+        super(factory);
         configuration = new Configuration();
     }
 
-    public String[] getExtensions() {
-        return new String[] { FREEMARKER_SCRIPT_EXTENSION };
-    }
-
-    public String getEngineName() {
-        return "Freemarker Script Engine";
-    }
-
-    public String getEngineVersion() {
-        return "0.9";
-    }
-
-    public void eval(SlingScript script, Map<String, Object> props)
-            throws SlingException, IOException {
-
-        // ensure get method
-        HttpServletRequest request = (HttpServletRequest) props.get(REQUEST);
-        if (!"GET".equals(request.getMethod())) {
-            throw new HttpStatusCodeException(
-                HttpServletResponse.SC_METHOD_NOT_ALLOWED,
+    public Object eval(Reader reader, ScriptContext scriptContext)
+            throws ScriptException {
+        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
+        if (helper == null) {
+            throw new ScriptException("SlingScriptHelper missing from bindings");
+        }
+        
+        // ensure GET request
+        if (!"GET".equals(helper.getRequest().getMethod())) {
+            throw new ScriptException(
                 "FreeMarker templates only support GET requests");
         }
 
-        String scriptName = script.getScriptResource().getURI();
-        Template tmpl = new Template(scriptName, script.getScriptReader(),
-            configuration);
-
+        String scriptName = helper.getScript().getScriptResource().getURI();
+        
         try {
-            Writer w = ((HttpServletResponse) props.get(RESPONSE)).getWriter();
-            tmpl.process(props, w);
-        } catch (IOException ioe) {
-            throw ioe;
+            Template tmpl = new Template(scriptName, reader, configuration);
+            tmpl.process(bindings, scriptContext.getWriter());
         } catch (Throwable t) {
-            throw new SlingException("Failure running FreeMarker script "
-                + scriptName, t);
+            log.error("Failure running Freemarker script.", t);
+            throw new ScriptException("Failure running FreeMarker script "
+                + scriptName);
         }
+
+        return null;
     }
+
 }

Added: incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngineFactory.java?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngineFactory.java (added)
+++ incubator/sling/trunk/scripting/freemarker/src/main/java/org/apache/sling/scripting/freemarker/FreemarkerScriptEngineFactory.java Mon Dec 17 03:39:32 2007
@@ -0,0 +1,117 @@
+/*
+ * 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 org.apache.sling.scripting.freemarker;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.script.ScriptEngine;
+
+import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
+
+public class FreemarkerScriptEngineFactory extends AbstractScriptEngineFactory {
+
+    /** The extensions of FreeMarker scripts (value is "ftl"). */
+    public final static String FREEMARKER_SCRIPT_EXTENSION = "ftl";
+
+    /** The MIME type of FreeMarker script files (value is "text/x-freemarker"). */
+    public final static String FREEMARKER_MIME_TYPE = "text/x-freemarker";
+
+    /**
+     * The short name of the FreeMarker script engine factory (value is
+     * "freemarker").
+     */
+    public final static String SHORT_NAME = "freemarker";
+
+    /** The name of the FreeMarker language (value is "FreeMarker"). */
+    private static final String FREEMARKER_NAME = "FreeMarker";
+
+    /**
+     * The absolute path to the FreeMarker version properties file (value is
+     * "/freemarker/version.properties").
+     */
+    private static final String FREEMARKER_VERSION_PROPERTIES = "/freemarker/version.properties";
+
+    /**
+     * The name of the property containing the FreeMarker version (value is
+     * "version").
+     */
+    private static final String PROP_FREEMARKER_VERSION = "version";
+
+    /**
+     * The default version of FreeMarker if the version property cannot be read
+     * (value is "2.3", which is the latest minor version release as of
+     * 17.Dec.2007).
+     */
+    private static final String DEFAULT_FREEMARKER_VERSION = "2.3";
+
+    /**
+     * The FreeMarker language version extracted from the FreeMarker version
+     * properties file. If this file cannot be read the language version
+     * defaults to ...
+     */
+    private final String languageVersion;
+
+    public FreemarkerScriptEngineFactory() {
+        setExtensions(FREEMARKER_SCRIPT_EXTENSION);
+        setMimeTypes(FREEMARKER_MIME_TYPE);
+        setNames(SHORT_NAME);
+
+        // extract language version from version.properties file
+        String langVersion = null;
+        InputStream ins = null;
+        try {
+            ins = getClass().getResourceAsStream(FREEMARKER_VERSION_PROPERTIES);
+            if (ins != null) {
+                Properties props = new Properties();
+                props.load(ins);
+                langVersion = props.getProperty(PROP_FREEMARKER_VERSION);
+            }
+        } catch (IOException ioe) {
+            // don't really care, just use default
+        } finally {
+            if (ins != null) {
+                try {
+                    ins.close();
+                } catch (IOException ignore) {
+                    // ignore
+                }
+            }
+        }
+
+        // if we could not extract the actual version, assume version 2.3
+        // which is the current minor release as of 17.Dec.2007
+        languageVersion = (langVersion == null)
+                ? DEFAULT_FREEMARKER_VERSION
+                : langVersion;
+    }
+
+    public ScriptEngine getScriptEngine() {
+        return new FreemarkerScriptEngine(this);
+    }
+
+    public String getLanguageName() {
+        return FREEMARKER_NAME;
+    }
+
+    public String getLanguageVersion() {
+        return languageVersion;
+    }
+}

Added: incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE (added)
+++ incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE Mon Dec 17 03:39:32 2007
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.

Added: incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE.freemarker
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE.freemarker?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE.freemarker (added)
+++ incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/LICENSE.freemarker Mon Dec 17 03:39:32 2007
@@ -0,0 +1,37 @@
+Copyright (c) 2003 The Visigoth Software Society.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+   1. Redistributions of source code must retain the above copyright
+      notice, this list of conditions and the following disclaimer.
+      
+   2. The end-user documentation included with the redistribution,
+      if any, must include the following acknowledgement: "This
+      product includes software developed by the Visigoth Software
+      Society (http://www.visigoths.org/)." Alternately, this
+      acknowledgement may appear in the software itself, if and
+      wherever such third-party acknowledgements normally appear.
+      
+   3. Neither the name "FreeMarker", "Visigoth", nor any of the names
+      of the project contributors may be used to endorse or promote
+      products derived from this software without prior written
+      permission. For written permission, please contact
+      visigoths@visigoths.org.
+      
+   4. Products derived from this software may not be called "FreeMarker"
+      or "Visigoth" nor may "FreeMarker" or "Visigoth" appear in their
+      names without prior written permission of the Visigoth Software
+      Society.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+VISIGOTH SOFTWARE SOCIETY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file

Added: incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/NOTICE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/NOTICE?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/NOTICE (added)
+++ incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/NOTICE Mon Dec 17 03:39:32 2007
@@ -0,0 +1,8 @@
+Apache Sling FreeMarker Scripting Support
+Copyright 2007 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+
+This product includes software developed by
+the Visigoth Software Society (http://www.visigoths.org/).

Added: incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory (added)
+++ incubator/sling/trunk/scripting/freemarker/src/main/resources/META-INF/services/javax.script.ScriptEngineFactory Mon Dec 17 03:39:32 2007
@@ -0,0 +1 @@
+org.apache.sling.scripting.freemarker.FreemarkerScriptEngineFactory
\ No newline at end of file

Modified: incubator/sling/trunk/scripting/javascript/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/pom.xml?rev=604840&r1=604839&r2=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/pom.xml (original)
+++ incubator/sling/trunk/scripting/javascript/pom.xml Mon Dec 17 03:39:32 2007
@@ -1,21 +1,21 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <!--
-  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.
+    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.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -64,8 +64,15 @@
                 <configuration>
                     <instructions>
                         <Private-Package>
-                            org.apache.sling.scripting.javascript.*
+                            org.apache.sling.scripting.javascript.*,
+                            org.mozilla.classfile,
+                            !org.mozilla.javascript.tools.*,
+                            !org.mozilla.javascript.xml.impl.xmlbeans,
+                            org.mozilla.javascript.*
                         </Private-Package>
+                        
+                        <ScriptEngine-Name>${pom.name}</ScriptEngine-Name>
+                        <ScriptEngine-Version>${pom.version}</ScriptEngine-Version>
                     </instructions>
                 </configuration>
             </plugin>
@@ -79,6 +86,11 @@
             <version>2.0.0-incubator-SNAPSHOT</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.scripting.api</artifactId>
+            <version>2.0.0-incubator-SNAPSHOT</version>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
@@ -86,16 +98,16 @@
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
         </dependency>
-	    <dependency>
-	        <groupId>rhino</groupId>
-	        <artifactId>js</artifactId>
-  	        <version>1.6R7</version>
-	    </dependency>
+        <dependency>
+            <groupId>rhino</groupId>
+            <artifactId>js</artifactId>
+            <version>1.6R6</version>
+        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-    <!-- Testing -->
+        <!-- Testing -->
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>

Copied: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngine.java (from r603540, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavasSriptEngine.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngine.java?p2=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngine.java&p1=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavasSriptEngine.java&r1=603540&r2=604840&rev=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavasSriptEngine.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngine.java Mon Dec 17 03:39:32 2007
@@ -16,73 +16,72 @@
  */
 package org.apache.sling.scripting.javascript;
 
-import java.io.IOException;
 import java.io.Reader;
-import java.util.Map;
 import java.util.Map.Entry;
 
-import org.apache.sling.api.SlingException;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.scripting.SlingScript;
-import org.apache.sling.api.scripting.SlingScriptEngine;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
+import org.apache.sling.scripting.javascript.helper.EspReader;
+import org.apache.sling.scripting.javascript.helper.SlingWrapFactory;
 import org.mozilla.javascript.Context;
+import org.mozilla.javascript.NativeObject;
+import org.mozilla.javascript.ScriptRuntime;
+import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
 
 /**
  * A ScriptEngine that uses the Rhino interpreter to process Sling requests with
  * server-side javascript.
- *
- * @scr.component
- * @scr.property name="service.vendor" value="The Apache Software Foundation"
- * @scr.property name="service.description" value="Sling JavaScript Script Engine"
- * @scr.service interface="org.apache.sling.api.scripting.SlingScriptEngine"
  */
-public class RhinoJavasSriptEngine implements SlingScriptEngine {
+public class RhinoJavaScriptEngine extends AbstractSlingScriptEngine {
 
-    public final static String JS_SCRIPT_EXTENSION = "js";
-
-    public final static String ESP_SCRIPT_EXTENSION = "esp";
-
-    private String engineName;
-
-    {
-        Context cx = Context.enter();
-        engineName = "ECMAScript Engine (" + cx.getImplementationVersion() + ")";
-        Context.exit();
-    }
-
-    public String[] getExtensions() {
-        return new String[] { JS_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION };
-    }
-
-    public String getEngineName() {
-        return engineName;
+    private Scriptable rootScope;
+    
+    public RhinoJavaScriptEngine(ScriptEngineFactory factory, Scriptable rootScope) {
+        super(factory);
+        this.rootScope = rootScope;
     }
 
-    public String getEngineVersion() {
-        return "0.9";
-    }
-
-    public void eval(SlingScript script, Map<String, Object> props)
-            throws SlingException, IOException {
+    public Object eval(Reader scriptReader, ScriptContext scriptContext)
+            throws ScriptException {
+        Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
 
-        String scriptName = script.getScriptResource().getURI();
+        SlingScriptHelper helper = (SlingScriptHelper) bindings.get(SlingBindings.SLING);
+        String scriptName = helper.getScript().getScriptResource().getURI();
 
         // wrap the reader in an EspReader for ESP scripts
-        Reader scriptReader = script.getScriptReader();
-        if (scriptName.endsWith(ESP_SCRIPT_EXTENSION)) {
+        if (scriptName.endsWith(RhinoJavaScriptEngineFactory.ESP_SCRIPT_EXTENSION)) {
             scriptReader = new EspReader(scriptReader);
         }
 
         // create a rhino Context and execute the script
         try {
             final Context rhinoContext = Context.enter();
-            final ScriptableObject scope = rhinoContext.initStandardObjects();
+            final ScriptableObject scope = new NativeObject();
+            
+            // Set the global scope to be our prototype
+            scope.setPrototype(rootScope);
+
+            // We want "scope" to be a new top-level scope, so set its parent
+            // scope to null. This means that any variables created by assignments
+            // will be properties of "scope".
+            scope.setParentScope(null);
+
+            // setup the context for use
+            rhinoContext.setWrapFactory(SlingWrapFactory.INSTANCE);
 
             // add initial properties to the scope
-            for (Entry<String, Object> entry : props.entrySet()) {
-                Object wrapped = wrap(scope, entry.getValue(), rhinoContext);
-                ScriptableObject.putProperty(scope, entry.getKey(), wrapped);
+            for (Object entryObject : bindings.entrySet()) {
+                Entry<?, ?> entry = (Entry<?, ?>) entryObject;
+                Object wrapped = ScriptRuntime.toObject(scope, entry.getValue());
+                ScriptableObject.putProperty(scope, (String) entry.getKey(),
+                    wrapped);
             }
 
             final int lineNumber = 1;
@@ -90,35 +89,13 @@
 
             rhinoContext.evaluateReader(scope, scriptReader, scriptName,
                 lineNumber, securityDomain);
-
-        } catch (IOException ioe) {
-            throw ioe;
         } catch (Throwable t) {
-            throw new SlingException("Failure running script " + scriptName, t);
+            throw new ScriptException("Failure running script " + scriptName
+                + ": " + t.getMessage());
         } finally {
             Context.exit();
         }
+        return null;
     }
 
-    /**
-     * Wraps Java objects in Rhino host objects.
-     *
-     * @param scope the current scope
-     * @param entry the object to wrap
-     * @param context the current context, if needed for class definitions
-     * @return a rhino hostobject
-     */
-    protected Object wrap(final ScriptableObject scope, Object entry,
-            Context context) {
-        // wrap the resource to make it friendlier for javascript
-        if (entry instanceof Resource) {
-            try {
-                ScriptableObject.defineClass(scope, ScriptableResource.class);
-                return context.newObject(scope, "Resource",  new Object[] { entry });
-            } catch (Exception e) {
-                return Context.javaToJS(entry, scope);
-            }
-        }
-        return Context.javaToJS(entry, scope);
-    }
 }

Added: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java (added)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/RhinoJavaScriptEngineFactory.java Mon Dec 17 03:39:32 2007
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.sling.scripting.javascript;
+
+import javax.script.ScriptEngine;
+
+import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
+import org.apache.sling.scripting.javascript.helper.SlingWrapFactory;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableNode;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableResource;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+
+/**
+ * The <code>RhinoJavaScriptEngineFactory</code> TODO
+ */
+public class RhinoJavaScriptEngineFactory extends AbstractScriptEngineFactory {
+
+    public final static String JS_SCRIPT_EXTENSION = "js";
+
+    public final static String ESP_SCRIPT_EXTENSION = "esp";
+
+    private final String languageVersion;
+    
+    private Scriptable rootScope;
+
+    public RhinoJavaScriptEngineFactory() {
+        Context cx = Context.enter();
+        setEngineName(getEngineName() + " (" + cx.getImplementationVersion()
+            + ")");
+        languageVersion = String.valueOf(cx.getLanguageVersion());
+        Context.exit();
+
+        setExtensions(JS_SCRIPT_EXTENSION, ESP_SCRIPT_EXTENSION);
+        setMimeTypes("text/javascript", "application/ecmascript",
+            "application/javascript");
+        setNames("ecma", "javascript", JS_SCRIPT_EXTENSION,
+            ESP_SCRIPT_EXTENSION);
+    }
+
+    public ScriptEngine getScriptEngine() {
+        return new RhinoJavaScriptEngine(this, getRootScope());
+    }
+
+    public String getLanguageName() {
+        return "ECMAScript";
+    }
+
+    public String getLanguageVersion() {
+        return languageVersion;
+    }
+
+    private Scriptable getRootScope() {
+        if (rootScope == null) {
+            final Context rhinoContext = Context.enter();
+            rootScope = rhinoContext.initStandardObjects();
+            
+            try {
+                ScriptableObject.defineClass(rootScope, ScriptableResource.class);
+                ScriptableObject.defineClass(rootScope, ScriptableNode.class);
+            } catch (Throwable t) {
+                // TODO: log
+            }
+        }
+        
+        return rootScope;
+    }
+}

Copied: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java (from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java?p2=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java&p1=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java&r1=603870&r2=604840&rev=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/EspReader.java Mon Dec 17 03:39:32 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.scripting.javascript;
+package org.apache.sling.scripting.javascript.helper;
 
 import java.io.FilterReader;
 import java.io.IOException;

Added: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java (added)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/helper/SlingWrapFactory.java Mon Dec 17 03:39:32 2007
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.sling.scripting.javascript.helper;
+
+import javax.jcr.Node;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableNode;
+import org.apache.sling.scripting.javascript.wrapper.ScriptableResource;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.WrapFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SlingWrapFactory extends WrapFactory {
+
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public static final WrapFactory INSTANCE = new SlingWrapFactory();
+
+    /**
+     * @param cx the current Context for this thread
+     * @param scope the scope of the executing script
+     * @param javaObject the object to be wrapped
+     * @param staticType type hint. If security restrictions prevent to wrap
+     *            object based on its class, staticType will be used instead.
+     * @return the wrapped value which shall not be null
+     */
+    @Override
+    public Scriptable wrapAsJavaObject(Context cx, Scriptable scope,
+            Object javaObject, Class staticType) {
+
+        try {
+            if (javaObject instanceof Resource) {
+                return cx.newObject(scope, ScriptableResource.CLASSNAME,
+                    new Object[] { javaObject });
+            } else if (javaObject instanceof Node) {
+                return cx.newObject(scope, ScriptableNode.CLASSNAME,
+                    new Object[] { javaObject });
+            }
+        } catch (Exception e) {
+            log.warn("Cannot Wrap " + javaObject, e);
+        }
+
+        return super.wrapAsJavaObject(cx, scope, javaObject, staticType);
+    }
+
+}

Copied: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java (from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableNode.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java?p2=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java&p1=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableNode.java&r1=603870&r2=604840&rev=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableNode.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableNode.java Mon Dec 17 03:39:32 2007
@@ -14,11 +14,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.scripting.javascript;
+package org.apache.sling.scripting.javascript.wrapper;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import javax.jcr.Node;
@@ -35,21 +36,33 @@
 import org.mozilla.javascript.ScriptRuntime;
 import org.mozilla.javascript.Scriptable;
 import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.Undefined;
 /**
  * A wrapper for JCR nodes that exposes all properties and child nodes
  * as properties of a Javascript object.
  */
 public class ScriptableNode extends ScriptableObject {
+    
+    public static final String CLASSNAME = "Node";
+    
 	private Node node;
 
+	public ScriptableNode() {
+	}
+
 	public ScriptableNode(Node item) {
 		super();
 		this.node = item;
 	}
 
+    public void jsConstructor(Object res) {
+        this.node = (Node) res;
+    }
+
 	public String getClassName() {
-		return "Node";
+		return CLASSNAME;
 	}
+	
 	/**
 	 * Gets the value of a (Javascript) property. If there is a single single-value
 	 * JCR property of this node, return its string value. If there are multiple properties
@@ -57,18 +70,21 @@
 	 */
 	@Override
 	public Object get(String name, Scriptable start) {
-		Set items = new HashSet();
+		List<Scriptable> items = new ArrayList<Scriptable>();
+		
+		// add all matching nodes
 		try {
-			Iterator it = node.getNodes(name);
+			NodeIterator it = node.getNodes(name);
 			while (it.hasNext()) {
-				items.add(new ScriptableNode((Node) it.next()));
+				items.add(new ScriptableNode(it.nextNode()));
 			}
 		} catch (RepositoryException e) {}
 
+		// add all matching properies
 		try {
-			Iterator it = node.getProperties(name);
+			PropertyIterator it = node.getProperties(name);
 			while (it.hasNext()) {
-				Property prop = (Property) it.next();
+				Property prop = it.nextProperty();
 				int type = prop.getType();
 				if (prop.getDefinition().isMultiple()) {
 					Value[] values = prop.getValues();
@@ -86,7 +102,7 @@
 		} catch (RepositoryException e) {}
 
 		if (items.size()==0) {
-			return null;
+			return Undefined.instance;
 		} else if (items.size()==1) {
 			return items.iterator().next();
 		} else {
@@ -96,20 +112,25 @@
 	        return result;
 		}
 	}
-	private Object wrap(Value value, int type) throws ValueFormatException, IllegalStateException, RepositoryException {
+	
+	private Scriptable wrap(Value value, int type) throws ValueFormatException, IllegalStateException, RepositoryException {
+	    Object valObj;
 		if (type==PropertyType.BINARY) {
-			return Context.toBoolean(value.getBoolean());
+			valObj = value.getBoolean();
 		} else if (type==PropertyType.DOUBLE) {
-			return Context.toNumber(value.getDouble());
+		    valObj = value.getDouble();
 		} else if (type==PropertyType.LONG) {
-			return Context.toNumber(value.getLong());
+		    valObj = value.getLong();
+		} else {
+		    valObj = value.getString();
 		}
-		return value.getString();
+		
+		return ScriptRuntime.toObject(this, valObj);
 	}
 
 	@Override
 	public Object[] getIds() {
-		Collection<String> ids = new HashSet<String>();
+		Collection<String> ids = new ArrayList<String>();
 		try {
 			PropertyIterator pit = node.getProperties();
 			while (pit.hasNext()) {

Copied: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java (from r603870, incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java?p2=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java&p1=incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java&r1=603870&r2=604840&rev=604840&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/ScriptableResource.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/wrapper/ScriptableResource.java Mon Dec 17 03:39:32 2007
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sling.scripting.javascript;
+package org.apache.sling.scripting.javascript.wrapper;
 
 import javax.jcr.Node;
 
@@ -29,10 +29,17 @@
  * [String] getURI(); [String] uri
  */
 public class ScriptableResource extends ScriptableObject {
+    
+    public static final String CLASSNAME = "Resource";
+    
     private Resource resource;
 
     public ScriptableResource() {
     }
+    
+    public ScriptableResource(Resource resource) {
+        this.resource = resource;
+    }
 
     public void jsConstructor(Object res) {
         this.resource = (Resource) res;
@@ -40,7 +47,7 @@
 
     @Override
     public String getClassName() {
-        return "Resource";
+        return CLASSNAME;
     }
 
     public Object jsFunction_getObject() {
@@ -50,10 +57,7 @@
 
     public Object jsFunction_getNode() {
         Node node = resource.adaptTo(Node.class);
-        if (node != null) {
-            return new ScriptableNode(node);
-        }
-        return Undefined.instance;
+        return node != null ? node : Undefined.instance;
     }
 
     /** alias for getNode */

Added: incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE?rev=604840&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE (added)
+++ incubator/sling/trunk/scripting/javascript/src/main/resources/META-INF/LICENSE Mon Dec 17 03:39:32 2007
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.