jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r738480 [1/3] - in /jackrabbit/sandbox/spi: ./ spi2davex/ spi2davex/src/ spi2davex/src/main/ spi2davex/src/main/java/ spi2davex/src/main/java/org/ spi2davex/src/main/java/org/apache/ spi2davex/src/main/java/org/apache/jackrabbit/ spi2davex/...
Date Wed, 28 Jan 2009 13:35:48 GMT
Author: angela
Date: Wed Jan 28 13:35:47 2009
New Revision: 738480

URL: http://svn.apache.org/viewvc?rev=738480&view=rev
Log:
JCR-1958: Enhanced JCR remoting (client sided part. work in progress)

Added:
    jackrabbit/sandbox/spi/spi2davex/   (with props)
    jackrabbit/sandbox/spi/spi2davex/pom.xml   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/
    jackrabbit/sandbox/spi/spi2davex/src/main/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/QValueFactoryImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/RepositoryServiceImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ValueLoader.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/BatchTest.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/ConnectionTest.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/DummyJSONHandler.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/JSONParserTest.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/ReadTest.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/ServiceStubImpl.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/java/org/apache/jackrabbit/spi/spi2davex/TestAll.java   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/log4j.properties   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/apache/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/apache/jackrabbit/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/apache/jackrabbit/spi/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/apache/jackrabbit/spi/spi2davex/
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/org/apache/jackrabbit/spi/spi2davex/image.bmp   (with props)
    jackrabbit/sandbox/spi/spi2davex/src/test/resources/repositoryServiceStubImpl.properties   (with props)
Modified:
    jackrabbit/sandbox/spi/pom.xml

Modified: jackrabbit/sandbox/spi/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/pom.xml?rev=738480&r1=738479&r2=738480&view=diff
==============================================================================
--- jackrabbit/sandbox/spi/pom.xml (original)
+++ jackrabbit/sandbox/spi/pom.xml Wed Jan 28 13:35:47 2009
@@ -36,6 +36,7 @@
   
   <modules>
     <module>spi2dav</module>
+    <module>spi2davex</module>
     <module>spi-rmi</module>
     <module>client</module>
     <module>spi-logger</module>
@@ -302,6 +303,12 @@
         <version>1.4</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>org.json</groupId>
+        <artifactId>json</artifactId>
+        <version>20070829</version>
+        <scope>test</scope>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 </project>

Propchange: jackrabbit/sandbox/spi/spi2davex/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Jan 28 13:35:47 2009
@@ -0,0 +1,6 @@
+target
+*.log
+*.iws
+*.ipr
+*.iml
+junit*.properties

