jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r687316 - in /jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr: DefaultItemCollection.java DefaultItemResource.java JcrValueType.java
Date Wed, 20 Aug 2008 13:12:45 GMT
Author: angela
Date: Wed Aug 20 06:12:44 2008
New Revision: 687316

URL: http://svn.apache.org/viewvc?rev=687316&view=rev
Log:
JCR-1300: spi2dav Improve performance for large binary properties

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java?rev=687316&r1=687315&r2=687316&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemCollection.java
Wed Aug 20 06:12:44 2008
@@ -81,6 +81,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
@@ -400,8 +402,28 @@
                 if (in == null) {
                     // PUT: not possible without request body
                     throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Cannot create
a new non-collection resource without request body.");
+                }
+                // PUT : create new or overwrite existing property.
+                String ct = inputContext.getContentType();
+                int type = JcrValueType.typeFromContentType(ct);
+                if (type != PropertyType.UNDEFINED) {
+                    // no need to create value/values property. instead
+                    // prop-value can be retrieved directly:
+                    int pos = ct.indexOf(';');
+                    String charSet = (pos > -1) ? ct.substring(pos) : "UTF-8";
+                    if (type == PropertyType.BINARY) {
+                        n.setProperty(memberName, inputContext.getInputStream());
+                    } else {
+                        BufferedReader r = new BufferedReader(new InputStreamReader(inputContext.getInputStream(),
charSet));
+                        String line;
+                        StringBuffer value = new StringBuffer();
+                        while ((line = r.readLine()) != null) {
+                            value.append(line);
+                        }
+                        n.setProperty(memberName, value.toString(), type);
+                    }
                 } else {
-                    // PUT : create new or overwrite existing property.
+                    // try to parse the request body into a 'values' property.
                     tmpFile = File.createTempFile(TMP_PREFIX + Text.escape(memberName), null,
null);
                     FileOutputStream out = new FileOutputStream(tmpFile);
                     IOUtil.spool(in, out);

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java?rev=687316&r1=687315&r2=687316&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/DefaultItemResource.java
Wed Aug 20 06:12:44 2008
@@ -302,14 +302,14 @@
 
                 // set the content type
                 String contentType;
-                if (!isMultiple()) {
-                    contentType = (type == PropertyType.BINARY) ? "application/octet-stream"
: "text/plain";
+                if (isMultiple()) {
+                    contentType = IOUtil.buildContentType("text/xml","utf-8");
                 } else {
-                    contentType = "text/xml";
+                    contentType = IOUtil.buildContentType(JcrValueType.contentTypeFromType(type),
"utf-8");
+
                 }
                 properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTTYPE, contentType));
 
-
                 // add jcr-specific resource properties
                 properties.add(new DefaultDavProperty(JCR_TYPE, PropertyType.nameFromValue(type)));
                 if (isMultiple()) {
@@ -319,9 +319,6 @@
                     properties.add(new ValuesProperty(prop.getValue()));
                     long length = prop.getLength();
                     properties.add(new DefaultDavProperty(JCR_LENGTH, String.valueOf(length),
true));
-                    if (prop.getLength() > IOUtil.UNDEFINED_LENGTH) {
-                        properties.add(new DefaultDavProperty(DavPropertyName.GETCONTENTLENGTH,
String.valueOf(length)));
-                    }
                 }
             } catch (RepositoryException e) {
                 log.error("Failed to retrieve resource properties: "+e.getMessage());

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java?rev=687316&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
(added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
Wed Aug 20 06:12:44 2008
@@ -0,0 +1,67 @@
+/*
+ * 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.jackrabbit.webdav.jcr;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.PropertyType;
+
+/** <code>JcrValueType</code>... */
+public final class JcrValueType {
+
+    private static Logger log = LoggerFactory.getLogger(JcrValueType.class);
+
+    /**
+     * Fragment for build the content type of request entities representing
+     * a JCR-value. The fragment must be completed as follows:
+     * <pre>
+     * jcr-value/ + Value.getType().toLowerCase()
+     * </pre>
+     *
+     * resulting in the following types:
+     * <pre>
+     * jcr-value/string
+     * jcr-value/boolean
+     * jcr-value/long
+     * jcr-value/double
+     * jcr-value/date
+     * jcr-value/binary
+     * jcr-value/date
+     * jcr-value/name
+     * jcr-value/path
+     * </pre>
+     */
+    private static final String VALUE_CONTENT_TYPE_FRAGMENT = "jcr-value/";
+
+    public static String contentTypeFromType(int propertyType) {
+        return VALUE_CONTENT_TYPE_FRAGMENT + PropertyType.nameFromValue(propertyType).toLowerCase();
+    }
+
+    public static int typeFromContentType(String contentType) {
+        if (contentType != null && contentType.startsWith(VALUE_CONTENT_TYPE_FRAGMENT))
{
+            // no need to create value/values property. instead
+            // prop-value can be retrieved directly:
+            int pos = contentType.indexOf('/');
+            int pos2 = contentType.indexOf(';');
+
+            String typename = contentType.substring(pos+1, pos+2).toUpperCase() + contentType.substring(pos+2,
(pos2 > -1) ? pos2 : contentType.length());
+            return PropertyType.valueFromName(typename);
+        }
+        return PropertyType.UNDEFINED;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrValueType.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message