SLING-6288 : Improve jsp resource change listener to use globs
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1769860 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java b/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
index 11aa6d0..dc0ef1c 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
@@ -40,13 +40,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Properties;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingException;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingIOException;
@@ -63,7 +56,6 @@
import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.commons.compiler.JavaCompiler;
-import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
import org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext;
@@ -73,6 +65,14 @@
import org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper;
import org.apache.sling.scripting.jsp.util.TagUtil;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.Designate;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,39 +80,101 @@
* The JSP engine (a.k.a Jasper).
*
*/
-@Component(label="%jsphandler.name",
- description="%jsphandler.description",
- metatype=true)
-@Service(value={javax.script.ScriptEngineFactory.class,ResourceChangeListener.class,Servlet.class})
-@Properties({
- @Property(name="service.description",value="JSP Script Handler"),
- @Property(name="service.vendor",value="The Apache Software Foundation"),
- @Property(name="jasper.compilerTargetVM", value=JspServletOptions.AUTOMATIC_VERSION),
- @Property(name="jasper.compilerSourceVM", value=JspServletOptions.AUTOMATIC_VERSION),
- @Property(name="jasper.classdebuginfo",boolValue=true),
- @Property(name="jasper.enablePooling",boolValue=true),
- @Property(name="jasper.ieClassId",value="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"),
- @Property(name="jasper.genStringAsCharArray",boolValue=false),
- @Property(name="jasper.keepgenerated",boolValue=true),
- @Property(name="jasper.mappedfile",boolValue=true),
- @Property(name="jasper.trimSpaces",boolValue=false),
- @Property(name="jasper.displaySourceFragments",boolValue=false),
- @Property(name=ResourceChangeListener.PATHS, value={"/"}, propertyPrivate=true),
- @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)
-})
+@Component(service = {javax.script.ScriptEngineFactory.class,ResourceChangeListener.class,Servlet.class},
+ property = {
+ Constants.SERVICE_VENDOR + "=The Apache Software Foundation",
+ Constants.SERVICE_DESCRIPTION + "=JSP Script Handler",
+ ResourceChangeListener.PATHS + "=/**/*.jsp",
+ ResourceChangeListener.PATHS + "=/**/*.jspf",
+ ResourceChangeListener.PATHS + "=/**/*.jspx",
+ ResourceChangeListener.PATHS + "=/**/*.tld",
+ ResourceChangeListener.PATHS + "=/**/*.tag",
+ "felix.webconsole.label=slingjsp",
+ "felix.webconsole.title=JSP",
+ "felix.webconsole.category=Sling"
+ })
+@Designate(ocd = JspScriptEngineFactory.Config.class)
public class JspScriptEngineFactory
extends AbstractScriptEngineFactory
implements Servlet,ResourceChangeListener,ExternalResourceChangeListener {
- @Property(boolValue = true)
- private static final String PROP_DEFAULT_IS_SESSION = "default.is.session";
+ @ObjectClassDefinition(name = "Apache Sling JSP Script Handler",
+ description = "The JSP Script Handler supports development of JSP " +
+ "scripts to render response content on behalf of ScriptComponents. Internally " +
+ "Jasper 6.0.14 JSP Engine is used together with the Eclipse Java Compiler to " +
+ "compile generated Java code into Java class files. Some settings of Jasper " +
+ "may be configured as shown below. Note that JSP scripts are expected in the " +
+ "JCR repository and generated Java source and class files will be written to " +
+ "the JCR repository below the configured Compilation Location.")
+ public @interface Config {
+ @AttributeDefinition(name = "Target Version",
+ description = "The taret JVM version for the compiled classes. If " +
+ "left empty, the default version, 1.6., is used. If the value \"auto\" is used, the " +
+ "current vm version will be used.")
+ String jasper_compilerTargetVM() default JspServletOptions.AUTOMATIC_VERSION;
+
+ @AttributeDefinition(name = "Source Version",
+ description = "The JVM version for the java/JSP source. If " +
+ "left empty, the default version, 1.6., is used. If the value \"auto\" is used, the " +
+ "current vm version will be used.")
+ String jasper_compilerSourceVM() default JspServletOptions.AUTOMATIC_VERSION;
+
+ @AttributeDefinition(name = "Generate Debug Info",
+ description = "Should the class file be compiled with " +
+ "debugging information? true or false, default true.")
+ boolean jasper_classdebuginfo() default true;
+
+ @AttributeDefinition(name = "Tag Pooling",
+ description = "Determines whether tag handler pooling is " +
+ "enabled. true or false, default true.")
+ boolean jasper_enablePooling() default true;
+
+ @AttributeDefinition(name = "Plugin Class-ID",
+ description = "The class-id value to be sent to Internet " +
+ "Explorer when using <jsp:plugin> tags. Default " +
+ "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93.")
+ String jasper_ieClassId() default "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93";
+
+ @AttributeDefinition(name = "Char Array Strings",
+ description = "Should text strings be generated as " +
+ "char arrays, to improve performance in some cases? Default false.")
+ boolean jasper_genStringAsCharArray() default false;
+
+ @AttributeDefinition(name = "Keep Generated Java",
+ description = "Should we keep the generated Java source " +
+ "code for each page instead of deleting it? true or false, default true.")
+ boolean jasper_keepgenerated() default true;
+
+ @AttributeDefinition(name = "Mapped Content",
+ description = "Should we generate static content with one " +
+ "print statement per input line, to ease debugging? true or false, default true.")
+ boolean jasper_mappedfile() default true;
+
+ @AttributeDefinition(name = "Trim Spaces",
+ description = "Should white spaces in template text between " +
+ "actions or directives be trimmed ?, default false.")
+ boolean jasper_trimSpaces() default false;
+
+ @AttributeDefinition(name = "Display Source Fragments",
+ description = "Should we include a source fragment " +
+ "in exception messages, which could be displayed to the developer")
+ boolean jasper_displaySourceFragments() default false;
+
+ @AttributeDefinition(name = "Default Session Value",
+ description = "Should a session be created by default for every " +
+ "JSP page? Warning - this behavior may produce unintended results and changing " +
+ "it will not impact previously-compiled pages.")
+ boolean default_is_session() default true;
+ }
+/**
+default.is.session.name = Default Session Value
+default.is.session.description = Should a session be created by default for every \
+ JSP page? Warning - this behavior may produce unintended results and changing \
+ it will not impact previously-compiled pages. */
/** Default logger */
- private final Logger logger = LoggerFactory.getLogger(JspScriptEngineFactory.class);
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
- @Reference(unbind="unbindSlingServletContext", target="(name=org.apache.sling)")
private ServletContext slingServletContext;
@Reference
@@ -331,8 +393,10 @@
* Activate this component
*/
@Activate
- protected void activate(final BundleContext bundleContext, final Map<String, Object> properties) {
- this.defaultIsSession = PropertiesUtil.toBoolean(properties.get(PROP_DEFAULT_IS_SESSION), true);
+ protected void activate(final BundleContext bundleContext,
+ final Config config,
+ final Map<String, Object> properties) {
+ this.defaultIsSession = config.default_is_session();
// set the current class loader as the thread context loader for
// the setup of the JspRuntimeContext
@@ -349,7 +413,7 @@
// return options which use the jspClassLoader
options = new JspServletOptions(slingServletContext, ioProvider,
- properties, tldLocationsCache);
+ properties, tldLocationsCache);
jspServletContext = new JspServletContext(ioProvider,
slingServletContext, tldLocationsCache);
@@ -443,6 +507,11 @@
}
}
+ @Reference(target="(name=org.apache.sling)")
+ protected void bindSlingServletContext(final ServletContext context) {
+ this.slingServletContext = context;
+ }
+
/**
* Unbinds the Sling ServletContext and removes any known servlet context
* attributes preventing the bundles's class loader from being collected.
diff --git a/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java b/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
index e16b58d..7b4d803 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
@@ -313,7 +313,7 @@
}
/**
- * Allways return null for the compiler to use, assuming JDT is the default
+ * Always return null for the compiler to use, assuming JDT is the default
* which we will never overwrite.
*/
@Override
diff --git a/src/main/resources/OSGI-INF/metatype/metatype.properties b/src/main/resources/OSGI-INF/metatype/metatype.properties
deleted file mode 100644
index cc28825..0000000
--- a/src/main/resources/OSGI-INF/metatype/metatype.properties
+++ /dev/null
@@ -1,80 +0,0 @@
-#
-# 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.
-#
-
-#
-# This file contains localization strings for configuration labels and
-# descriptions as used in the metatype.xml descriptor generated by the
-# the Sling SCR plugin
-
-jsphandler.name = Apache Sling JSP Script Handler
-jsphandler.description The JSP Script Handler supports development of JSP \
- scripts to render response content on behalf of ScriptComponents. Internally \
- Jasper 5.5.20 JSP Engine is used together with the Eclipse Java Compiler to \
- compile generated Java code into Java class files. Some settings of Jasper \
- may be configured as shown below. Note that JSP scripts are expected in the \
- JCR repository and generated Java source and class files will be written to \
- the JCR repository below the configured Compilation Location.
-
-jasper.compilerSourceVM.name = Source Version
-jasper.compilerSourceVM.description = The JVM version for the java/JSP source. If \
- left empty, the default version, 1.6., is used. If the value "auto" is used, the \
- current vm version will be used.
-
-jasper.compilerTargetVM.name = Target Version
-jasper.compilerTargetVM.description = The taret JVM version for the compiled classes. If \
- left empty, the default version, 1.6., is used. If the value "auto" is used, the \
- current vm version will be used.
-
-jasper.classdebuginfo.name = Generate Debug Info
-jasper.classdebuginfo.description = Should the class file be compiled with \
- debugging information? true or false, default true.
-
-jasper.enablePooling.name = Tag Pooling
-jasper.enablePooling.description = Determines whether tag handler pooling is \
- enabled. true or false, default true.
-
-jasper.ieClassId.name = Plugin Class-ID
-jasper.ieClassId.description = The class-id value to be sent to Internet \
- Explorer when using <jsp:plugin> tags. Default \
- clsid:8AD9C840-044E-11D1-B3E9-00805F499D93.
-
-jasper.genStringAsCharArray.name = Char Array Strings
-jasper.genStringAsCharArray.description = Should text strings be generated as \
- char arrays, to improve performance in some cases? Default false.
-
-jasper.keepgenerated.name = Keep Generated Java
-jasper.keepgenerated.description = Should we keep the generated Java source \
- code for each page instead of deleting it? true or false, default true.
-
-jasper.mappedfile.name = Mapped Content
-jasper.mappedfile.description = Should we generate static content with one \
- print statement per input line, to ease debugging? true or false, default true.
-
-jasper.trimSpaces.name = Trim Spaces
-jasper.trimSpaces.description = Should white spaces in template text between \
- actions or directives be trimmed ?, default false.
-
-jasper.displaySourceFragments.name = Display Source Fragments
-jasper.displaySourceFragments.description = Should we include a source fragment \
- in exception messages, which could be displayed to the developer
-
-default.is.session.name = Default Session Value
-default.is.session.description = Should a session be created by default for every \
- JSP page? Warning - this behavior may produce unintended results and changing \
- it will not impact previously-compiled pages.