You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/02/17 16:35:27 UTC

svn commit: r911022 [2/2] - in /sling/trunk/bundles/scripting/jsp: ./ src/main/java/org/apache/sling/scripting/jsp/ src/main/java/org/apache/sling/scripting/jsp/jasper/ src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/ src/main/java/org/apa...

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServlet.java?rev=911022&r1=911021&r2=911022&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServlet.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServlet.java Wed Feb 17 15:35:26 2010
@@ -5,9 +5,9 @@
  * 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.
@@ -28,7 +28,6 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.sling.scripting.jsp.jasper.Constants;
@@ -36,7 +35,6 @@
 import org.apache.sling.scripting.jsp.jasper.Options;
 import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext;
 import org.apache.sling.scripting.jsp.jasper.compiler.Localizer;
-import org.apache.sling.scripting.jsp.jasper.runtime.PeriodicEventListener;
 
 /**
  * The JSP engine (a.k.a Jasper).
@@ -54,7 +52,7 @@
  * @author Kin-man Chung
  * @author Glenn Nielsen
  */
-public class JspServlet extends HttpServlet implements PeriodicEventListener {
+public class JspServlet extends HttpServlet {
 
     // Logger
     private Log log = LogFactory.getLog(JspServlet.class);
@@ -69,14 +67,14 @@
      * Initializes this JspServlet.
      */
     public void init(ServletConfig config) throws ServletException {
-        
+
         super.init(config);
         this.config = config;
         this.context = config.getServletContext();
-        
+
         // Initialize the JSP Runtime Context
         // Check for a custom Options implementation
-        String engineOptionsName = 
+        String engineOptionsName =
             config.getInitParameter("engineOptionsClass");
         if (engineOptionsName != null) {
             // Instantiate the indicated Options implementation
@@ -99,7 +97,7 @@
             options = new EmbeddedServletOptions(config, context);
         }
         rctxt = new JspRuntimeContext(context, options);
-        
+
         if (log.isDebugEnabled()) {
             log.debug(Localizer.getMessage("jsp.message.scratch.dir.is",
                     options.getScratchDir().toString()));
@@ -202,9 +200,9 @@
         }
 
     }
-    
 
-    public void service (HttpServletRequest request, 
+
+    public void service (HttpServletRequest request,
     			 HttpServletResponse response)
                 throws ServletException, IOException {
 
@@ -233,7 +231,7 @@
                 }
             } else {
                 /*
-                 * Requested JSP has not been the target of a 
+                 * Requested JSP has not been the target of a
                  * RequestDispatcher.include(). Reconstruct its path from the
                  * request's getServletPath() and getPathInfo()
                  */
@@ -245,7 +243,7 @@
             }
         }
 
-        if (log.isDebugEnabled()) {	    
+        if (log.isDebugEnabled()) {
             log.debug("JspEngine --> " + jspUri);
             log.debug("\t     ServletPath: " + request.getServletPath());
             log.debug("\t        PathInfo: " + request.getPathInfo());
@@ -256,7 +254,7 @@
             Enumeration e = request.getParameterNames();
             while (e.hasMoreElements()) {
                 String name = (String) e.nextElement();
-                log.debug("\t\t " + name + " = " 
+                log.debug("\t\t " + name + " = "
                           + request.getParameter(name));
             }
         }
@@ -285,10 +283,6 @@
     }
 
 
-    public void periodicEvent() {
-        rctxt.checkCompile();
-    }
-
     // -------------------------------------------------------- Private Methods
 
     private void serviceJspFile(HttpServletRequest request,
@@ -296,11 +290,10 @@
                                 Throwable exception, boolean precompile)
         throws ServletException, IOException {
 
-        JspServletWrapper wrapper =
-            (JspServletWrapper) rctxt.getWrapper(jspUri);
+        JspServletWrapper wrapper = rctxt.getWrapper(jspUri);
         if (wrapper == null) {
             synchronized(this) {
-                wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
+                wrapper = rctxt.getWrapper(jspUri);
                 if (wrapper == null) {
                     // Check if the requested JSP page exists, to avoid
                     // creating unnecessary directories and files.

Modified: sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java?rev=911022&r1=911021&r2=911022&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/jasper/servlet/JspServletWrapper.java Wed Feb 17 15:35:26 2010
@@ -5,9 +5,9 @@
  * 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.
@@ -69,8 +69,8 @@
 
     private Servlet theServlet;
     private String jspUri;
-    private Class servletClass;
-    private Class tagHandlerClass;
+    private Class<?> servletClass;
+    private Class<?> tagHandlerClass;
     private JspCompilationContext ctxt;
     private long available = 0L;
     private ServletConfig config;
@@ -81,7 +81,7 @@
     private int tripCount;
     private JasperException compileException;
     private long servletClassLastModifiedTime;
-    private long lastModificationTest = 0L;
+    private volatile long lastModificationTest = 0L;
 
     /*
      * JspServletWrapper for JSP pages.
@@ -99,7 +99,7 @@
 					 this, rctxt);
     }
 
-    /*
+    /**
      * JspServletWrapper for tag files.
      */
     public JspServletWrapper(ServletContext servletContext,
@@ -108,13 +108,12 @@
 			     TagInfo tagInfo,
 			     JspRuntimeContext rctxt,
 			     URL tagFileJarUrl)
-	    throws JasperException {
-
-	this.isTagFile = true;
+    throws JasperException {
+        this.isTagFile = true;
         this.config = null;	// not used
         this.options = options;
-	this.jspUri = tagFilePath;
-	this.tripCount = 0;
+        this.jspUri = tagFilePath;
+        this.tripCount = 0;
         ctxt = new JspCompilationContext(jspUri, tagInfo, options,
 					 servletContext, this, rctxt,
 					 tagFileJarUrl);
@@ -138,9 +137,9 @@
                 if (reload) {
                     // This is to maintain the original protocol.
                     destroy();
-                    
+
                     Servlet servlet = null;
-                    
+
                     try {
                         servletClass = ctxt.load();
                         servlet = (Servlet) servletClass.newInstance();
@@ -156,7 +155,7 @@
                     } catch (Exception e) {
                         throw new JasperException(e);
                     }
-                    
+
                     servlet.init(config);
 
                     if (!firstTime) {
@@ -166,7 +165,7 @@
                     theServlet = servlet;
                     reload = false;
                 }
-            }    
+            }
         }
         return theServlet;
     }
@@ -204,13 +203,13 @@
     /**
      * Compile (if needed) and load a tag file
      */
-    public Class loadTagFile() throws JasperException {
+    public Class<?> loadTagFile() throws JasperException {
 
         try {
             if (ctxt.isRemoved()) {
                 throw new FileNotFoundException(jspUri);
             }
-            if (options.getDevelopment() || firstTime ) {
+            if (firstTime || this.lastModificationTest == 0) {
                 synchronized (this) {
                     firstTime = false;
                     ctxt.compile();
@@ -238,20 +237,21 @@
      * (skeleton) with no dependencies on other other tag files is
      * generated and compiled.
      */
-    public Class loadTagFilePrototype() throws JasperException {
+    public Class<?> loadTagFilePrototype() throws JasperException {
 
-	ctxt.setPrototypeMode(true);
-	try {
-	    return loadTagFile();
-	} finally {
-	    ctxt.setPrototypeMode(false);
-	}
+    	ctxt.setPrototypeMode(true);
+    	try {
+    	    return loadTagFile();
+    	} finally {
+    	    ctxt.setPrototypeMode(false);
+    	}
     }
 
     /**
      * Get a list of files that the current page has source dependency on.
      */
-    public java.util.List getDependants() {
+    @SuppressWarnings("unchecked")
+    public java.util.List<String> getDependants() {
         try {
             Object target;
             if (isTagFile) {
@@ -272,22 +272,26 @@
     }
 
     public boolean isTagFile() {
-	return this.isTagFile;
+        return this.isTagFile;
     }
 
     public int incTripCount() {
-	return tripCount++;
+        return tripCount++;
     }
 
     public int decTripCount() {
-	return tripCount--;
+        return tripCount--;
     }
 
-    public void service(HttpServletRequest request, 
+    public String getJspUri() {
+        return jspUri;
+    }
+
+    public void service(HttpServletRequest request,
                         HttpServletResponse response,
                         boolean precompile)
 	    throws ServletException, IOException, FileNotFoundException {
-        
+
         try {
 
             if (ctxt.isRemoved()) {
@@ -301,23 +305,24 @@
                         (HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                          Localizer.getMessage("jsp.error.unavailable"));
                     return;
-                } else {
-                    // Wait period has expired. Reset.
-                    available = 0;
                 }
+                // Wait period has expired. Reset.
+                available = 0;
             }
 
             /*
              * (1) Compile
              */
-            if (options.getDevelopment() || firstTime ) {
+            if (firstTime || this.lastModificationTest == 0 ) {
                 synchronized (this) {
+                    System.out.println("Compiling " + this.getJspUri());
                     firstTime = false;
 
                     // The following sets reload to true, if necessary
                     ctxt.compile();
                 }
             } else {
+                System.out.println("Calling " + this.getJspUri());
                 if (compileException != null) {
                     // Throw cached compilation exception
                     throw compileException;
@@ -343,44 +348,27 @@
                 // a response.sendError() will be ignored by the
                 // servlet engine.
                 throw new ServletException(ex);
-            } else {
-                try {
-                    response.sendError(HttpServletResponse.SC_NOT_FOUND, 
-                                      ex.getMessage());
-                } catch (IllegalStateException ise) {
-                    log.error(Localizer.getMessage("jsp.error.file.not.found",
-                           ex.getMessage()),
-                  ex);
-                }
             }
-        } catch (ServletException ex) {
-            if (options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
+            try {
+                response.sendError(HttpServletResponse.SC_NOT_FOUND,
+                                  ex.getMessage());
+            } catch (IllegalStateException ise) {
+                log.error(Localizer.getMessage("jsp.error.file.not.found",
+                       ex.getMessage()),
+              ex);
             }
+        } catch (ServletException ex) {
+            throw handleJspException(ex);
         } catch (IOException ex) {
-            if (options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
-            }
+            throw handleJspException(ex);
         } catch (IllegalStateException ex) {
-            if (options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
-            }
+            throw handleJspException(ex);
         } catch (Exception ex) {
-            if (options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw new JasperException(ex);
-            }
+            throw handleJspException(ex);
         }
 
         try {
-            
+
             /*
              * (3) Service request
              */
@@ -402,41 +390,24 @@
                 // a response.sendError() will be ignored by the
                 // servlet engine.
                 throw ex;
-            } else {
-                int unavailableSeconds = ex.getUnavailableSeconds();
-                if (unavailableSeconds <= 0) {
-                    unavailableSeconds = 60;        // Arbitrary default
-                }
-                available = System.currentTimeMillis() +
-                    (unavailableSeconds * 1000L);
-                response.sendError
-                    (HttpServletResponse.SC_SERVICE_UNAVAILABLE, 
-                     ex.getMessage());
             }
+            int unavailableSeconds = ex.getUnavailableSeconds();
+            if (unavailableSeconds <= 0) {
+                unavailableSeconds = 60;        // Arbitrary default
+            }
+            available = System.currentTimeMillis() +
+                (unavailableSeconds * 1000L);
+            response.sendError
+                (HttpServletResponse.SC_SERVICE_UNAVAILABLE,
+                 ex.getMessage());
         } catch (ServletException ex) {
-            if(options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
-            }
+            throw handleJspException(ex);
         } catch (IOException ex) {
-            if(options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
-            }
+            throw handleJspException(ex);
         } catch (IllegalStateException ex) {
-            if(options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw ex;
-            }
+            throw handleJspException(ex);
         } catch (Exception ex) {
-            if(options.getDevelopment()) {
-                throw handleJspException(ex);
-            } else {
-                throw new JasperException(ex);
-            }
+            throw handleJspException(ex);
         }
     }
 
@@ -494,7 +465,7 @@
                 exMessage = ex.toString();
             }
         }
-        
+
         // avoid nested ScriptEvaluationExceptions (eg. in nested jsp includes)
         while (realException instanceof ScriptEvaluationException) {
             realException = realException.getCause();
@@ -517,42 +488,38 @@
                 // to the generated servlet class, we can't really add anything
                 return new JasperException(exMessage, realException);
             }
-            else {
-                int javaLineNumber = jspFrame.getLineNumber();
-                JavacErrorDetail detail = ErrorDispatcher.createJavacError(
-                        jspFrame.getMethodName(),
-                        this.ctxt.getCompiler().getPageNodes(),
-                        null,
-                        javaLineNumber,
-                        ctxt);
-
-                // If the line number is less than one we couldn't find out
-                // where in the JSP things went wrong
-                int jspLineNumber = detail.getJspBeginLineNumber();
-                if (jspLineNumber < 1) {
-                    return new JasperException(exMessage, realException);
-                }
-
-                if (options.getDisplaySourceFragment()) {
-                    return new JasperException(Localizer.getMessage
-                            ("jsp.exception", detail.getJspFileName(),
-                                    "" + jspLineNumber) +
-                                    "\n\n" + detail.getJspExtract() +
-                                    "\n", realException);
-                    
-                } else {
-                    return new JasperException(Localizer.getMessage
-                            ("jsp.exception", detail.getJspFileName(),
-                                    "" + jspLineNumber), realException);
-                }
+            int javaLineNumber = jspFrame.getLineNumber();
+            JavacErrorDetail detail = ErrorDispatcher.createJavacError(
+                    jspFrame.getMethodName(),
+                    this.ctxt.getCompiler().getPageNodes(),
+                    null,
+                    javaLineNumber,
+                    ctxt);
+
+            // If the line number is less than one we couldn't find out
+            // where in the JSP things went wrong
+            int jspLineNumber = detail.getJspBeginLineNumber();
+            if (jspLineNumber < 1) {
+                return new JasperException(exMessage, realException);
+            }
+
+            if (options.getDisplaySourceFragment()) {
+                return new JasperException(Localizer.getMessage
+                        ("jsp.exception", detail.getJspFileName(),
+                                "" + jspLineNumber) +
+                                "\n\n" + detail.getJspExtract() +
+                                "\n", realException);
+
             }
+            return new JasperException(Localizer.getMessage
+                    ("jsp.exception", detail.getJspFileName(),
+                            "" + jspLineNumber), realException);
         } catch (Exception je) {
             // If anything goes wrong, just revert to the original behaviour
             if (realException instanceof JasperException) {
                 return (JasperException) realException;
-            } else {
-                return new JasperException(exMessage, realException);
             }
+            return new JasperException(exMessage, realException);
         }
     }
 

Modified: sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=911022&r1=911021&r2=911022&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties (original)
+++ sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties Wed Feb 17 15:35:26 2010
@@ -31,22 +31,10 @@
  JCR repository and generated Java source and class files will be written to \
  the JCR repository below the configured Compilation Location.  
 
-jasper.checkInterval.name = Compilation Check Interval
-jasper.checkInterval.description = If development is false and reloading is \
- true, background compiles are enabled. checkInterval is the time in seconds \
- between checks to see if a JSP page needs to be recompiled. Default 300 seconds. \
- Currently this feature is not implemented in Apache Sling!
- 
 jasper.classdebuginfo.name = Generate Debug Info
 jasper.classdebuginfo.description = Should the class file be compiled with \
  debugging information? true or false, default true.
  
-jasper.development.name = Development Mode
-jasper.development.description = Is Jasper used in development mode (will check \
- for JSP modification on every access)? true or false, default true. \
- If development mode is turned off, a jsp is only compiled once and never \
- checked again - even if the generated class file will be removed!
- 
 jasper.enablePooling.name = Tag Pooling
 jasper.enablePooling.description = Determines whether tag handler pooling is \
  enabled. true or false, default true.
@@ -68,13 +56,6 @@
 jasper.mappedfile.description = Should we generate static content with one \
  print statement per input line, to ease debugging? true or false, default true.
  
-jasper.modificationTestInterval.name = Modification Check Interval
-jasper.modificationTestInterval.description = Checks for modification for a \
- given JSP file (and all its dependent files) will be performed only once every \
- specified amount of seconds. Setting this to 0 will cause the JSP to be checked \
- on every access. Default is 4 seconds. This parameter has only an effect if \
- developement mode is turned on.
- 
 jasper.trimSpaces.name = Trim Spaces
 jasper.trimSpaces.description = Should white spaces in template text between \
  actions or directives be trimmed ?, default false.