incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1591298 - in /sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp: JspScriptEngineFactory.java JspServletConfig.java
Date Wed, 30 Apr 2014 14:05:21 GMT
Author: cziegeler
Date: Wed Apr 30 14:05:21 2014
New Revision: 1591298

URL: http://svn.apache.org/r1591298
Log:
SLING-3486 : Configuration changes like jasper.trimSpaces only work after cleaning /var/classes
and bundle restart

Modified:
    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/JspServletConfig.java

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=1591298&r1=1591297&r2=1591298&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
Wed Apr 30 14:05:21 2014
@@ -18,7 +18,10 @@ package org.apache.sling.scripting.jsp;
 
 import static org.apache.sling.api.scripting.SlingBindings.SLING;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.util.Dictionary;
@@ -90,9 +93,9 @@ import org.slf4j.LoggerFactory;
    @Property(name="jasper.trimSpaces",boolValue=false),
    @Property(name="jasper.displaySourceFragments",boolValue=false),
    @Property(name=EventConstants.EVENT_TOPIC, value={"org/apache/sling/api/resource/*"},
propertyPrivate=true),
-   @Property(name="felix.webconsole.label", value="slingjsp"),
-   @Property(name="felix.webconsole.title", value="JSP"),
-   @Property(name="felix.webconsole.category", value="Sling"),
+   @Property(name="felix.webconsole.label", value="slingjsp", propertyPrivate=true),
+   @Property(name="felix.webconsole.title", value="JSP", propertyPrivate=true),
+   @Property(name="felix.webconsole.category", value="Sling", propertyPrivate=true),
 })
 public class JspScriptEngineFactory
     extends AbstractScriptEngineFactory
@@ -126,7 +129,7 @@ public class JspScriptEngineFactory
 
     private JspServletContext jspServletContext;
 
-    private ServletConfig servletConfig;
+    private JspServletConfig servletConfig;
 
     private boolean defaultIsSession;
 
@@ -343,6 +346,9 @@ public class JspScriptEngineFactory
             Thread.currentThread().setContextClassLoader(old);
         }
 
+        // check for changes in jasper config
+        this.checkJasperConfig();
+
         logger.debug("IMPORTANT: Do not modify the generated servlet classes directly");
     }
 
@@ -366,6 +372,59 @@ public class JspScriptEngineFactory
         this.jspFactoryHandler = null;
     }
 
+    private static final String CONFIG_PATH = "/jsp.config";
+
+    /**
+     * Check if the jasper configuration changed.
+     */
+    private void checkJasperConfig() {
+        boolean changed = false;
+        InputStream is = null;
+        try {
+            is = this.classLoaderWriter.getInputStream(CONFIG_PATH);
+            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int length = 0;
+            while ( ( length = is.read(buffer)) != -1 ) {
+                baos.write(buffer, 0, length);
+            }
+            baos.close();
+            final String oldKey = new String(baos.toByteArray(), "UTF-8");
+            changed = !oldKey.equals(this.servletConfig.getConfigKey());
+            if ( changed ) {
+                logger.info("Removing all class files due to jsp configuration change");
+            }
+        } catch ( final IOException notFound ) {
+            changed = true;
+        } finally {
+            if ( is != null ) {
+                try {
+                    is.close();
+                } catch ( final IOException ignore) {
+                    // ignore
+                }
+            }
+        }
+        if ( changed ) {
+            OutputStream os = null;
+            try {
+                os = this.classLoaderWriter.getOutputStream(CONFIG_PATH);
+                os.write(this.servletConfig.getConfigKey().getBytes("UTF-8"));
+            } catch ( final IOException ignore ) {
+                // ignore
+            } finally {
+                if ( os != null ) {
+                    try {
+                        os.close();
+                    } catch ( final IOException ignore ) {
+                        // ignore
+                    }
+                }
+            }
+            this.classLoaderWriter.delete("/org/apache/jsp");
+        }
+    }
+
     /**
      * Unbinds the Sling ServletContext and removes any known servlet context
      * attributes preventing the bundles's class loader from being collected.

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java?rev=1591298&r1=1591297&r2=1591298&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java
(original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletConfig.java
Wed Apr 30 14:05:21 2014
@@ -21,8 +21,8 @@ package org.apache.sling.scripting.jsp;
 import java.util.Collections;
 import java.util.Dictionary;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.TreeMap;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -47,7 +47,7 @@ class JspServletConfig implements Servle
         }
 
         // copy the "jasper." properties
-        properties = new HashMap<String, String>();
+        properties = new TreeMap<String, String>();
         for (Enumeration<?> ke = config.keys(); ke.hasMoreElements();) {
             String key = (String) ke.nextElement();
             if (key.startsWith("jasper.")) {
@@ -72,4 +72,18 @@ class JspServletConfig implements Servle
     public String getServletName() {
         return servletName;
     }
+
+    /**
+     * Return a unique key for the jasper configuration
+     */
+    public String getConfigKey() {
+        final StringBuilder sb = new StringBuilder();
+        for(final Map.Entry<String, String> entry : this.properties.entrySet() ) {
+            sb.append(entry.getKey());
+            sb.append('=');
+            sb.append(entry.getValue());
+            sb.append(';');
+        }
+        return sb.toString();
+    }
 }
\ No newline at end of file



Mime
View raw message