This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.scripting.java-1.0.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-java.git

commit beb532d941f087ad30e1d86f8851ed118581ecf5
Author: Carsten Ziegeler <cziege...@apache.org>
AuthorDate: Fri Jul 17 06:18:00 2009 +0000

    Use new class loader writer.
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/java@794979 
13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            |   5 -
 .../sling/scripting/java/CompilationContext.java   |   4 +-
 .../scripting/java/JavaScriptEngineFactory.java    |   8 +-
 .../org/apache/sling/scripting/java/Options.java   |   8 +-
 .../sling/scripting/java/ServletWrapper.java       |   2 +-
 .../sling/scripting/java/SlingIOProvider.java      | 193 ++-------------------
 .../OSGI-INF/metatype/metatype.properties          |   5 -
 7 files changed, 24 insertions(+), 201 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4b5008a..744f786 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,11 +100,6 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.api</artifactId>
-            <version>2.0.2-incubator</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.commons.classloader</artifactId>
             <version>0.9.0-SNAPSHOT</version>
         </dependency>
diff --git 
a/src/main/java/org/apache/sling/scripting/java/CompilationContext.java 
b/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
index 2de7af7..89af03d 100644
--- a/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
+++ b/src/main/java/org/apache/sling/scripting/java/CompilationContext.java
@@ -55,7 +55,7 @@ public class CompilationContext {
     private long lastModificationTest = 0L;
     private int removed = 0;
 
-    private Class servletClass;
+    private Class<?> servletClass;
 
     private final ServletWrapper wrapper;
 
@@ -194,7 +194,7 @@ public class CompilationContext {
     /**
      * Load the class.
      */
-    public Class load()
+    public Class<?> load()
     throws ServletException, FileNotFoundException {
         final String name = this.getClassFilePath().substring(1).replace('/', 
'.');
         try {
diff --git 
a/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java 
b/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
index 0425c08..c0f6e38 100644
--- a/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/scripting/java/JavaScriptEngineFactory.java
@@ -33,6 +33,7 @@ import org.apache.sling.api.SlingServletException;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
 import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
 import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
@@ -52,7 +53,6 @@ import org.slf4j.LoggerFactory;
  * @scr.property name="java.compilerSourceVM" value="1.5"
  * @scr.property name="java.compilerTargetVM" value="1.5"
  * @scr.property name="java.development" value="true"
- * @scr.property name="java.outputPath" value="/var/classes"
  * @scr.property name="java.modificationTestInterval" value="-1"
  * @scr.property name="java.classdebuginfo" value="true"
  */
@@ -74,6 +74,9 @@ public class JavaScriptEngineFactory extends 
AbstractScriptEngineFactory {
     /** @scr.reference */
     private ServletContext slingServletContext;
 
+    /** @scr.reference */
+    private ClassLoaderWriter classLoaderWriter;
+
     private SlingIOProvider ioProvider;
 
     private JavaServletContext javaServletContext;
@@ -120,7 +123,7 @@ public class JavaScriptEngineFactory extends 
AbstractScriptEngineFactory {
      * @param componentContext
      */
     protected void activate(ComponentContext componentContext) {
-        this.ioProvider = new SlingIOProvider();
+        this.ioProvider = new SlingIOProvider(this.classLoaderWriter);
         this.servletCache = new ServletCache();
 
         this.javaServletContext = new JavaServletContext(ioProvider,
@@ -157,6 +160,7 @@ public class JavaScriptEngineFactory extends 
AbstractScriptEngineFactory {
      * @throws SlingServletException
      * @throws SlingIOException
      */
+    @SuppressWarnings("unchecked")
     private void callServlet(Bindings bindings, SlingScriptHelper 
scriptHelper) {
 
         
ioProvider.setRequestResourceResolver(scriptHelper.getScript().getScriptResource().getResourceResolver());
diff --git a/src/main/java/org/apache/sling/scripting/java/Options.java 
b/src/main/java/org/apache/sling/scripting/java/Options.java
index bc445ac..375c348 100644
--- a/src/main/java/org/apache/sling/scripting/java/Options.java
+++ b/src/main/java/org/apache/sling/scripting/java/Options.java
@@ -36,8 +36,6 @@ public class Options {
 
     private static final String PROPERTY_DEVELOPMENT = "development";
 
-    private static final String PROPERTY_OUTPUT_PATH = "outputPath";
-
     private static final String PROPERTY_MODIFICATION_TEST_INTERVAL = 
"modificationTestInterval";
 
     private static final String PROPERTY_CLASSDEBUGINFO = "classdebuginfo";
@@ -80,8 +78,6 @@ public class Options {
      */
     private final ClassLoader classLoader;
 
-    private final String destinationDir;
-
     /**
      * Create an compiler options object using data available from
      * the component configuration.
@@ -100,7 +96,6 @@ public class Options {
         properties.put(PROPERTY_COMPILER_TARGET_V_M, DEFAULT_VM_VERSION);
         properties.put(PROPERTY_COMPILER_SOURCE_V_M, DEFAULT_VM_VERSION);
         properties.put(PROPERTY_JAVA_ENCODING, "UTF-8");
-        properties.put(PROPERTY_OUTPUT_PATH, "/var/classes");
 
         // now check component properties
         Dictionary<?, ?> config = componentContext.getProperties();
@@ -116,7 +111,6 @@ public class Options {
             }
         }
 
-        this.destinationDir = properties.get(PROPERTY_OUTPUT_PATH).toString();
         this.classDebugInfo = 
Boolean.valueOf(properties.get(PROPERTY_CLASSDEBUGINFO).toString());
         this.modificationTestInterval = 
Integer.valueOf(properties.get(PROPERTY_MODIFICATION_TEST_INTERVAL).toString());
         this.development = 
Boolean.valueOf(properties.get(PROPERTY_DEVELOPMENT).toString());
@@ -129,7 +123,7 @@ public class Options {
      * Return the destination directory.
      */
     public String getDestinationPath() {
-        return this.destinationDir;
+        return ":";
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java 
b/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
index 9d0a59d..4d948f5 100644
--- a/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
+++ b/src/main/java/org/apache/sling/scripting/java/ServletWrapper.java
@@ -102,7 +102,7 @@ public class ServletWrapper {
                     Servlet servlet = null;
 
                     try {
-                        final Class servletClass = ctxt.load();
+                        final Class<?> servletClass = ctxt.load();
                         servlet = (Servlet) servletClass.newInstance();
                     } catch (IllegalAccessException e) {
                         throw new ServletException(e);
diff --git a/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java 
b/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
index 34908ab..4e07e44 100644
--- a/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
+++ b/src/main/java/org/apache/sling/scripting/java/SlingIOProvider.java
@@ -16,8 +16,6 @@
  */
 package org.apache.sling.scripting.java;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -27,32 +25,30 @@ import java.net.URL;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
-import java.util.StringTokenizer;
-
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * The <code>SlingIOProvider</code> TODO
+ * The <code>SlingIOProvider</code>
  */
 public class SlingIOProvider  {
 
     /** default log */
-    private static final Logger log = 
LoggerFactory.getLogger(SlingIOProvider.class);
+    private final Logger log = LoggerFactory.getLogger(SlingIOProvider.class);
 
     private ThreadLocal<ResourceResolver> requestResourceResolver;
 
-    SlingIOProvider() {
+    private final ClassLoaderWriter classLoaderWriter;
+
+    SlingIOProvider(final ClassLoaderWriter classLoaderWriter) {
         this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
+        this.classLoaderWriter = classLoaderWriter;
     }
 
     void setRequestResourceResolver(ResourceResolver resolver) {
@@ -72,7 +68,9 @@ public class SlingIOProvider  {
      */
     public InputStream getInputStream(String fileName)
     throws FileNotFoundException, IOException {
-
+        if ( fileName.startsWith(":") ) {
+            return 
this.classLoaderWriter.getInputStream(fileName.substring(1));
+        }
         try {
 
             Resource resource = getResourceInternal(fileName);
@@ -100,6 +98,9 @@ public class SlingIOProvider  {
      * returned.
      */
     public long lastModified(String fileName) {
+        if ( fileName.startsWith(":") ) {
+            return 
this.classLoaderWriter.getLastModified(fileName.substring(1));
+        }
         try {
             Resource resource = getResourceInternal(fileName);
             if (resource != null) {
@@ -117,36 +118,10 @@ public class SlingIOProvider  {
     }
 
     /**
-     * Removes the named item from the repository.
-     */
-    public boolean delete(String fileName) {
-        Node parentNode = null;
-        try {
-            fileName = cleanPath(fileName);
-            Session session = getPrivateSession();
-            if (session.itemExists(fileName)) {
-                Item fileItem = session.getItem(fileName);
-                parentNode = fileItem.getParent();
-                fileItem.remove();
-                parentNode.save();
-                return true;
-            }
-        } catch (RepositoryException re) {
-            log.error("Cannot remove " + fileName, re);
-        } finally {
-            checkNode(parentNode, fileName);
-        }
-
-        // fall back to false if item does not exist or in case of error
-        return false;
-    }
-
-    /**
      * Returns an output stream to write to the repository.
      */
     public OutputStream getOutputStream(String fileName) {
-        fileName = cleanPath(fileName);
-        return new RepositoryOutputStream(this, fileName);
+        return this.classLoaderWriter.getOutputStream(fileName.substring(1));
     }
 
     /* package */URL getURL(String path) throws MalformedURLException {
@@ -192,21 +167,6 @@ public class SlingIOProvider  {
 
     // ---------- internal 
-----------------------------------------------------
 
-    private Session getPrivateSession() throws RepositoryException {
-        return requestResourceResolver.get().adaptTo(Session.class);
-    }
-
-    private static void checkNode(Node node, String path) {
-        if (node != null && node.isModified()) {
-            try {
-                node.refresh(false);
-            } catch (RepositoryException re) {
-                log.error("Cannot refresh node for " + path
-                    + " after failed save", re);
-            }
-        }
-    }
-
     private String cleanPath(String path) {
         // replace backslash by slash
         path = path.replace('\\', '/');
@@ -218,129 +178,4 @@ public class SlingIOProvider  {
 
         return path;
     }
-
-    private static class RepositoryOutputStream extends ByteArrayOutputStream {
-
-        private final SlingIOProvider repositoryOutputProvider;
-
-        private final String fileName;
-
-        RepositoryOutputStream(SlingIOProvider repositoryOutputProvider,
-                String fileName) {
-            this.repositoryOutputProvider = repositoryOutputProvider;
-            this.fileName = fileName;
-        }
-
-        public void close() throws IOException {
-            super.close();
-
-            Node parentNode = null;
-            try {
-                Session session = repositoryOutputProvider.getPrivateSession();
-                Node fileNode = null;
-                Node contentNode = null;
-                if (session.itemExists(fileName)) {
-                    Item item = session.getItem(fileName);
-                    if (item.isNode()) {
-                        Node node = item.isNode()
-                                ? (Node) item
-                                : item.getParent();
-                        if ("jcr:content".equals(node.getName())) {
-                            // replace the content properties of the 
jcr:content
-                            // node
-                            parentNode = node;
-                            contentNode = node;
-                        } else if (node.isNodeType("nt:file")) {
-                            // try to set the content properties of jcr:content
-                            // node
-                            parentNode = node;
-                            contentNode = node.getNode("jcr:content");
-                        } else { // fileName is a node
-                            // try to set the content properties of the node
-                            parentNode = node;
-                            contentNode = node;
-                        }
-                    } else {
-                        // replace property with an nt:file node (if possible)
-                        parentNode = item.getParent();
-                        String name = item.getName();
-                        fileNode = parentNode.addNode(name, "nt:file");
-                        item.remove();
-                    }
-                } else {
-                    fileNode = createPath(fileName, "nt:folder", "nt:file", 
session);
-                    parentNode = session.getRootNode();
-                }
-
-                // if we have a file node, create the contentNode
-                if (fileNode != null) {
-                    contentNode = fileNode.addNode("jcr:content", 
"nt:resource");
-                }
-
-                contentNode.setProperty("jcr:lastModified",
-                    System.currentTimeMillis());
-                contentNode.setProperty("jcr:data", new ByteArrayInputStream(
-                    buf, 0, size()));
-                contentNode.setProperty("jcr:mimeType",
-                    "application/octet-stream");
-
-                parentNode.save();
-            } catch (RepositoryException re) {
-                log.error("Cannot write file " + fileName, re);
-                throw new IOException("Cannot write file " + fileName
-                    + ", reason: " + re.toString());
-            } finally {
-                checkNode(parentNode, fileName);
-            }
-        }
-    }
-
-    /**
-     * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
-     * In case it has to create the Node all non-existent intermediate 
path-elements
-     * will be create with the given intermediate node type and the returned 
node
-     * will be created with the given nodeType
-     *
-     * @param path to create
-     * @param intermediateNodeType to use for creation of intermediate nodes
-     * @param nodeType to use for creation of the final node
-     * @param session to use
-     * @return the Node at path
-     * @throws RepositoryException in case of exception accessing the 
Repository
-     */
-    private static Node createPath(String path,
-                                  String intermediateNodeType,
-                                  String nodeType,
-                                  Session session)
-            throws RepositoryException {
-        if (path == null || path.length() == 0 || "/".equals(path)) {
-            return session.getRootNode();
-        } else if (!session.itemExists(path)) {
-            Node node = session.getRootNode();
-            path = path.substring(1);
-            int pos = path.lastIndexOf('/');
-            if ( pos != -1 ) {
-                final StringTokenizer st = new 
StringTokenizer(path.substring(0, pos), "/");
-                while ( st.hasMoreTokens() ) {
-                    final String token = st.nextToken();
-                    if ( !node.hasNode(token) ) {
-                        try {
-                            node.addNode(token, intermediateNodeType);
-                        } catch (RepositoryException re) {
-                            // we ignore this as this folder might be created 
from a different task
-                            node.refresh(false);
-                        }
-                    }
-                    node = node.getNode(token);
-                }
-                path = path.substring(pos + 1);
-            }
-            if ( !node.hasNode(path) ) {
-                node.addNode(path, nodeType);
-            }
-            return node.getNode(path);
-        } else {
-            return (Node) session.getItem(path);
-        }
-    }
 }
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties 
b/src/main/resources/OSGI-INF/metatype/metatype.properties
index 666d78f..c6e2467 100644
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ b/src/main/resources/OSGI-INF/metatype/metatype.properties
@@ -51,8 +51,3 @@ java.compilerSourceVM.description = Java Specification to be 
used to read \
 java.compilerTargetVM.name = Target VM
 java.compilerTargetVM.description = Java Specification to be used to generate \
  the compiled output.
-
-java.outputPath.name = Compilation Location
-java.outputPath.description = What directory should we use when \
- compiling Java files? Default is /var/classes.
- 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Reply via email to