You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2009/02/12 14:05:19 UTC
svn commit: r743718 - in /jackrabbit/trunk/jackrabbit-jcr-server/src:
main/java/org/apache/jackrabbit/server/remoting/davex/
test/java/org/apache/jackrabbit/server/remoting/davex/
Author: angela
Date: Thu Feb 12 13:05:17 2009
New Revision: 743718
URL: http://svn.apache.org/viewvc?rev=743718&view=rev
Log:
- JCR-1958: Enhanced JCR remoting (work in progress)
Added:
jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.java
jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/TestAll.java
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.java?rev=743718&r1=743717&r2=743718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.java Thu Feb 12 13:05:17 2009
@@ -122,11 +122,11 @@
*
* <h4>Diff format</h4>
*
- * The diff parameter currently consists of a JSON object with the following
- * special requirements:
+ * The diff parameter currently consists of JSON-like key-value pairs with the
+ * following special requirements:
*
* <pre>
- * diff ::= "{" members "}"
+ * diff ::= members
* members ::= pair | pairs
* pair ::= key " : " value
* pairs ::= pair line-end pair | pair line-end pairs
@@ -145,7 +145,7 @@
*
* In other words:
* <ul>
- * <li>diff is a JSON object consisting of key-value pairs</li>
+ * <li>diff consists of one or more key-value pair(s)</li>
* <li>key must start with a diffchar followed by a rel. or abs. item path</li>
* <li>diffchar being any of "+", "^", "-" or ">" representing the transient
* item modifications as follows
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java?rev=743718&r1=743717&r2=743718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandler.java Thu Feb 12 13:05:17 2009
@@ -45,6 +45,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
+import java.util.LinkedList;
/** <code>JsonDiffHandler</code>... */
class JsonDiffHandler implements DiffHandler {
@@ -228,14 +229,19 @@
* @throws RepositoryException
*/
String getItemPath(String diffPath) throws RepositoryException {
- if (diffPath.startsWith("/")) {
- // diff path is already an absolute path
- return diffPath;
- } else {
+ StringBuffer itemPath;
+ if (!diffPath.startsWith("/")) {
// diff path is relative to the item path retrieved from the
// request URI -> calculate item path.
- return requestItemPath + diffPath;
+ itemPath = new StringBuffer(requestItemPath);
+ if (!requestItemPath.endsWith("/")) {
+ itemPath.append('/');
+ }
+ itemPath.append(diffPath);
+ } else {
+ itemPath = new StringBuffer(diffPath);
}
+ return normalize(itemPath.toString());
}
private void addNode(String parentPath, String nodeName, String diffValue)
@@ -254,6 +260,30 @@
}
}
+ private static String normalize(String path) {
+ if (path.indexOf('.') == -1) {
+ return path;
+ }
+ String[] elems = Text.explode(path, '/', false);
+ LinkedList queue = new LinkedList();
+ String last = "..";
+ for (int i = 0; i < elems.length; i++) {
+ String segm = elems[i];
+ if ("..".equals(segm) && !"..".equals(last)) {
+ queue.removeLast();
+ if (queue.isEmpty()) {
+ last = "..";
+ } else {
+ last = queue.getLast().toString();
+ }
+ } else if (!".".equals(segm)) {
+ last = segm;
+ queue.add(last);
+ }
+ }
+ return "/" + Text.implode((String[]) queue.toArray(new String[queue.size()]), "/");
+ }
+
private static Node importNode(Node parent, String nodeName, String ntName,
String uuid) throws RepositoryException {
Added: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java?rev=743718&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java Thu Feb 12 13:05:17 2009
@@ -0,0 +1,202 @@
+/*
+ * 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.server.remoting.davex;
+
+import junit.framework.TestCase;
+
+import javax.jcr.Session;
+import javax.jcr.Repository;
+import javax.jcr.Workspace;
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Item;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.AccessDeniedException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ValueFactory;
+import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.InvalidSerializedDataException;
+import javax.jcr.NamespaceException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.version.VersionException;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.security.AccessControlException;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * <code>JsonDiffHandlerTest</code>...
+ */
+public class JsonDiffHandlerTest extends TestCase {
+
+ public void testGetItemPath() throws Exception {
+ Map m = new HashMap();
+ m.put("abc", "/reqPath/abc");
+ m.put("abc/def/ghi", "/reqPath/abc/def/ghi");
+ m.put("/abc", "/abc");
+ m.put("/abc/def/ghi", "/abc/def/ghi");
+ m.put(".", "/reqPath");
+ m.put("./abc", "/reqPath/abc");
+ m.put("abc/./def", "/reqPath/abc/def");
+ m.put("/abc/./def", "/abc/def");
+ m.put("..", "/");
+ m.put("../abc/def", "/abc/def");
+ m.put("abc/../def/.", "/reqPath/def");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("abc/../def/..", "/reqPath");
+ m.put("./././././", "/reqPath");
+ m.put("/./././././", "/");
+ m.put("/./abc/def/../ghi", "/abc/ghi");
+
+ JsonDiffHandler handler = new JsonDiffHandler(new DummySession(), "/reqPath", null);
+ for (Iterator it = m.keySet().iterator(); it.hasNext();) {
+ String targetPath = it.next().toString();
+ String expItemPath = m.get(targetPath).toString();
+ assertEquals(expItemPath, handler.getItemPath(targetPath));
+ }
+ }
+
+ private final class DummySession implements Session {
+
+ public Repository getRepository() {
+ return null;
+ }
+
+ public String getUserID() {
+ return null;
+ }
+
+ public Object getAttribute(String name) {
+ return null;
+ }
+
+ public String[] getAttributeNames() {
+ return new String[0];
+ }
+
+ public Workspace getWorkspace() {
+ return null;
+ }
+
+ public Session impersonate(Credentials credentials) throws LoginException, RepositoryException {
+ return null;
+ }
+
+ public Node getRootNode() throws RepositoryException {
+ return null;
+ }
+
+ public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException {
+ return null;
+ }
+
+ public Item getItem(String absPath) throws PathNotFoundException, RepositoryException {
+ return null;
+ }
+
+ public boolean itemExists(String absPath) throws RepositoryException {
+ return false;
+ }
+
+ public void move(String srcAbsPath, String destAbsPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
+ }
+
+ public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException, InvalidItemStateException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException {
+ }
+
+ public void refresh(boolean keepChanges) throws RepositoryException {
+ }
+
+ public boolean hasPendingChanges() throws RepositoryException {
+ return false;
+ }
+
+ public ValueFactory getValueFactory() throws UnsupportedRepositoryOperationException, RepositoryException {
+ return null;
+ }
+
+ public void checkPermission(String absPath, String actions) throws AccessControlException, RepositoryException {
+ }
+
+ public ContentHandler getImportContentHandler(String parentAbsPath, int uuidBehavior) throws PathNotFoundException, ConstraintViolationException, VersionException, LockException, RepositoryException {
+ return null;
+ }
+
+ public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, RepositoryException {
+ }
+
+ public void exportSystemView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException {
+ }
+
+ public void exportSystemView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, PathNotFoundException, RepositoryException {
+ }
+
+ public void exportDocumentView(String absPath, ContentHandler contentHandler, boolean skipBinary, boolean noRecurse) throws PathNotFoundException, SAXException, RepositoryException {
+ }
+
+ public void exportDocumentView(String absPath, OutputStream out, boolean skipBinary, boolean noRecurse) throws IOException, PathNotFoundException, RepositoryException {
+ }
+
+ public void setNamespacePrefix(String prefix, String uri) throws NamespaceException, RepositoryException {
+ }
+
+ public String[] getNamespacePrefixes() throws RepositoryException {
+ return new String[0];
+ }
+
+ public String getNamespaceURI(String prefix) throws NamespaceException, RepositoryException {
+ return null;
+ }
+
+ public String getNamespacePrefix(String uri) throws NamespaceException, RepositoryException {
+ return null;
+ }
+
+ public void logout() {
+ }
+
+ public boolean isLive() {
+ return false;
+ }
+
+ public void addLockToken(String lt) {
+ }
+
+ public String[] getLockTokens() {
+ return new String[0];
+ }
+
+ public void removeLockToken(String lt) {
+ }
+ }
+}
\ No newline at end of file
Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/JsonDiffHandlerTest.java
------------------------------------------------------------------------------
svn:keywords = author date id revision url
Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/TestAll.java?rev=743718&r1=743717&r2=743718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/server/remoting/davex/TestAll.java Thu Feb 12 13:05:17 2009
@@ -33,6 +33,7 @@
TestSuite suite = new TestSuite("org.apache.jackrabbit.server.remoting.davex tests");
suite.addTestSuite(DiffParserTest.class);
+ suite.addTestSuite(JsonDiffHandlerTest.class);
suite.addTestSuite(BatchReadConfigTest.class);
return suite;