Author: fmeschbe
Date: Mon Dec 17 03:37:09 2007
New Revision: 604837
URL: http://svn.apache.org/viewvc?rev=604837&view=rev
Log:
SLING-110 Add Java Script API with Sling extensions
Added:
incubator/sling/trunk/scripting/api/ (with props)
incubator/sling/trunk/scripting/api/pom.xml (with props)
incubator/sling/trunk/scripting/api/src/
incubator/sling/trunk/scripting/api/src/main/
incubator/sling/trunk/scripting/api/src/main/java/
incubator/sling/trunk/scripting/api/src/main/java/org/
incubator/sling/trunk/scripting/api/src/main/java/org/apache/
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java
(with props)
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java
(with props)
incubator/sling/trunk/scripting/api/src/main/java/sun/
incubator/sling/trunk/scripting/api/src/main/java/sun/misc/
incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java
(with props)
Propchange: incubator/sling/trunk/scripting/api/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Dec 17 03:37:09 2007
@@ -0,0 +1,3 @@
+.classpath
+.project
+target
Added: incubator/sling/trunk/scripting/api/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/api/pom.xml?rev=604837&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/api/pom.xml (added)
+++ incubator/sling/trunk/scripting/api/pom.xml Mon Dec 17 03:37:09 2007
@@ -0,0 +1,111 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>1-incubator-SNAPSHOT</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.scripting.api</artifactId>
+ <version>2.0.0-incubator-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Sling - Scripting Implementation API</name>
+ <description>
+ This bundle provides the internal API to implement scripting. As such
+ it bundles the Java Scripting API provided by Apache BSF.
+ </description>
+
+ <scm>
+ <connection>
+
scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/api
+ </connection>
+ <developerConnection>
+
scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/scripting/api
+ </developerConnection>
+ <url>
+ http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/api
+ </url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Export-Package>
+
org.apache.sling.scripting.api;version=${pom.version},
+ javax.script
+ </Export-Package>
+ <Private-Package>
+ sun.misc
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.bsf</groupId>
+ <artifactId>bsf-api</artifactId>
+ <version>3.0-beta2</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_compendium</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+
+ </dependencies>
+</project>
Propchange: incubator/sling/trunk/scripting/api/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java?rev=604837&view=auto
==============================================================================
---
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java
(added)
+++
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java
Mon Dec 17 03:37:09 2007
@@ -0,0 +1,153 @@
+/*
+ * 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.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineFactory;
+
+public abstract class AbstractScriptEngineFactory implements
+ ScriptEngineFactory {
+
+ private String engineName;
+ private String engineVersion;
+ private List<String> extensions;
+ private List<String> mimeTypes;
+ private List<String> names;
+
+ protected AbstractScriptEngineFactory() {
+ String name = null;
+ String version = null;
+
+ // try to get the manifest
+ Manifest manifest = null;
+ InputStream ins = null;
+ try {
+ ins = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
+ if (ins != null) {
+ manifest = new Manifest(ins);
+ Attributes attrs = manifest.getMainAttributes();
+ name = attrs.getValue("ScriptEngine-Name");
+ version = attrs.getValue("ScriptEngine-Version");
+ }
+ } catch (IOException ioe) {
+ // might want to log ?
+ } finally {
+ if (ins != null) {
+ try {
+ ins.close();
+ } catch (IOException ignore) {
+ }
+ }
+ }
+
+ // fall back to class name and version zero
+ if (name == null) {
+ String className = getClass().getName();
+ name = className.substring(className.lastIndexOf('.') + 1);
+ }
+ if (version == null) {
+ version = "0";
+ }
+
+ setEngineName(name);
+ setEngineVersion(version);
+ }
+
+ public String getEngineName() {
+ return engineName;
+ }
+
+ protected void setEngineName(String engineName) {
+ this.engineName = engineName;
+ }
+
+ public String getEngineVersion() {
+ return engineVersion;
+ }
+
+ protected void setEngineVersion(String engineVersion) {
+ this.engineVersion = engineVersion;
+ }
+
+ public List<String> getExtensions() {
+ return extensions;
+ }
+
+ protected void setExtensions(String... extensions) {
+ this.extensions = Arrays.asList(extensions);
+ }
+
+ public List<String> getMimeTypes() {
+ return mimeTypes;
+ }
+
+ protected void setMimeTypes(String... mimeTypes) {
+ this.mimeTypes = Arrays.asList(mimeTypes);
+ }
+
+ public List<String> getNames() {
+ return names;
+ }
+
+ protected void setNames(String... names) {
+ this.names = Arrays.asList(names);
+ }
+
+ public String getMethodCallSyntax(String obj, String m, String[] args) {
+ StringBuffer callSyntax = new StringBuffer();
+ callSyntax.append(obj).append('.').append(m).append('(');
+ for (int i = 0; args != null && i < args.length; i++) {
+ if (i > 0) callSyntax.append(',');
+ callSyntax.append(args[i]);
+ }
+ callSyntax.append(')');
+ return callSyntax.toString();
+ }
+
+ public String getOutputStatement(String value) {
+ return "out.print(" + value + ")";
+ }
+
+ public Object getParameter(String name) {
+ if (ScriptEngine.ENGINE.equals(name)) {
+ return getEngineName();
+ } else if (ScriptEngine.ENGINE_VERSION.equals(name)) {
+ return getEngineVersion();
+ } else if (ScriptEngine.NAME.equals(name)) {
+ return getNames();
+ } else if (ScriptEngine.LANGUAGE.equals(name)) {
+ return getLanguageName();
+ } else if (ScriptEngine.LANGUAGE_VERSION.equals(name)) {
+ return getLanguageVersion();
+ }
+ return null;
+ }
+
+ public String getProgram(String[] arg0) {
+ return null;
+ }
+
+}
Propchange:
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractScriptEngineFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java?rev=604837&view=auto
==============================================================================
---
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java
(added)
+++
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java
Mon Dec 17 03:37:09 2007
@@ -0,0 +1,48 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.scripting.api;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.script.AbstractScriptEngine;
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngineFactory;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+
+public abstract class AbstractSlingScriptEngine extends AbstractScriptEngine {
+
+ private final ScriptEngineFactory scriptEngineFactory;
+
+ protected AbstractSlingScriptEngine(ScriptEngineFactory
scriptEngineFactory) {
+ this.scriptEngineFactory = scriptEngineFactory;
+ }
+
+ public Bindings createBindings() {
+ return new SimpleBindings();
+ }
+
+ public Object eval(String script, ScriptContext context) throws
ScriptException {
+ StringReader reader = new StringReader(script);
+ return eval(reader, context);
+ }
+
+ public ScriptEngineFactory getFactory() {
+ return scriptEngineFactory;
+ }
+
+}
Propchange:
incubator/sling/trunk/scripting/api/src/main/java/org/apache/sling/scripting/api/AbstractSlingScriptEngine.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java?rev=604837&view=auto
==============================================================================
--- incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java
(added)
+++ incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java Mon
Dec 17 03:37:09 2007
@@ -0,0 +1,44 @@
+/*
+ * 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 sun.misc;
+
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * The <code>Service</code> class is a primitive stub of the original
+ * <code>sun.misc.Service</code> class used by the
+ * <code>javax.script.ScriptEngineManager</code> to find script engine
+ * factories in factory service files.
+ * <p>
+ * This stub is provided because the original class is not part of the official
+ * Java API and may not be available on all platforms. In addition even if the
+ * class would be available on the Java platform, it may not be visible inside
+ * the OSGi framework. Finally, the
<em>org.apache.sling.scripting.resolver</em>
+ * bundle implements its own resolution of script engine factories and thus the
+ * <code>Service</code> method is not used.
+ */
+public class Service {
+
+ /** Returns an empty iterator */
+ public static Iterator<String> providers(Class<?> type, ClassLoader
loader) {
+ return Collections.<String> emptyList().iterator();
+ }
+
+}
Propchange:
incubator/sling/trunk/scripting/api/src/main/java/sun/misc/Service.java
------------------------------------------------------------------------------
svn:eol-style = native