incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r794543 - in /sling/trunk/bundles/scripting/jsp: ./ src/main/java/org/apache/sling/scripting/jsp/
Date Thu, 16 Jul 2009 05:57:41 GMT
Author: cziegeler
Date: Thu Jul 16 05:57:40 2009
New Revision: 794543

URL: http://svn.apache.org/viewvc?rev=794543&view=rev
Log:
SLING-1049 : Use new commons dynamic class loader instead of using dynamic import package
*.

Modified:
    sling/trunk/bundles/scripting/jsp/pom.xml
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
    sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java

Modified: sling/trunk/bundles/scripting/jsp/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/pom.xml?rev=794543&r1=794542&r2=794543&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp/pom.xml Thu Jul 16 05:57:40 2009
@@ -65,7 +65,6 @@
                             org.apache.sling.scripting.jsp.jasper.*,
                             org.apache.juli.logging
                         </Private-Package>
-                        <DynamicImport-Package>*</DynamicImport-Package>
 
                         <Import-Package>
                             !org.eclipse.*, *
@@ -117,8 +116,8 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.classloader</artifactId>
-            <version>2.0.2-incubator</version>
+            <artifactId>org.apache.sling.commons.classloader</artifactId>
+            <version>0.9.0-SNAPSHOT</version>
         </dependency>
 
         <dependency>

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=794543&r1=794542&r2=794543&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Thu Jul 16 05:57:40 2009
@@ -20,7 +20,6 @@
 
 import java.io.Reader;
 
-import javax.jcr.RepositoryException;
 import javax.script.Bindings;
 import javax.script.ScriptContext;
 import javax.script.ScriptEngine;
@@ -35,8 +34,8 @@
 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.DynamicClassLoaderManager;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider;
 import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
 import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
 import org.apache.sling.scripting.jsp.jasper.JasperException;
@@ -83,10 +82,6 @@
     /** @scr.reference */
     private ServletContext slingServletContext;
 
-    /**
-     * @scr.reference name="RepositoryClassLoaderProvider"
-     *                interface="org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider"
-     */
     private ClassLoader jspClassLoader;
 
     private SlingIOProvider ioProvider;
@@ -101,12 +96,11 @@
 
     private ServletConfig servletConfig;
 
-    private RepositoryClassLoaderProvider repoCLProvider;
+    /** @scr.reference */
+    private DynamicClassLoaderManager dynamicClassLoaderManager;
 
     public static final String[] SCRIPT_TYPE = { "jsp", "jspf", "jspx" };
 
-    private static final String CLASSLOADER_NAME = "admin";
-
     public JspScriptEngineFactory() {
         setExtensions(SCRIPT_TYPE);
     }