Added: jackrabbit/sandbox/spi/spi2davex/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/pom.xml?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/pom.xml (added)
+++ jackrabbit/sandbox/spi/spi2davex/pom.xml Wed Jan 28 13:35:47 2009
@@ -0,0 +1,155 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+   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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+                             http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+<!-- ====================================================================== -->
+<!-- P A R E N T  P R O J E C T  D E S C R I P T I O N                      -->
+<!-- ====================================================================== -->
+  <parent>
+    <groupId>org.apache.jackrabbit</groupId>
+    <artifactId>jackrabbit-spi-contrib</artifactId>
+    <version>1.6-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent>
+
+<!-- ====================================================================== -->
+<!-- P R O J E C T  D E S C R I P T I O N                                   -->
+<!-- ====================================================================== -->
+  <artifactId>jackrabbit-spi-spi2davex</artifactId>
+  <packaging>jar</packaging>
+  
+  <name>SPI 2 Webdav - Extended</name>
+  <description>Extension of the spi2dav implementation, using JSON for batch-read 
+     and a custom JSON-based DIFF format for batch-write.
+  </description>
+  
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/spi2davex
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/jackrabbit/sandbox/spi/spi2davex
+    </developerConnection>
+    <url>http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex</url>
+  </scm>
+
+    <!-- ====================================================================== -->
+    <!-- B U I L D   D E F I N I T I O N                                        -->
+    <!-- ====================================================================== -->
+    <build>
+        <plugins>
+            <plugin>
+                <inherited>true</inherited>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <target>1.4</target>
+                    <source>1.4</source>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <skip>true</skip>
+                    <includes>
+                        <include>**/TestAll.java</include>
+                    </includes>
+                    <forkMode>once</forkMode>
+                    <argLine>-Xmx128m -enableassertions</argLine>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <!-- ====================================================================== -->
+    <!-- D E P E N D E N C I E S                                                -->
+    <!-- ====================================================================== -->
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <classifier></classifier>
+            <version>${project.parent.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi-commons</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-jcr-commons</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi-spi2dav</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-webdav</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-jcr-server</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>xerces</groupId>
+                    <artifactId>xercesImpl</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.jackrabbit</groupId>
+            <artifactId>jackrabbit-spi</artifactId>
+            <classifier>tests</classifier>
+            <version>${project.parent.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.spi.spi2davex;
+
+import javax.jcr.NamespaceException;
+
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.PathResolver;
+
+/**
+ * <code>BatchReadConfig</code> defines if and how deep child item
+ * information should be retrieved, when accessing a <code>Node</code>.
+ * The configuration is based on path.
+ */
+public interface BatchReadConfig {
+
+    /**
+     * Return the depth for the given path.
+     *
+     * @param path
+     * @param resolver
+     * @return -1 if all child infos should be return or any value greater
+     * than -1 if only parts of the subtree should be returned. If there is no
+     * matching configuration entry some implementation specific default depth
+     * will be returned.
+     */
+    public int getDepth(Path path, PathResolver resolver) throws NamespaceException;
+
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BatchReadConfig.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.commons.httpclient.methods.multipart.PartSource;
+import org.apache.jackrabbit.spi.QValue;
+
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * <code>BinaryPartSource</code>...
+ */
+public class BinaryPartSource implements PartSource {
+
+    private final QValue value;
+
+    BinaryPartSource(QValue value) {
+        this.value = value;
+    }
+
+    public long getLength() {
+        try {
+            return value.getLength();
+        } catch (RepositoryException e) {
+            throw new IllegalStateException(e.getMessage());
+        }
+    }
+
+    public String getFileName() {
+        return value.toString();
+    }
+
+    public InputStream createInputStream() throws IOException {
+        try {
+            return value.getStream();
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/BinaryPartSource.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,124 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+
+/** <code>ChildInfoImpl</code>... */
+public class ChildInfoImpl implements ChildInfo {
+
+    /**
+     * The name of this child info.
+     */
+    private final Name name;
+
+    /**
+     * The unique id for this child info or <code>null</code> if it does not
+     * have a unique id.
+     */
+    private final String uniqueId;
+
+    /**
+     * 1-based index of this child info.
+     */
+    private final int index;
+
+    private int hashCode;
+
+    /**
+     * Creates a new serializable <code>ChildInfoImpl</code>.
+     *
+     * @param name     the name of the child node.
+     * @param uniqueId the unique id of the child node or <code>null</code>.
+     * @param index    the index of the child node.
+     */
+    public ChildInfoImpl(Name name, String uniqueId, int index) {
+        if (name == null || index < Path.INDEX_UNDEFINED) {
+            throw new IllegalArgumentException();
+        }
+        this.name = name;
+        this.uniqueId = uniqueId;
+        this.index = (index == Path.INDEX_UNDEFINED) ? Path.INDEX_DEFAULT : index;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getUniqueID() {
+        return uniqueId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getIndex() {
+        return index;
+    }
+
+    //-------------------------------------------------------------< Object >---
+    /**
+     * @see Object#hashCode()
+     */
+    public int hashCode() {
+        // build hashCode (format: <name>/<name>/<index>/<uniqueID>)
+        if (hashCode == 0) {
+            StringBuffer sb = new StringBuffer();
+            sb.append(name.toString());
+            sb.append(index);
+            if (uniqueId != null) {
+                sb.append(uniqueId);
+            }
+            hashCode = sb.toString().hashCode();
+        }
+        return hashCode;
+    }
+
+    /**
+     * @see Object#equals(Object)
+     */
+    public boolean equals(Object object) {
+        if (object == this) {
+            return true;
+        }
+        if (object instanceof ChildInfoImpl) {
+            ChildInfoImpl ci = (ChildInfoImpl) object;
+            boolean sameUID = (uniqueId == null) ? ci.uniqueId == null : uniqueId.equals(ci.uniqueId);
+            return sameUID && name.equals(ci.name) && index == ci.index;
+        }
+        return false;
+    }
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString() {
+        StringBuffer sb = new StringBuffer();
+        sb.append(name.toString());
+        sb.append(" : ").append(index);
+        sb.append(" : ").append((uniqueId == null) ? "-" : uniqueId);
+        return sb.toString();
+    }
+}

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ChildInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.webdav.DavMethods;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <code>GetMethod</code>...
+ */
+class GetMethod extends DavMethodBase {
+
+    private static Logger log = LoggerFactory.getLogger(GetMethod.class);
+
+    public GetMethod(String uri) {
+        super(uri);
+    }
+
+    public String getName() {
+        return DavMethods.METHOD_GET;
+    }
+
+    protected boolean isSuccess(int statusCode) {
+        return statusCode == DavServletResponse.SC_OK;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/GetMethod.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.spi.ItemInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+
+import javax.jcr.RepositoryException;
+import java.io.Serializable;
+
+/**
+ * <code>ItemInfoImpl</code> is a base class for <code>ItemInfo</code>
+ * implementations.
+ */
+public abstract class ItemInfoImpl implements ItemInfo, Serializable {
+
+    /**
+     * The path of this item info.
+     */
+    private final Path path;
+
+    /**
+     * Flag indicating whether this is a node or a property info.
+     */
+    private final boolean isNode;
+
+    /**
+     * Creates a new serializable item info for the given qualified
+     * <code>item</code> info.
+     *
+     * @param path     the path to this item.
+     * @param isNode   if this item is a node.
+     * @throws javax.jcr.RepositoryException
+     */
+    public ItemInfoImpl(Path path, boolean isNode) throws RepositoryException {
+        if (path == null) {
+            throw new RepositoryException();
+        }
+        this.path = path;
+        this.isNode = isNode;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Name getName() {
+        return path.getNameElement().getName();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean denotesNode() {
+        return isNode;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getPath() {
+        return path;
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,316 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.util.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Stack;
+
+/**
+ * <code>ItemInfoJSONHandler</code>...
+ */
+class ItemInfoJSONHandler implements JSONHandler {
+
+    private static Logger log = LoggerFactory.getLogger(ItemInfoJSONHandler.class);
+
+    private static final int SPECIAL_JSON_PAIR = Integer.MAX_VALUE;
+
+    private final List itemInfos;
+    private final NamePathResolver resolver;
+    private final String rootURI;
+
+    private final QValueFactoryImpl vFactory;
+    private final PathFactory pFactory;
+    private final IdFactory idFactory;
+
+    private Name name;
+    private int propertyType;
+    private int index = Path.INDEX_DEFAULT;
+
+    private Stack nodeInfos = new Stack();
+    private PropertyInfoImpl mvPropInfo;
+
+    ItemInfoJSONHandler(NamePathResolver resolver, NodeInfo nInfo,
+                        String rootURI,
+                        QValueFactoryImpl vFactory,
+                        PathFactory pFactory,
+                        IdFactory idFactory) {
+        this.resolver = resolver;
+        this.rootURI = rootURI;
+
+        this.vFactory = vFactory;
+        this.pFactory = pFactory;
+        this.idFactory = idFactory;
+
+        itemInfos = new ArrayList();
+        itemInfos.add(nInfo);
+        nodeInfos.push(nInfo);
+    }
+
+    public void object() throws IOException {
+        if (name != null) {
+            try {
+                NodeInfo current = getCurrentNodeInfo();
+                Path relPath = pFactory.create(name, index);
+                NodeId id = idFactory.createNodeId(current.getId(), relPath);
+                Path currentPath = current.getPath();
+                Path p = pFactory.create(currentPath, relPath, true);
+                NodeInfo nInfo = new NodeInfoImpl(id, p);
+                nodeInfos.push(nInfo);
+                itemInfos.add(nInfo);
+            } catch (RepositoryException e) {
+                throw new IOException(e.getMessage());
+            }
+        }
+    }
+
+    public void endObject() throws IOException {
+        try {
+            NodeInfoImpl nInfo = (NodeInfoImpl) nodeInfos.pop();
+            NodeInfo parent = getCurrentNodeInfo();
+            if (parent != null) {
+                if (nInfo.getPath().getAncestor(1).equals(parent.getPath())) {
+                    ChildInfo ci = new ChildInfoImpl(nInfo.getName(), nInfo.getUniqueID(), nInfo.getIndex());
+                    ((NodeInfoImpl) parent).addChildInfo(ci);
+                } else {
+                    log.debug("NodeInfo '"+ nInfo.getPath() + "' out of hierarchy. Parent path = " + parent.getPath());
+                }
+            }
+            if (!nInfo.isCompleted()) {
+                log.debug("Incomplete NodeInfo '"+ nInfo.getPath() + "' -> Only present as ChildInfo with its parent.");
+                itemInfos.remove(nInfo);
+            }
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void array() throws IOException {
+        try {
+            mvPropInfo = createPropertyInfo(null, true);
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void endArray() throws IOException {
+        try {
+            // make sure that type is set for mv-properties with empty value array.
+            if (propertyType == PropertyType.UNDEFINED &&
+                    mvPropInfo.numberOfValues() == 0) {
+                int type = vFactory.retrieveType(getValueURI());
+                mvPropInfo.setType(type);
+            }
+            mvPropInfo.checkCompleted();
+            getCurrentNodeInfo().addPropertyInfo(mvPropInfo, idFactory);
+            mvPropInfo = null;
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void key(String key) throws IOException {
+        try {
+            if (key.equals("::NodeIteratorSize")) {
+                propertyType = SPECIAL_JSON_PAIR;
+                // TODO: if additional JSON pairs are created -> set name
+            } else if (key.startsWith(":")) {
+                // binary property
+                name = resolver.getQName(key.substring(1));
+                propertyType = PropertyType.BINARY;
+                index = Path.INDEX_DEFAULT;
+            } else if (key.endsWith("]")) {
+                // sns-node name
+                int pos = key.lastIndexOf('[');
+                name = resolver.getQName(key.substring(0, pos));
+                propertyType = PropertyType.UNDEFINED;
+                index = Integer.parseInt(key.substring(pos + 1, key.length() - 1));
+            } else {
+                // either node or property
+                Name previousName = name;
+                name = resolver.getQName(key);
+                propertyType = guessPropertyType(name, previousName);
+                // property type is defined through json value OR special property
+                // :propertyName = type.
+                index = Path.INDEX_DEFAULT;
+            }
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void value(String value) throws IOException {
+        try {
+            QValue v;
+            switch (propertyType) {
+                case SPECIAL_JSON_PAIR:
+                    // currently no special boolean value pair -> ignore
+                    return;
+                case PropertyType.BINARY:
+                    // key started with ':' but value is String instead of
+                    // long. value therefore reflects the property type.
+                    // -> reset the property type.
+                    // -> omit creation of value AND call to value(QValue)
+                    propertyType = PropertyType.valueFromName(value);
+                    return;
+                case PropertyType.UNDEFINED:
+                    v = vFactory.create(value, PropertyType.STRING);
+                    break;
+                case PropertyType.NAME:
+                    v = vFactory.create(resolver.getQName(value));
+                    break;
+                case PropertyType.PATH:
+                    v = vFactory.create(resolver.getQPath(value));
+                    break;
+                default:
+                    v = vFactory.create(value, propertyType);
+            }
+            value(v);
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void value(boolean value) throws IOException {
+        if (propertyType == SPECIAL_JSON_PAIR) {
+            // currently no special boolean value pair -> ignore
+            return;
+        }
+        try {
+            value(vFactory.create(value));
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void value(long value) throws IOException {
+        if (propertyType == SPECIAL_JSON_PAIR) {
+            NodeInfoImpl parent = getCurrentNodeInfo();
+            if (parent != null) {
+                parent.setNumberOfChildNodes(value);
+            }
+            return;
+        }
+        try {
+            QValue v;
+            if (propertyType == PropertyType.BINARY) {
+                int indx = (mvPropInfo == null) ? -1 : mvPropInfo.numberOfValues();
+                v = vFactory.create(value, getValueURI(), indx);
+            } else {
+                v = vFactory.create(value);
+            }
+            value(v);
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    public void value(double value) throws IOException {
+        if (propertyType == SPECIAL_JSON_PAIR) {
+            // currently no special double value pair -> ignore
+            return;
+        }
+        try {
+            value(vFactory.create(value));
+        } catch (RepositoryException e) {
+            throw new IOException(e.getMessage());
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     *
+     * @param value
+     * @throws RepositoryException
+     */
+    private void value(QValue value) throws RepositoryException {
+        if (mvPropInfo == null) {
+            createPropertyInfo(value, false);
+        } else {
+            mvPropInfo.addValue(value);
+        }
+    }
+
+    Iterator getItemInfos() {
+        return Collections.unmodifiableList(itemInfos).iterator();
+    }
+
+    private NodeInfoImpl getCurrentNodeInfo() {
+        return  (nodeInfos.isEmpty()) ? (NodeInfoImpl) null : (NodeInfoImpl) nodeInfos.peek();
+    }
+
+    private PropertyInfoImpl createPropertyInfo(QValue value, boolean isMultiValued) throws RepositoryException {
+        NodeInfoImpl parent = getCurrentNodeInfo();
+        Path p = pFactory.create(parent.getPath(), name, true);
+        PropertyId id = idFactory.createPropertyId(parent.getId(), name);
+
+        PropertyInfoImpl pInfo;
+        if (isMultiValued) {
+            pInfo = new PropertyInfoImpl(id, p, propertyType);
+            // not added to parent but upon having read all values.
+        } else {
+            pInfo = new PropertyInfoImpl(id, p, propertyType, value);
+            parent.addPropertyInfo(pInfo, idFactory);
+        }
+        itemInfos.add(pInfo);
+        return pInfo;
+    }
+
+    private String getValueURI() throws RepositoryException {
+        Path propertyPath;
+        if (mvPropInfo == null) {
+            propertyPath = pFactory.create(getCurrentNodeInfo().getPath(), name, true);
+        } else {
+            propertyPath = mvPropInfo.getPath();
+        }
+        StringBuffer sb = new StringBuffer(rootURI);
+        sb.append(Text.escape(resolver.getJCRPath(propertyPath)));
+        return sb.toString();
+    }
+
+    private int guessPropertyType(Name name, Name previousName) {
+        if (name.equals(previousName)) {
+            // property has been previously retrieved from :name : "typeName"
+            // entry in the JSON string. if by coincidence the previous key
+            // is equal but belongs to an JSON object (-> node) the prop type
+            // has been reset to UNDEFINED anyway.
+            return propertyType;
+        } else {
+            // default: determine type upon Property.getType() only.
+            return PropertyType.UNDEFINED;
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/ItemInfoJSONHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,43 @@
+/*
+ * 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.spi.spi2davex;
+
+import java.io.IOException;
+
+/**
+ * <code>JSONHandler</code>...
+ */
+public interface JSONHandler {
+
+    void object() throws IOException;
+
+    void endObject() throws IOException;
+
+    void array() throws IOException;
+
+    void endArray() throws IOException;
+
+    void key(String key) throws IOException;
+
+    void value(String value) throws IOException;
+
+    void value(boolean value) throws IOException;
+
+    void value(long value) throws IOException;
+
+    void value(double value) throws IOException;
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,294 @@
+/*
+ * 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.spi.spi2davex;
+
+import java.io.BufferedReader;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.Stack;
+
+/**
+ * <code>JSONParser</code>...
+ */
+class JSONParser {
+
+    private static final String NULL = "null";
+    private static final int EOF = -1;
+
+    private static final int KEY_START = 0;
+    private static final int VALUE_START = 2;
+    private static final int VALUE = 4;
+
+    private static final Integer OBJECT = new Integer(32);
+    private static final Integer ARRAY = new Integer(64);
+
+    /* the handler */
+    private final JSONHandler handler;
+
+    /**
+     * Create a new <code>JSONParser</code> with the specified <code>JSONHandler</code>.
+     *
+     * @param jsonHandler A <code>JSONHandler</code>
+     */
+    JSONParser(JSONHandler jsonHandler) {
+        handler = jsonHandler;
+    }
+
+    /**
+     *
+     * @param str String to be parsed
+     * @throws IOException If an error occurs.
+     */
+    public void parse(String str) throws IOException {
+        parse(new BufferedReader(new StringReader(str)));
+    }
+
+    /**
+     *
+     * @param input InputStream to be parsed.
+     * @param charSetName Name of the charset to be used.
+     * @throws IOException If an error occurs.
+     */
+    public void parse(InputStream input, String charSetName) throws IOException {
+        parse(new BufferedReader(new InputStreamReader(input, charSetName)));
+    }
+
+    /**
+     *
+     * @param reader The reader
+     * @throws IOException If an error occurs.
+     */
+    public void parse(Reader reader) throws IOException {
+
+        //StringBuffer key = new StringBuffer();
+        StringBuffer value = new StringBuffer();
+
+        int state;
+        Stack complexVStack = new Stack();
+
+        int next = reader.read();
+        if (next == '{') {
+            handler.object();
+            complexVStack.push(OBJECT);
+            state = KEY_START;
+            next = readIgnoreWhitespace(reader);
+        } else {
+            throw new IOException("JSON object must start with a '{'");
+        }
+
+
+        while (next != EOF) {
+            switch (state) {
+
+                case KEY_START:
+                    if (next == '"') {
+                        String key = nextString(reader, '\"');
+                        next = readIgnoreWhitespace(reader);
+                        if (next == ':') {
+                            handler.key(key);
+                            state = VALUE_START;
+                        } else {
+                            throw new IOException("Key-Value pairs must be separated by ':'");
+                        }
+                        next = readIgnoreWhitespace(reader);
+                    } else if (next == '}') {
+                        // empty object
+                        state = VALUE;
+                    } else {
+                        throw new IOException("Key must be in String format (double quotes)");
+                    }
+                    break;
+
+                case VALUE_START:
+                    if (next == '[') {
+                        handler.array();
+                        complexVStack.push(ARRAY);
+                        // status still value_start
+                        next = readIgnoreWhitespace(reader);
+                    } else if (next == '{') {
+                        handler.object();
+                        complexVStack.push(OBJECT);
+                        state = KEY_START;
+                        next = readIgnoreWhitespace(reader);
+                    } else if (next == '\"') {
+                        handler.value(nextString(reader, '\"'));
+                        next = readIgnoreWhitespace(reader);
+                        if (!(next == ',' || next == ']' || next == '}')) {
+                            throw new IOException("Invalid json format");
+                        }
+                    } else {
+                        // start of boolean/long/double/null value
+                        // will be notified as key-value pair
+                        state = VALUE;
+                    }
+                    break;
+
+                case VALUE:
+                    if (next == '"') {
+                        throw new IOException("Invalid json format");
+                    } else if (next == ',') {
+                        state = (complexVStack.peek() == OBJECT) ? KEY_START : VALUE_START;
+                        value = resetValue(value);
+                        next = readIgnoreWhitespace(reader);
+                    } else if (next == ']') {
+                        if (complexVStack.pop() != ARRAY) {
+                            throw new IOException("Invalid json format: Unexpected array termination.");
+                        }
+                        value = resetValue(value);
+                        handler.endArray();
+
+                        next = readIgnoreWhitespace(reader);
+                        if (!(next == ',' || next == '}' || next == ']')) {
+                            throw new IOException("Invalid json format");
+                        }
+                    } else if (next == '}') {
+                        if (complexVStack.pop() != OBJECT) {
+                            throw new IOException("Invalid json format: Unexpected object termination.");
+                        }
+                        value = resetValue(value);
+                        handler.endObject();
+
+                        next = readIgnoreWhitespace(reader);
+                        if (!(next == ',' || next == '}' || next == ']' || next == EOF)) {
+                            throw new IOException("Invalid json format");
+                        }
+                    } else {
+                        // simple value
+                        value.append((char) next);
+                        next = reader.read();
+                    }
+                    break;
+            }
+        }
+
+        // EOF reached -> minimal validation check
+        if (value.length() != 0) {
+            throw new IOException("Invalid json format");
+        }
+    }
+
+    /**
+     * Return the characters up to the next close quote character.
+     * Backslash processing is done. The formal JSON format does not
+     * allow strings in single quotes, but an implementation is allowed to
+     * accept them.
+     *
+     * @param r The reader.
+     * @param quote The quoting character, either
+     *      <code>"</code>&nbsp;<small>(double quote)</small> or
+     *      <code>'</code>&nbsp;<small>(single quote)</small>.
+     * @return      A String.
+     * @throws IOException Unterminated string.
+     */
+    private static String nextString(Reader r, char quote) throws IOException {
+        int c;
+        StringBuffer sb = new StringBuffer();
+        for (;;) {
+            c = r.read();
+            switch (c) {
+            case EOF:
+            case '\n':
+            case '\r':
+                throw new IOException("Unterminated string");
+            case '\\':
+                c = r.read();
+                switch (c) {
+                case 'b':
+                    sb.append('\b');
+                    break;
+                case 't':
+                    sb.append('\t');
+                    break;
+                case 'n':
+                    sb.append('\n');
+                    break;
+                case 'f':
+                    sb.append('\f');
+                    break;
+                case 'r':
+                    sb.append('\r');
+                    break;
+                case 'u':
+                    sb.append((char)Integer.parseInt(next(r, 4), 16));
+                    break;
+                case 'x' :
+                    sb.append((char) Integer.parseInt(next(r, 2), 16));
+                    break;
+                default:
+                    sb.append((char) c);
+                }
+                break;
+            default:
+                if (c == quote) {
+                    return sb.toString();
+                }
+                sb.append((char) c);
+            }
+        }
+    }
+
+    private static String next(Reader r, int n) throws IOException {
+        StringBuffer b = new StringBuffer(n);
+        while (n-- > 0) {
+            int c = r.read();
+            if (c < 0) {
+                throw new EOFException();
+            }
+            b.append((char) c);
+        }
+        return b.toString();
+    }
+
+    /**
+     * Get the next char in the string, skipping whitespace.
+     *
+     * @param reader The reader
+     * @return A character, or -1 if there are no more characters.
+     * @throws IOException If an error occurs.
+     */
+    private static int readIgnoreWhitespace(Reader reader) throws IOException {
+        int next;
+        do {
+            next = reader.read();
+        } while (next == ' ' || next == '\n' || next == '\r' || next == '\t');
+        return next;
+    }
+
+    private StringBuffer resetValue(StringBuffer value) throws IOException {
+        if (value != null && value.length() > 0) {
+            String v = value.toString();
+            if (NULL.equals(v)) {
+                handler.value(null);
+            } else if (v.equalsIgnoreCase("true")) {
+                handler.value(true);
+            } else if (v.equalsIgnoreCase("false")) {
+                handler.value(false);
+            } else if (v.indexOf('.') > -1) {
+                double d = Double.parseDouble(v);
+                handler.value(d);
+            } else {
+                long l = Long.parseLong(v);
+                handler.value(l);
+            }
+        }
+        return new StringBuffer();
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/JSONParser.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,155 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.NodeInfo;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.Collections;
+
+/**
+ * <code>NodeInfoImpl</code>...
+ */
+public class NodeInfoImpl extends ItemInfoImpl implements NodeInfo {
+
+    private static Logger log = LoggerFactory.getLogger(NodeInfoImpl.class);
+
+    private NodeId id;
+    private String uniqueID;
+    private Name primaryNodeTypeName;
+    private Name[] mixinNodeTypeNames = new Name[0];
+
+    private final Set propertyInfos = new HashSet();
+    private List childInfos = null;
+
+    private int numberOfChildNodes = -1;
+
+    /**
+     * Creates a new serializable item info for the given qualified
+     * <code>item</code> info.
+     *
+     * @param id The node id.
+     * @param path the path to this item.
+     * @throws javax.jcr.RepositoryException If an error occurs.
+     */
+    public NodeInfoImpl(NodeId id, Path path) throws RepositoryException {
+        super(path, true);
+        this.id = id;
+    }
+
+    //-----------------------------------------------------------< NodeInfo >---
+    public NodeId getId() {
+        return id;
+    }
+
+    public int getIndex() {
+        return getPath().getNameElement().getNormalizedIndex();
+    }
+
+    public Name getNodetype() {
+        return primaryNodeTypeName;
+    }
+
+    public Name[] getMixins() {
+        return mixinNodeTypeNames;
+    }
+
+    public PropertyId[] getReferences() {
+        return new PropertyId[0];
+    }
+
+    public Iterator getPropertyIds() {
+        List l = new ArrayList();
+        for (Iterator it = propertyInfos.iterator(); it.hasNext(); ) {
+            PropertyId pId = ((PropertyInfo) it.next()).getId();
+            l.add(pId);
+        }
+        return l.iterator();
+    }
+
+    public Iterator getChildInfos() {
+        return (childInfos == null) ? null : childInfos.iterator();
+    }
+
+    //--------------------------------------------------------------------------
+    void addPropertyInfo(PropertyInfoImpl propInfo, IdFactory idFactory) throws RepositoryException {
+        propertyInfos.add(propInfo);
+
+        Name pn = propInfo.getId().getName();
+        if (NameConstants.JCR_UUID.equals(pn)) {
+            uniqueID = propInfo.getValues()[0].getString();
+            id = idFactory.createNodeId(uniqueID);
+            propInfo.setId(idFactory.createPropertyId(id, propInfo.getName()));
+        } else if (NameConstants.JCR_PRIMARYTYPE.equals(pn)) {
+            primaryNodeTypeName = propInfo.getValues()[0].getName();
+        } else if (NameConstants.JCR_MIXINTYPES.equals(pn)) {
+            QValue[] vs = propInfo.getValues();
+            Name[] mixins = new Name[vs.length];
+            for (int i = 0; i < vs.length; i++) {
+                mixins[i] = vs[i].getName();
+            }
+            mixinNodeTypeNames = mixins;
+        }
+    }
+
+    void addChildInfo(ChildInfo childInfo) {
+        if (childInfos == null) {
+            childInfos = new ArrayList();
+        }
+        if (childInfos.contains(childInfo)) {
+            log.warn("ChildInfo ( " + childInfo.toString() + " ) already contained -> ignore.");
+        } else {
+            childInfos.add(childInfo);
+        }
+    }
+
+    void setNumberOfChildNodes(long numberOfChildNodes) {
+        if (numberOfChildNodes == 0) {
+            childInfos = Collections.EMPTY_LIST;
+        } // else: wait for calls to #addChildInfo
+    }
+
+    boolean isCompleted() {
+        return !(id == null || primaryNodeTypeName == null || propertyInfos.isEmpty());
+    }
+
+    void checkCompleted() throws RepositoryException {
+        if (!isCompleted()) {
+            throw new RepositoryException("Incomplete NodeInfo");
+        }
+    }
+
+    String getUniqueID() {
+        return uniqueID;
+    }
+}

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/NodeInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,120 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.RequestEntity;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.apache.commons.httpclient.util.EncodingUtil;
+import org.apache.jackrabbit.webdav.DavMethods;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.client.methods.DavMethodBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>PostMethod</code>...*
+ */
+class PostMethod extends DavMethodBase {
+
+    private static Logger log = LoggerFactory.getLogger(PostMethod.class);
+
+    /** The Content-Type for www-form-urlencoded. */
+    public static final String FORM_URL_ENCODED_CONTENT_TYPE = "application/x-www-form-urlencoded; charset=utf-8";
+
+    /**
+     * The buffered request body consisting of <code>NameValuePair</code>s.
+     */
+    private List params = new ArrayList();
+
+    public PostMethod(String uri) {
+        super(uri);
+        HttpMethodParams params = getParams();
+        params.setContentCharset("UTF-8");
+    }
+
+    // -----------------------------------------------------< DavMethodBase >---
+    protected boolean isSuccess(int statusCode) {
+        return statusCode == DavServletResponse.SC_OK ||
+                statusCode == DavServletResponse.SC_NO_CONTENT ||
+                statusCode == DavServletResponse.SC_CREATED;
+    }
+
+    public String getName() {
+        return DavMethods.METHOD_POST;
+    }
+
+    // COPIED FROM httpclient PostMethod.
+    // ---------------------------------------------< EntityEnclosingMethod >---
+    protected boolean hasRequestContent() {
+        if (!params.isEmpty()) {
+            return true;
+        } else {
+            return super.hasRequestContent();
+        }
+    }
+
+    protected void clearRequestBody() {
+        log.debug("enter PostMethod.clearRequestBody()");
+        this.params.clear();
+        super.clearRequestBody();
+    }
+
+    protected RequestEntity generateRequestEntity() {
+        if (!this.params.isEmpty()) {
+            // Use a ByteArrayRequestEntity instead of a StringRequestEntity.
+            // This is to avoid potential encoding issues.  Form url encoded strings
+            // are ASCII by definition but the content type may not be.  Treating the content
+            // as bytes allows us to keep the current charset without worrying about how
+            // this charset will effect the encoding of the form url encoded string.
+            NameValuePair[] mvps = (NameValuePair[]) params.toArray(new NameValuePair[params.size()]);
+            String content = EncodingUtil.formUrlEncode(mvps, getRequestCharSet());
+            ByteArrayRequestEntity entity = new ByteArrayRequestEntity(
+                    EncodingUtil.getAsciiBytes(content),
+                    FORM_URL_ENCODED_CONTENT_TYPE
+            );
+            return entity;
+        } else {
+            return super.generateRequestEntity();
+        }
+    }
+
+    //--------------------------------------------------------------------------
+    /**
+     * Adds a new parameter to be used in the POST request body.
+     *
+     * @param paramName The parameter name to add.
+     * @param paramValue The parameter value to add.
+     * @throws IllegalArgumentException if either argument is null
+     */
+    public void addParameter(String paramName, String paramValue)
+            throws IllegalArgumentException {
+        log.debug("enter PostMethod.addParameter(String, String)");
+
+        if ((paramName == null) || (paramValue == null)) {
+            throw new IllegalArgumentException(
+                    "Arguments to addParameter(String, String) cannot be null");
+        }
+        super.clearRequestBody();
+        params.add(new NameValuePair(paramName, paramValue));
+    }
+    // COPIED FROM httpclient PostMethod.
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PostMethod.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java?rev=738480&view=auto
==============================================================================
--- jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java (added)
+++ jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java Wed Jan 28 13:35:47 2009
@@ -0,0 +1,108 @@
+/*
+ * 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.spi.spi2davex;
+
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.spi.PropertyInfo;
+import org.apache.jackrabbit.spi.QValue;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <code>PropertyInfoImpl</code>...
+ */
+public class PropertyInfoImpl extends ItemInfoImpl implements PropertyInfo {
+
+    private final boolean isMultiValued;
+
+    private PropertyId id;
+    private int propertyType;
+    private List values = new ArrayList();
+
+    public PropertyInfoImpl(PropertyId id, Path path, int propertyType,
+                            QValue singleValue) throws RepositoryException {
+        super(path, false);
+        this.id = id;
+        this.propertyType = propertyType;
+        isMultiValued = false;
+        values.add(singleValue);
+    }
+
+    public PropertyInfoImpl(PropertyId id, Path path, int propertyType) throws RepositoryException {
+        super(path, false);
+        this.id = id;
+        this.propertyType = propertyType;
+        isMultiValued = true;
+    }
+
+    //-------------------------------------------------------< PropertyInfo >---
+    public PropertyId getId() {
+        return id;
+    }
+
+    public int getType() {
+        if (propertyType == PropertyType.UNDEFINED) {
+            // in case of empty-value-array of a multivalued property the type
+            // must always be set.
+            propertyType = getValues()[0].getType();
+        }
+        return propertyType;
+    }
+
+    public boolean isMultiValued() {
+        return isMultiValued;
+    }
+
+    public QValue[] getValues() {
+        return (QValue[]) values.toArray(new QValue[values.size()]);
+    }
+
+    //--------------------------------------------------------------------------
+    int numberOfValues() {
+        return values.size();
+    }
+
+    void setId(PropertyId id) {
+        this.id = id;
+    }
+
+    void addValue(QValue value) throws RepositoryException {
+        if (values == null) {
+            values = new ArrayList();
+        } else if (!isMultiValued && !values.isEmpty()) {
+            throw new RepositoryException("Attempt to add multiple values to a single valued PropertyInfo");
+        }
+        values.add(value);
+    }
+
+    void setType(int propertyType) {
+        this.propertyType = propertyType;
+    }
+
+    void checkCompleted() throws RepositoryException {
+        if (id == null) {
+            throw new RepositoryException("Incomplete PropertyInfo: id missing.");
+        }
+        if (values.size() == 0 && propertyType == PropertyType.UNDEFINED) {
+            throw new RepositoryException("Incomplete PropertyInfo: missing type of multivalued property.");
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/sandbox/spi/spi2davex/src/main/java/org/apache/jackrabbit/spi/spi2davex/PropertyInfoImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url



Mime
View raw message