Author: bdelacretaz
Date: Thu Dec 5 01:32:21 2013
New Revision: 1547985
URL: http://svn.apache.org/r1547985
Log:
Request context prototype - install and request /apps/requestcontext.html to
execute. See scripts under /apps/requestcontext.
Added:
sling/whiteboard/bdelacretaz/request-context/ (with props)
sling/whiteboard/bdelacretaz/request-context/pom.xml (with props)
sling/whiteboard/bdelacretaz/request-context/src/
sling/whiteboard/bdelacretaz/request-context/src/main/
sling/whiteboard/bdelacretaz/request-context/src/main/java/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/resources/
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp
(with props)
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma
(with props)
Propchange: sling/whiteboard/bdelacretaz/request-context/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec 5 01:32:21 2013
@@ -0,0 +1,15 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+derby.log
+jackrabbit
+sling
+
+
Added: sling/whiteboard/bdelacretaz/request-context/pom.xml
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/pom.xml?rev=1547985&view=auto
==============================================================================
--- sling/whiteboard/bdelacretaz/request-context/pom.xml (added)
+++ sling/whiteboard/bdelacretaz/request-context/pom.xml Thu Dec 5 01:32:21
2013
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>18</version>
+ </parent>
+
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.requestcontext</artifactId>
+ <version>0.1.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+ <name>Apache Sling Request Context Prototype</name>
+
+ <properties>
+ <sling.java.version>6</sling.java.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Export-Package>org.apache.sling.requestcontext.api</Export-Package>
+
<Private-Package>org.apache.sling.requestcontext.impl.*</Private-Package>
+
<Sling-Initial-Content>SLING-CONTENT</Sling-Initial-Content>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.servlets.post</artifactId>
+ <version>2.1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.api</artifactId>
+ <version>2.1.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <version>1.6R6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Propchange: sling/whiteboard/bdelacretaz/request-context/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+package org.apache.sling.requestcontext.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+
+@SuppressWarnings("serial")
+class ScriptableProperties extends ScriptableObject {
+
+ private final Map<String, Object> properties = new HashMap<String,
Object>();
+ private boolean isReadOnly;
+
+ @Override
+ public String getClassName() {
+ return getClass().getName();
+ }
+
+ protected void setReadOnly(boolean b) {
+ isReadOnly = b;
+ }
+
+ @Override
+ public Object get(String name, Scriptable start) {
+ final Object result = properties.get(name);
+ return result != null ? result : NOT_FOUND;
+ }
+
+ @Override
+ public void put(String name, Scriptable start, Object value) {
+ if(isReadOnly) {
+ throw new IllegalArgumentException("Read-only object, property is
not modifiable:" + name);
+ }
+ properties.put(name, value);
+ }
+
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableProperties.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.sling.requestcontext.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ValueMap;
+import org.mozilla.javascript.Scriptable;
+import org.mozilla.javascript.ScriptableObject;
+
+@SuppressWarnings("serial")
+class ScriptableResourceProperties extends ScriptableObject {
+
+ private final ValueMap valueMap;
+
+ ScriptableResourceProperties(Resource r) {
+ valueMap = r.adaptTo(ValueMap.class);
+ }
+
+ @Override
+ public String getClassName() {
+ return getClass().getName();
+ }
+
+ @Override
+ public Object get(String name, Scriptable start) {
+ final Object result = valueMap == null ? null : valueMap.get(name);
+ return result != null ? result : NOT_FOUND;
+ }
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/ScriptableResourceProperties.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+package org.apache.sling.requestcontext.api;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.mozilla.javascript.Scriptable;
+
+/** Intelligent Request Context meant to be provided in
+ * scripts as the "rc" object.
+ */
+@SuppressWarnings("serial")
+public class SlingRequestContext extends ScriptableProperties {
+
+ private final SlingHttpServletRequest request;
+
+ public SlingRequestContext(SlingHttpServletRequest request) {
+ this.request = request;
+ request.setAttribute(this.getClass().getName(), this);
+
+ // Free read-write properties: "u"
+ put("u", this, new ScriptableProperties());
+
+ // The current resource's properties as "r"
+ put("r", this, new
ScriptableResourceProperties(request.getResource()));
+
+ setReadOnly(true);
+ }
+
+ public static SlingRequestContext fromRequest(HttpServletRequest r) {
+ return
(SlingRequestContext)r.getAttribute(SlingRequestContext.class.getName());
+ }
+
+ @Override
+ public Object get(String name, Scriptable start) {
+ Object result = super.get(name, start);
+ if(result == NOT_FOUND) {
+ // TODO fallback to request attributes, script bindings, OSGi
services etc
+ // for now just a few example fallbacks - should use reflection on
objects like Resource
+ if("path".equals(name)) {
+ return request.getResource().getPath();
+ } else if("resourceType".equals(name)) {
+ return request.getResource().getResourceType();
+ }
+ }
+ return result;
+ }
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/api/SlingRequestContext.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.apache.sling.requestcontext.impl;
+
+import javax.script.Bindings;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.requestcontext.api.SlingRequestContext;
+import org.apache.sling.scripting.api.BindingsValuesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+@Service
+public class RequestContextBindingsValuesProvider implements
BindingsValuesProvider {
+
+ private Logger log = LoggerFactory.getLogger(getClass());
+ static final ThreadLocal<SlingHttpServletRequest> requestThreadLocal = new
ThreadLocal<SlingHttpServletRequest>();
+ public static final String RC_BINDING_NAME = "rc";
+
+ public void addBindings(Bindings b) {
+ final SlingHttpServletRequest request = requestThreadLocal.get();
+ if(request == null) {
+ log.debug("No request in thread local, cannot add {} binding",
RC_BINDING_NAME);
+ return;
+ }
+ final SlingRequestContext rc =
SlingRequestContext.fromRequest(request);
+ if(rc == null) {
+ log.debug("No SlingRequestContext in request, cannot add {}
binding", RC_BINDING_NAME);
+ return;
+ }
+ b.put(RC_BINDING_NAME, rc);
+ }
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextBindingsValuesProvider.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.apache.sling.requestcontext.impl;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.sling.SlingFilter;
+import org.apache.felix.scr.annotations.sling.SlingFilterScope;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestPathInfo;
+import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
+import org.apache.sling.requestcontext.api.SlingRequestContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SlingFilter(
+ scope=SlingFilterScope.REQUEST,
+ order=Integer.MIN_VALUE,
+ description="Calls an optional request setup script and populates the
RequestContext")
+public class RequestContextFilter implements Filter {
+
+ public static final String SETUP_SCRIPT_EXTENSION = "setup";
+
+ private Logger log = LoggerFactory.getLogger(getClass());
+
+ @Reference
+ private ServletResolver servletResolver;
+
+ private static class RequestPathInfoWrapper implements RequestPathInfo {
+
+ private final RequestPathInfo wrapped;
+
+ RequestPathInfoWrapper(RequestPathInfo rpi) {
+ wrapped = rpi;
+ }
+
+ public String getExtension() {
+ return SETUP_SCRIPT_EXTENSION;
+ }
+
+ public String getResourcePath() {
+ return wrapped.getResourcePath();
+ }
+
+ public String getSelectorString() {
+ return wrapped.getSelectorString();
+ }
+
+ public String[] getSelectors() {
+ return wrapped.getSelectors();
+ }
+
+ public String getSuffix() {
+ return wrapped.getSuffix();
+ }
+
+ };
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
+ SlingHttpServletRequest slingRequest = null;
+ if(request instanceof SlingHttpServletRequest) {
+ slingRequest = (SlingHttpServletRequest)request;
+ setupRequestContext(slingRequest, response);
+ }
+ try {
+
RequestContextBindingsValuesProvider.requestThreadLocal.set(slingRequest);
+ chain.doFilter(request, response);
+ } finally {
+ RequestContextBindingsValuesProvider.requestThreadLocal.set(null);
+ }
+ }
+
+ public void destroy() {
+ }
+
+ void setupRequestContext(SlingHttpServletRequest slingRequest,
ServletResponse servletResponse) {
+ if(!(servletResponse instanceof SlingHttpServletResponse)) {
+ log.debug("{} is not a SlingHttpServletResponse, cannot setup
RequestContext", servletResponse);
+ return;
+ }
+
+ final SlingHttpServletResponse slingResponse =
(SlingHttpServletResponse)servletResponse;
+
+ // Wrap the request so that we resolve a script for the setup extension
+ final SlingHttpServletRequest wrappedRequest = new
SlingHttpServletRequestWrapper(slingRequest) {
+ private final RequestPathInfo rpi = new
RequestPathInfoWrapper(super.getRequestPathInfo());
+
+ @Override
+ public RequestPathInfo getRequestPathInfo() {
+ return rpi;
+ }
+
+ };
+ final Servlet servlet = servletResolver.resolveServlet(wrappedRequest);
+
+ if(servlet == null) {
+ log.debug("No setup Servlet found that handles extension {} for
{}", SETUP_SCRIPT_EXTENSION, slingRequest);
+ } else if(servlet instanceof SlingScript){
+ final SlingScript script = (SlingScript)servlet;
+ final SlingBindings bindings = new SlingBindings();
+ bindings.setRequest(slingRequest);
+ bindings.setResource(slingRequest.getResource());
+ bindings.setResponse(slingResponse);
+ final SlingRequestContext rc = new
SlingRequestContext(slingRequest);
+ bindings.put("rc", rc);
+ log.debug("Executing {} to populate {}", script, rc);
+ script.eval(bindings);
+ } else {
+ log.debug("{} does not implement SlingScript, cannot use it to
setup RequestContext");
+ }
+ }
+
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/java/org/apache/sling/requestcontext/impl/RequestContextFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,4 @@
+{
+ "sling:resourceType" : "requestcontext",
+ "jcr:description" : "a test node for the request context mechanism - request
this node with .html to trigger the setup.ecma and html.esp rendering"
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext.json
------------------------------------------------------------------------------
svn:eol-style = native
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,24 @@
+<html>
+<!--
+ This is a standard rendering script but it uses the
+ request context provided by the "rc" script binding.
+ The rc.u ("user") part of that is populated by the
+ setup.ecma script that's executed before this.
+-->
+<body>
+
+<h1><%= rc.u.title %></h1>
+
+random from rc.u = <%= rc.u.random %>
+<br/>
+
+compute function in rc.u = <%= rc.u.compute("something") %>
+<br/>
+
+resourceType from rc = <%= rc.resourceType %>
+<br/>
+
+resource property from rc.r = <%= rc.r["jcr:description"] %>
+
+</body>
+</html>
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/html.esp
------------------------------------------------------------------------------
svn:executable = *
Added:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma?rev=1547985&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma
(added)
+++
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma
Thu Dec 5 01:32:21 2013
@@ -0,0 +1,21 @@
+// This is called before the standard Sling rendering script,
+// by resolving the current request as if it was made with
+// a ".setup" extension.
+//
+// Such a setup script will usually add properties to the
+// rc.u ("user") space of the request context, which are
+// used by rendering scripts.
+//
+rc.u.title = "Here's the title for " + rc.path + ", computed at " + new Date();
+rc.u.random = Math.random();
+rc.u.compute = function(info) { return "Hello the resource type is " +
rc.resourceType + " and the info is " + info; }
+
+// Redirects and send error response can also happen here
+if(request.getParameter("redirect")) {
+ response.sendRedirect("http://www.perdu.com");
+}
+
+var status = request.getParameter("httpStatus");
+if(status) {
+ response.sendError(status, "Status set by request parameter: " + status);
+}
Propchange:
sling/whiteboard/bdelacretaz/request-context/src/main/resources/SLING-CONTENT/apps/requestcontext/setup.ecma
------------------------------------------------------------------------------
svn:executable = *