@@ -131,7 +125,7 @@
     @SuppressWarnings("unchecked")
     private void callJsp(Bindings bindings, SlingScriptHelper scriptHelper) {
 
-        ioProvider.setRequestResourceResolver(scriptHelper.getRequest().getResourceResolver());
+        ioProvider.setRequestResourceResolver(scriptHelper.getScript().getScriptResource().getResourceResolver());
         try {
             JspServletWrapperAdapter jsp = getJspWrapperAdapter(scriptHelper);
             // create a SlingBindings object
@@ -191,7 +185,7 @@
             // prepare some classes
             prepareJasperClasses();
 
-            ioProvider = new SlingIOProvider(repository, slingServletContext);
+            ioProvider = new SlingIOProvider(slingServletContext);
 
             tldLocationsCache = new SlingTldLocationsCache(slingServletContext,
                 componentContext.getBundleContext());
@@ -268,7 +262,7 @@
      * Bind the class load provider.
      * @param repositoryClassLoaderProvider the new provider
      */
-    protected void bindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp)
{
+    protected void bindDynamicClassLoaderManager(final DynamicClassLoaderManager rclp) {
         if ( this.jspClassLoader != null ) {
             this.ungetClassLoader();
         }
@@ -279,8 +273,8 @@
      * Unbind the class loader provider.
      * @param repositoryClassLoaderProvider the old provider
      */
-    protected void unbindRepositoryClassLoaderProvider(RepositoryClassLoaderProvider rclp)
{
-        if ( this.repoCLProvider == rclp ) {
+    protected void unbindDynamicClassLoaderManager(final DynamicClassLoaderManager rclp)
{
+        if ( this.dynamicClassLoaderManager == rclp ) {
             this.ungetClassLoader();
         }
     }
@@ -288,26 +282,17 @@
     /**
      * Get the class loader
      */
-    private void getClassLoader(RepositoryClassLoaderProvider rclp) {
-        try {
-            this.repoCLProvider = rclp;
-            this.jspClassLoader = rclp.getClassLoader(CLASSLOADER_NAME);
-        } catch (RepositoryException re) {
-            log.error("Cannot get JSP class loader", re);
-        }
+    private void getClassLoader(final DynamicClassLoaderManager rclp) {
+        this.dynamicClassLoaderManager = rclp;
+        this.jspClassLoader = rclp.getDynamicClassLoader();
     }
 
     /**
      * Unget the class loader
      */
     private void ungetClassLoader() {
-        if ( this.repoCLProvider != null ) {
-            if ( this.jspClassLoader != null ) {
-                this.repoCLProvider.ungetClassLoader(this.jspClassLoader);
-                this.jspClassLoader = null;
-            }
-            this.repoCLProvider = null;
-        }
+        this.jspClassLoader = null;
+        this.dynamicClassLoaderManager = null;
     }
 
     private void prepareJasperClasses() {

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java?rev=794543&r1=794542&r2=794543&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
Thu Jul 16 05:57:40 2009
@@ -609,7 +609,7 @@
 
         String dir = getProperty("scratchdir");
         this.scratchDir = (dir != null) ? dir : "/var/classes";
-        ioProvider.mkdirs(this.scratchDir);
+        //ioProvider.mkdirs(this.scratchDir);
 
         String compilerTargetVM = getProperty("compilerTargetVM");
         if (compilerTargetVM != null) {

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=794543&r1=794542&r2=794543&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
Thu Jul 16 05:57:40 2009
@@ -38,7 +38,6 @@
 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.jcr.api.SlingRepository;
 import org.apache.sling.scripting.jsp.jasper.IOProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,20 +50,20 @@
     /** default log */
     private static final Logger log = LoggerFactory.getLogger(SlingIOProvider.class);
 
-    private final SlingRepository repository;
+    //private final SlingRepository repository;
 
     private final ThreadLocal<ResourceResolver> requestResourceResolver;
 
     // private session for write access
-    private final ThreadLocal<Session> privateSession;
-    
+    //private final ThreadLocal<Session> privateSession;
+
     // used to find out about the mime type for created files
     private final ServletContext servletContext;
 
-    SlingIOProvider(SlingRepository repository, ServletContext servletContext) {
-        this.repository = repository;
+    SlingIOProvider(ServletContext servletContext) {
+        //this.repository = repository;
         this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
-        this.privateSession = new ThreadLocal<Session>();
+        //this.privateSession = new ThreadLocal<Session>();
         this.servletContext = servletContext;
     }
 
@@ -74,21 +73,12 @@
 
     void resetRequestResourceResolver() {
         requestResourceResolver.remove();
-
-        // at the same time logout this thread's session
-        Session session = privateSession.get();
-        if (session != null) {
-            if (session.isLive()) {
-                session.logout();
-            }
-            privateSession.remove();
-        }
     }
 
     ServletContext getServletContext() {
         return servletContext;
     }
-    
+
     // ---------- IOProvider interface -----------------------------------------
 
     /**
@@ -98,14 +88,14 @@
      */
     public InputStream getInputStream(String fileName)
             throws FileNotFoundException, IOException {
-        
+
         try {
-            
+
             Resource resource = getResourceInternal(fileName);
             if (resource == null) {
                 throw new FileNotFoundException("Cannot find " + fileName);
             }
-            
+
             InputStream stream = resource.adaptTo(InputStream.class);
             if (stream == null) {
                 throw new FileNotFoundException("Cannot find " + fileName);
@@ -284,14 +274,8 @@
 
     // ---------- internal -----------------------------------------------------
 
-    private Session getPrivateSession() throws RepositoryException {
-        Session session = privateSession.get();
-        if (session == null) {
-            session = repository.loginAdministrative(null);
-            privateSession.set(session);
-        }
-
-        return session;
+    private Session getPrivateSession()  {
+        return requestResourceResolver.get().adaptTo(Session.class);
     }
 
     private static void checkNode(Node node, String path) {
@@ -391,7 +375,7 @@
                 if (mimeType == null) {
                     mimeType = "application/octet-stream";
                 }
-                
+
                 contentNode.setProperty("jcr:lastModified",
                     System.currentTimeMillis());
                 contentNode.setProperty("jcr:data", new ByteArrayInputStream(



Mime
View raw message