Author: cziegeler
Date: Thu Nov 22 14:28:55 2012
New Revision: 1412559
URL: http://svn.apache.org/viewvc?rev=1412559&view=rev
Log:
Add new SlingRequestDispatcher implementation
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
(with props)
Added:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java?rev=1412559&view=auto
==============================================================================
---
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
(added)
+++
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
Thu Nov 22 14:28:55 2012
@@ -0,0 +1,97 @@
+/*
+ * 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.portal.container.internal.services;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ResourceWrapper;
+import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
+import org.apache.sling.portal.container.api.SlingRequestDispatcher;
+
+public class SlingRequestDispatcherImpl implements SlingRequestDispatcher {
+
+ String OPTION_RESOURCE_TYPE = "resourceType";
+
+ String OPTION_EXTENSION = "extension";
+
+ String OPTION_SELECTOR = "selector";
+
+ private final SlingHttpServletRequest request;
+
+ private final SlingHttpServletResponse response;
+
+ public SlingRequestDispatcherImpl(final SlingHttpServletRequest request,
+ final SlingHttpServletResponse response) {
+ this.request = request;
+ this.response = response;
+ }
+
+ public void include(final PrintWriter writer, final Map<String, Object>
options)
+ throws IOException, ServletException {
+ String path = (String) options.get(OPTION_PATH);
+ if ( path == null ) {
+ final String rel = (String) options.get(OPTION_RELATIVE_PATH);
+ if ( rel == null ) {
+ path = this.request.getResource().getPath();
+ } else {
+ path = this.request.getResource().getPath() + '/' + rel;
+ }
+ }
+ final String resourcePath = path;
+ final String resourceType = (String) options.get(OPTION_RESOURCE_TYPE)
;
+ Resource rsrc = this.request.getResourceResolver().getResource(path);
+ if ( rsrc == null ) {
+ rsrc = new ResourceWrapper(this.request.getResource()) {
+ @Override
+ public String getResourceType() {
+ return resourceType == null ?
request.getResource().getResourceType() : resourceType;
+ }
+
+ @Override
+ public String getPath() {
+ return resourcePath;
+ }
+
+ public Resource getParent() {
+ return
request.getResourceResolver().getResource(ResourceUtil.getParent(resourcePath));
+ }
+
+ public String getName() {
+ return ResourceUtil.getName(resourcePath);
+ }
+
+ };
+ }
+ final SlingHttpServletResponse res = new
SlingHttpServletResponseWrapper(response) {
+
+ @Override
+ public PrintWriter getWriter() throws IOException {
+ return writer;
+ }
+
+ };
+ this.request.getRequestDispatcher(rsrc).include(request, res);
+ }
+}
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/whiteboard/portal/container/src/main/java/org/apache/sling/portal/container/internal/services/SlingRequestDispatcherImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain