incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r816584 - in /sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl: JsonQueryServlet.java helpers/JsonResourceWriter.java helpers/XMLRendererServlet.java
Date Fri, 18 Sep 2009 11:24:30 GMT
Author: cziegeler
Date: Fri Sep 18 11:24:30 2009
New Revision: 816584

URL: http://svn.apache.org/viewvc?rev=816584&view=rev
Log:
Some code cleanup.

Modified:
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java
    sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/XMLRendererServlet.java

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java?rev=816584&r1=816583&r2=816584&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/JsonQueryServlet.java
Fri Sep 18 11:24:30 2009
@@ -19,8 +19,6 @@
 package org.apache.sling.servlets.get.impl;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -34,7 +32,6 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
 import org.apache.sling.commons.json.JSONException;
 import org.apache.sling.commons.json.io.JSONWriter;
@@ -84,13 +81,13 @@
 
     /** rep:exerpt */
     private static final String REP_EXCERPT = "rep:excerpt()";
-    
+
     private final JsonResourceWriter itemWriter;
 
     public JsonQueryServlet() {
         itemWriter = new JsonResourceWriter(null);
-    }    
-    
+    }
+
     @Override
     protected void doGet(SlingHttpServletRequest req,
             SlingHttpServletResponse resp) throws IOException {
@@ -115,7 +112,7 @@
 
             Iterator<Map<String, Object>> result = resolver.queryResources(
                 statement, queryType);
-          
+
 
             if (req.getParameter(OFFSET) != null) {
                 long skip = Long.parseLong(req.getParameter(OFFSET));
@@ -152,7 +149,7 @@
             while (result.hasNext() && count != 0) {
                 Map<String, Object> row = result.next();
 
-                
+
                 w.object();
                 String path = row.get("jcr:path").toString();
 
@@ -167,7 +164,7 @@
                         Object ev = row.get("rep:excerpt(" + exerptPath + ")");
                         strValue = (ev == null) ? "" : ev.toString();
                         w.value(strValue);
-                        
+
                     } else {
                         //strValue = formatValue(row.get(colName));
                     	itemWriter.dumpValue(w, row.get(colName));
@@ -182,8 +179,8 @@
                 }
 
                 w.endObject();
-                
-                
+
+
                 count--;
             }
             w.endArray();
@@ -201,7 +198,7 @@
         }
 
         itemWriter.dumpProperties(nodeRes, w, properties);
-        
+
     }
 
 
@@ -213,6 +210,6 @@
         log.warn("Error in QueryServlet: " + e.toString(), e);
         return new SlingException(e.toString(), e);
     }
-    
-    
+
+
 }

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java?rev=816584&r1=816583&r2=816584&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/JsonResourceWriter.java
Fri Sep 18 11:24:30 2009
@@ -36,9 +36,9 @@
 
 /**
  * Dumps JCR Items as JSON data. The dump methods are threadsafe.
- * 
- * Dump can be done on the Resource, property or value level. 
- * 
+ *
+ * Dump can be done on the Resource, property or value level.
+ *
  */
 public class JsonResourceWriter {
 
@@ -81,7 +81,7 @@
         jw.setTidy(tidy);
         dump(resource, jw, 0, maxRecursionLevels);
     }
-    
+
 
     /** Dump given resource in JSON, optionally recursing into its objects */
     protected void dump(Resource resource, JSONWriter w,
@@ -138,7 +138,7 @@
 
         w.endObject();
     }
-    
+
     /** Dump only a subset of the resource properties */
     public void dumpProperties(Resource resource, JSONWriter w,
             List<String> properties)
@@ -152,32 +152,31 @@
                 : resource.adaptTo(Map.class);
 
         if (propertyMap == null) {
-        	
-        	//TODO : not sure if we have to do something in this case ?
-        	return; 
 
-        } else {
+        	//TODO : not sure if we have to do something in this case ?
+        	return;
 
-            @SuppressWarnings("unchecked")
-            final Iterator<Map.Entry> props = propertyMap.entrySet().iterator();
+        }
 
-            // the node's actual properties
-            while (props.hasNext()) {
-                @SuppressWarnings("unchecked")
-                final Map.Entry prop = props.next();
+        @SuppressWarnings("unchecked")
+        final Iterator<Map.Entry> props = propertyMap.entrySet().iterator();
 
-                if (propertyNamesToIgnore != null
-                    && propertyNamesToIgnore.contains(prop.getKey())) {
-                    continue;
-                }
+        // the node's actual properties
+        while (props.hasNext()) {
+            @SuppressWarnings("unchecked")
+            final Map.Entry prop = props.next();
 
-                if (properties.contains(prop.getKey().toString()))
-                    writeProperty(w, valueMap, prop.getKey().toString(),
-                                  prop.getValue());
+            if (propertyNamesToIgnore != null
+                && propertyNamesToIgnore.contains(prop.getKey())) {
+                continue;
             }
+
+            if (properties.contains(prop.getKey().toString()))
+                writeProperty(w, valueMap, prop.getKey().toString(),
+                              prop.getValue());
         }
-    }        
-    
+    }
+
     /** Dump only a value in the correct format */
     public void dumpValue(JSONWriter w, Object value)
     throws JSONException {
@@ -198,7 +197,7 @@
             w.value(value.toString());
         }
     }
-    
+
     /** Dump a single node */
     protected void dumpSingleResource(Resource n, JSONWriter w,
             int currentRecursionLevel, int maxRecursionLevels)

Modified: sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/XMLRendererServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/XMLRendererServlet.java?rev=816584&r1=816583&r2=816584&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/XMLRendererServlet.java
(original)
+++ sling/trunk/bundles/servlets/get/src/main/java/org/apache/sling/servlets/get/impl/helpers/XMLRendererServlet.java
Fri Sep 18 11:24:30 2009
@@ -26,7 +26,6 @@
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.adapter.Adaptable;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceNotFoundException;
 import org.apache.sling.api.resource.ResourceUtil;
@@ -65,20 +64,19 @@
 
         final Node node = r.adaptTo(Node.class);
         if ( node != null ) {
-            // check if response is adaptable to a content handler
-            ContentHandler ch = null;
-            if ( resp instanceof Adaptable ) {
-                ch = ((Adaptable)resp).adaptTo(ContentHandler.class);
-            }
             try {
                 if ( req.getRequestPathInfo().getSelectorString() == null
                      || req.getRequestPathInfo().getSelectorString().equals(DOCVIEW) ) {
+                    // check if response is adaptable to a content handler
+                    final ContentHandler ch = resp.adaptTo(ContentHandler.class);
                     if ( ch == null ) {
                         node.getSession().exportDocumentView(node.getPath(), resp.getOutputStream(),
false, false);
                     } else {
                         node.getSession().exportDocumentView(node.getPath(), ch, false, false);
                     }
                 } else if ( req.getRequestPathInfo().getSelectorString().equals(SYSVIEW)
) {
+                    // check if response is adaptable to a content handler
+                    final ContentHandler ch = resp.adaptTo(ContentHandler.class);
                     if ( ch == null ) {
                         node.getSession().exportSystemView(node.getPath(), resp.getOutputStream(),
false, false);
                     } else {



Mime
View raw message