incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r693854 - in /incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get: DefaultGetServlet.java helpers/XMLRendererServlet.java
Date Wed, 10 Sep 2008 14:33:10 GMT
Author: cziegeler
Date: Wed Sep 10 07:33:09 2008
New Revision: 693854

URL: http://svn.apache.org/viewvc?rev=693854&view=rev
Log:
SLING-393 : Implement first version of a default xml get servlet

Added:
    incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
  (with props)
Modified:
    incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/DefaultGetServlet.java

Modified: incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/DefaultGetServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/DefaultGetServlet.java?rev=693854&r1=693853&r2=693854&view=diff
==============================================================================
--- incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/DefaultGetServlet.java
(original)
+++ incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/DefaultGetServlet.java
Wed Sep 10 07:33:09 2008
@@ -33,20 +33,21 @@
 import org.apache.sling.servlets.get.helpers.JsonRendererServlet;
 import org.apache.sling.servlets.get.helpers.PlainTextRendererServlet;
 import org.apache.sling.servlets.get.helpers.StreamRendererServlet;
+import org.apache.sling.servlets.get.helpers.XMLRendererServlet;
 
 /**
  * A SlingSafeMethodsServlet that renders the current Resource as simple HTML
- * 
+ *
  * @scr.component immediate="true" metatype="no"
  * @scr.service interface="javax.servlet.Servlet"
- * 
+ *
  * @scr.property name="service.description" value="Default GET Servlet"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
- * 
+ *
  * Use this as a default servlet for Sling
  * @scr.property name="sling.servlet.resourceTypes"
  *               value="sling/servlet/default"
- *               
+ *
  * Generic handler for all get requests
  * @scr.property name="sling.servlet.methods" value="GET"
  */
@@ -71,6 +72,8 @@
             new JsonRendererServlet());
         setupServlet(rendererMap, StreamRendererServlet.EXT_RES,
             new StreamRendererServlet());
+        setupServlet(rendererMap, XMLRendererServlet.EXT_XML,
+                new XMLRendererServlet());
 
         // use the servlet for rendering StreamRendererServlet.EXT_RES as the
         // streamer servlet
@@ -107,7 +110,7 @@
             return;
         }
 
-        request.getRequestProgressTracker().log("Using " 
+        request.getRequestProgressTracker().log("Using "
                 + rendererServlet.getClass().getName()
                 + " to render for extension=" + ext);
         rendererServlet.service(request, response);

Added: incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java?rev=693854&view=auto
==============================================================================
--- incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
(added)
+++ incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
Wed Sep 10 07:33:09 2008
@@ -0,0 +1,85 @@
+/*
+ * 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.servlets.get.helpers;
+
+import java.io.IOException;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.SlingConstants;
+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.ResourceNotFoundException;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+
+/**
+ * The <code>XMLRendererServlet</code> renders the current resource in XML
+ * on behalf of the {@link org.apache.sling.servlets.get.DefaultGetServlet}.
+ *
+ * At the moment only JCR nodes can be rendered as XML.
+ */
+public class XMLRendererServlet extends SlingSafeMethodsServlet {
+
+    public static final String EXT_XML = "xml";
+
+    private static final String responseContentType = "text/xml";
+
+    private static final String SYSVIEW = "sysview";
+    private static final String DOCVIEW = "docview";
+
+    @Override
+    protected void doGet(SlingHttpServletRequest req,
+                         SlingHttpServletResponse resp)
+    throws ServletException, IOException {
+        final Resource r = req.getResource();
+
+        if (ResourceUtil.isNonExistingResource(r)) {
+            throw new ResourceNotFoundException("No data to render.");
+        }
+
+        resp.setContentType(responseContentType);
+        resp.setCharacterEncoding("UTF-8");
+
+        // are we included?
+        final boolean isIncluded = req.getAttribute(SlingConstants.ATTR_REQUEST_SERVLET)
!= null;
+
+        final Node node = r.adaptTo(Node.class);
+        if ( node != null ) {
+            try {
+                if ( req.getRequestPathInfo().getSelectorString() == null
+                     || req.getRequestPathInfo().getSelectorString().equals(DOCVIEW) ) {
+                    node.getSession().exportDocumentView(node.getPath(), resp.getOutputStream(),
false, false);
+                } else if ( req.getRequestPathInfo().getSelectorString().equals(SYSVIEW)
) {
+                    node.getSession().exportSystemView(node.getPath(), resp.getOutputStream(),
false, false);
+                } else {
+                    resp.sendError(HttpServletResponse.SC_NO_CONTENT); // NO Content
+                }
+            } catch (RepositoryException e) {
+                throw new ServletException("Unable to export node as document view.", e);
+            }
+        } else {
+            if ( !isIncluded ) {
+                resp.sendError(HttpServletResponse.SC_NO_CONTENT); // NO Content
+            }
+        }
+    }
+}

Propchange: incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: incubator/sling/trunk/servlets/get/src/main/java/org/apache/sling/servlets/get/helpers/XMLRendererServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message