jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r157746 [2/2] - in incubator/jackrabbit/trunk/contrib/jcr-server: client/ server/ server/src/java/org/apache/jackrabbit/server/ server/src/java/org/apache/jackrabbit/server/simple/ server/src/java/org/apache/jackrabbit/server/simple/dav/ server/src/java/org/apache/jackrabbit/webdav/spi/ server/src/java/org/apache/jackrabbit/webdav/spi/nodetype/ server/src/java/org/apache/jackrabbit/webdav/spi/property/ webapp/ webdav/ webdav/src/java/org/apache/jackrabbit/webdav/ webdav/src/java/org/apache/jackrabbit/webdav/header/
Date Wed, 16 Mar 2005 13:36:14 GMT
Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java?view=diff&r1=157745&r2=157746
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/MultiStatusResponse.java
Wed Mar 16 05:36:05 2005
@@ -30,7 +30,7 @@
 public class MultiStatusResponse implements DavConstants {
 
     /**
-     * The content the 'href' element for this resposne
+     * The content the 'href' element for this response
      */
     private final String href;
 
@@ -45,9 +45,9 @@
     private final Element status404;
 
     /**
-     * Hashmap with all stati
+     * Hashmap containing all status
      */
-    private final HashMap stati = new HashMap();
+    private final HashMap statusMap = new HashMap();
 
     /**
      * An optional response description.
@@ -61,8 +61,8 @@
         this.href = href;
         status200 = new Element(XML_PROP, NAMESPACE);
         status404 = new Element(XML_PROP, NAMESPACE);
-        stati.put(new Integer(DavServletResponse.SC_OK), status200);
-        stati.put(new Integer(DavServletResponse.SC_NOT_FOUND), status404);
+        statusMap.put(new Integer(DavServletResponse.SC_OK), status200);
+        statusMap.put(new Integer(DavServletResponse.SC_NOT_FOUND), status404);
     }
 
     /**
@@ -129,7 +129,7 @@
     */
     public MultiStatusResponse(String href, int status) {
         this(href);
-        stati.put(new Integer(status), new Element(null));
+        statusMap.put(new Integer(status), new Element(null));
     }
 
     /**
@@ -140,10 +140,10 @@
      */
     private void add(Element prop, int status) {
         Integer statusKey = new Integer(status);
-        Element propsContainer = (Element) stati.get(statusKey);
+        Element propsContainer = (Element) statusMap.get(statusKey);
         if (propsContainer == null) {
             propsContainer = new Element(XML_PROP, NAMESPACE);
-            stati.put(statusKey, propsContainer);
+            statusMap.put(statusKey, propsContainer);
         }
         propsContainer.addContent(prop);
     }
@@ -214,10 +214,10 @@
         response.addContent(XmlUtil.hrefToXml(href));
 
         // add '<propstat>' elements or a single '<status>' element
-        Iterator iter = stati.keySet().iterator();
+        Iterator iter = statusMap.keySet().iterator();
         while (iter.hasNext()) {
             Integer statusKey = (Integer) iter.next();
-	    Element prop = (Element) stati.get(statusKey);
+	    Element prop = (Element) statusMap.get(statusKey);
             if (prop != null) {
                 Element status = new Element(XML_STATUS, NAMESPACE);
                 status.setText("HTTP/1.1 " + statusKey + " " + DavException.getStatusPhrase(statusKey.intValue()));

Modified: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java?view=diff&r1=157745&r2=157746
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/WebdavRequestImpl.java
Wed Mar 16 05:36:05 2005
@@ -26,6 +26,7 @@
 import org.apache.jackrabbit.webdav.version.*;
 import org.apache.jackrabbit.webdav.version.report.ReportInfo;
 import org.apache.jackrabbit.webdav.ordering.*;
+import org.apache.jackrabbit.webdav.header.DepthHeader;
 import org.jdom.input.SAXBuilder;
 import org.jdom.JDOMException;
 import org.jdom.Document;
@@ -179,9 +180,7 @@
      * @see DavServletRequest#getDepth(int)
      */
     public int getDepth(int defaultValue) {
-	String dHeader = httpRequest.getHeader(DavConstants.HEADER_DEPTH);
-	int depth = depthToInt(dHeader, defaultValue);
-	return depth;
+	return DepthHeader.parse(httpRequest.getHeader(DavConstants.HEADER_DEPTH), defaultValue).getDepth();
     }
 
     /**
@@ -245,9 +244,9 @@
         Document requestDocument = null;
         // try to parse the request body
         try {
-            SAXBuilder builder = new SAXBuilder(false);
             InputStream in = httpRequest.getInputStream();
             if (in != null) {
+		SAXBuilder builder = new SAXBuilder(false);
                 requestDocument = builder.build(in);
             }
         } catch (IOException e) {
@@ -507,30 +506,8 @@
 	}
 	return headerValue;
     }
-
-    /**
-     * Convert the String depth value to an integer.
-     *
-     * @param depth
-     * @param defaultValue
-     * @return integer representation of the given depth String or the given
-     * defaultValue if depth is <code>null</code> or invalid.
-     */
-    private static int depthToInt(String depth, int defaultValue) {
-        int d = defaultValue;
-        if (depth != null) {
-            if (depth.equalsIgnoreCase("infinity")) {
-                d = DavConstants.DEPTH_INFINITY;
-            } else if (depth.equals("0")) {
-                d = DavConstants.DEPTH_0;
-            } else if (depth.equals("1")) {
-                d = DavConstants.DEPTH_1;
-            }
-        }
-        return d;
-    }
-
-        //-----------------------------< TransactionDavServletRequest Interface >---
+    
+    //-----------------------------< TransactionDavServletRequest Interface >---
     /**
      *
      * @return

Added: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java?view=auto&rev=157746
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
Wed Mar 16 05:36:05 2005
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.jackrabbit.webdav.header;
+
+import org.apache.log4j.Logger;
+import org.apache.jackrabbit.webdav.DavConstants;
+
+/**
+ * <code>DepthHeader</code>...
+ */
+public class DepthHeader implements DavConstants {
+
+    private static Logger log = Logger.getLogger(DepthHeader.class);
+
+    private final int depth;
+
+    /**
+     * Create a new <code>DepthHeader</code> from the given integer.
+     *
+     * @param depth
+     */
+    public DepthHeader(int depth) {
+	if (depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1 || depth == DavConstants.DEPTH_INFINITY)
{
+	    this.depth = depth;
+	} else {
+	    throw new IllegalArgumentException("Invalid depth: " + depth);
+	}
+    }
+
+    /**
+     * @return integer representation of the depth indicated by the given header.
+     */
+    public int getDepth() {
+        return depth;
+    }
+
+    /**
+     * Return {@link DavConstants#HEADER_DEPTH Depth}
+     *
+     * @return {@link DavConstants#HEADER_DEPTH Depth}
+     * @see DavConstants#HEADER_DEPTH
+     */
+    public String getHeaderName() {
+	return DavConstants.HEADER_DEPTH;
+    }
+
+    /**
+     * Returns the header value.
+     *
+     * @return header value
+     */
+    public String getHeaderValue() {
+        if (depth == DavConstants.DEPTH_0 || depth == DavConstants.DEPTH_1) {
+	    return depth + "";
+	} else {
+	    return DavConstants.DEPTH_INFINITY_S;
+	}
+    }
+
+    /**
+     * Parse the given header value or use the defaultValue if the header
+     * string is empty or <code>null</code>.
+     *
+     * @param headerValue
+     * @param defaultValue
+     * @return a new DepthHeader
+     */
+    public static DepthHeader parse(String headerValue, int defaultValue) {
+        if (headerValue == null || "".equals(headerValue)) {
+	    return new DepthHeader(defaultValue);
+	} else {
+	    return new DepthHeader(depthToInt(headerValue));
+	}
+    }
+
+    /**
+     * Convert the String depth value to an integer.
+     *
+     * @param depth
+     * @return integer representation of the given depth String
+     * @throws IllegalArgumentException if the String does not represent a valid
+     * depth.
+     */
+    private static int depthToInt(String depth) {
+        int d;
+	if (depth.equalsIgnoreCase(DavConstants.DEPTH_INFINITY_S)) {
+	    d = DavConstants.DEPTH_INFINITY;
+	} else if (depth.equals(DavConstants.DEPTH_0+"")) {
+	    d = DavConstants.DEPTH_0;
+	} else if (depth.equals(DavConstants.DEPTH_1+"")) {
+	    d = DavConstants.DEPTH_1;
+	} else {
+	    throw new IllegalArgumentException("Invalid depth value: " + depth);
+	}
+        return d;
+    }
+}
\ No newline at end of file

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
------------------------------------------------------------------------------
    svn = 

Propchange: incubator/jackrabbit/trunk/contrib/jcr-server/webdav/src/java/org/apache/jackrabbit/webdav/header/DepthHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message