jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r463335 - in /jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav: IdURICache.java RepositoryServiceImpl.java URIResolverImpl.java
Date Thu, 12 Oct 2006 17:25:17 GMT
Author: angela
Date: Thu Oct 12 10:25:16 2006
New Revision: 463335

URL: http://svn.apache.org/viewvc?view=rev&rev=463335
Log:
work in progress

- MKCOL fails if resource already exists => problem with SNSs
- make sure resource hrefs are always cached without trailing /

Modified:
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java?view=diff&rev=463335&r1=463334&r2=463335
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/IdURICache.java
Thu Oct 12 10:25:16 2006
@@ -40,7 +40,7 @@
     }
 
     public ItemId getItemId(String uri) {
-        return (ItemId) uriToIdCache.get(uri);
+        return (ItemId) uriToIdCache.get(getCleanUri(uri));
     }
 
     public String getUri(ItemId itemId) {
@@ -48,7 +48,7 @@
     }
 
     public boolean containsUri(String uri) {
-        return uriToIdCache.containsKey(uri);
+        return uriToIdCache.containsKey(getCleanUri(uri));
     }
 
     public boolean containsItemId(ItemId itemId) {
@@ -59,18 +59,28 @@
         if (!uri.startsWith(workspaceUri)) {
             throw new IllegalArgumentException("Workspace missmatch.");
         }
-        uriToIdCache.put(uri, itemId);
-        idToUriCache.put(itemId, uri);
-        log.debug("Added: ItemId = " + itemId + " URI = " + uri);
+        String cleanUri = getCleanUri(uri);
+        uriToIdCache.put(cleanUri, itemId);
+        idToUriCache.put(itemId, cleanUri);
+        log.debug("Added: ItemId = " + itemId + " URI = " + cleanUri);
     }
 
     public void remove(String uri) {
-        Object itemId = uriToIdCache.remove(uri);
-        log.debug("Removed: ItemId = " + itemId + " URI = " + uri);
+        String cleanUri = getCleanUri(uri);
+        Object itemId = uriToIdCache.remove(cleanUri);
+        log.debug("Removed: ItemId = " + itemId + " URI = " + cleanUri);
     }
 
     public void remove(ItemId itemId) {
         Object uri = idToUriCache.remove(itemId);
         log.debug("Removed: ItemId = " + itemId + " URI = " + uri);
+    }
+
+    private static String getCleanUri(String uri) {
+        if (uri.endsWith("/")) {
+            return uri.substring(0, uri.length() - 1);
+        } else {
+            return uri;
+        }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=463335&r1=463334&r2=463335
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Thu Oct 12 10:25:16 2006
@@ -189,7 +189,8 @@
     private final NamespaceResolverImpl nsResolver;
     private final URIResolverImpl uriResolver;
 
-    private final HttpClient client;
+    private final HostConfiguration hostConfig;
+    private final HashMap clients = new HashMap();
 
     public RepositoryServiceImpl(String uri, IdFactory idFactory, ValueFactory valueFactory)
throws RepositoryException {
         if (uri == null || "".equals(uri)) {
@@ -209,14 +210,9 @@
 
         try {
             URI repositoryUri = new URI((uri.endsWith("/")) ? uri : uri+"/", true);
-            HostConfiguration hostConfig = new HostConfiguration();
+            hostConfig = new HostConfiguration();
             hostConfig.setHost(repositoryUri);
 
-            client = new HttpClient(new MultiThreadedHttpConnectionManager());
-            client.setHostConfiguration(hostConfig);
-            // always send authentication not waiting for 401
-            client.getParams().setAuthenticationPreemptive(true);
-
             nsResolver = new NamespaceResolverImpl();
             uriResolver = new URIResolverImpl(repositoryUri, this, nsResolver, domFactory);
 
@@ -247,11 +243,29 @@
         }
     }
 
+    private static boolean isSameResource(String requestURI, MultiStatusResponse response)
{
+        String href = response.getHref();
+        if (href.endsWith("/")) {
+            href = href.substring(0, href.length() - 1);
+        }
+        return requestURI.equals(href);
+    }
+
     private HttpClient getClient(org.apache.commons.httpclient.Credentials credentials) {
-        // NOTE: null credentials only work if 'missing-auth-mapping' param is
-        // set on the server
-        client.getState().setCredentials(AuthScope.ANY, credentials);
-        return client;
+        if (clients.containsKey(credentials)) {
+            return (HttpClient) clients.get(credentials);
+        } else {
+            HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
+            client.setHostConfiguration(hostConfig);
+            // always send authentication not waiting for 401
+            client.getParams().setAuthenticationPreemptive(true);
+            // NOTE: null credentials only work if 'missing-auth-mapping' param is
+            // set on the server
+            client.getState().setCredentials(AuthScope.ANY, credentials);
+
+            clients.put(credentials, client);
+            return client;
+        }
     }
 
     HttpClient getClient(SessionInfo sessionInfo) throws RepositoryException {
@@ -266,7 +280,7 @@
     private String getItemUri(NodeId parentId, QName childName, SessionInfo sessionInfo)
throws RepositoryException {
         String parentUri = uriResolver.getItemUri(parentId, sessionInfo.getWorkspaceName(),
sessionInfo);
         try {
-            return parentUri + NameFormat.format(childName, nsResolver);
+            return parentUri + "/" + NameFormat.format(childName, nsResolver);
         } catch (NoPrefixDeclaredException e) {
             throw new RepositoryException(e);
         }
@@ -637,8 +651,7 @@
             MultiStatusResponse nodeResponse = null;
             List childResponses = new ArrayList();
             for (int i = 0; i < responses.length; i++) {
-                String respHref = responses[i].getHref();
-                if (uri.equals(respHref)) {
+                if (isSameResource(uri, responses[i])) {
                     nodeResponse = responses[i];
                 } else {
                     childResponses.add(responses[i]);
@@ -1538,29 +1551,31 @@
         public void addNode(NodeId parentId, QName nodeName, QName nodetypeName, String uuid)
throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException,
NoSuchNodeTypeException, LockException, AccessDeniedException, UnsupportedRepositoryOperationException,
RepositoryException {
             checkConsumed();
             try {
-                String uri = getItemUri(parentId, nodeName, sessionInfo);
+                // TODO: TOBEFIXED. WebDAV does not allow MKCOL for existing resource ->
problem with SNS
+                // use fake name instead (see also #importXML)
+                QName fakeName = new QName(QName.NS_DEFAULT_URI, UUID.randomUUID().toString());
+                String uri = getItemUri(parentId, fakeName, sessionInfo);
                 MkColMethod method = new MkColMethod(uri);
 
                 // build 'sys-view' for the node to create and append it as request body
-                if (nodetypeName != null || uuid != null) {
-                    Document body = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
-                    Element nodeElement = DomUtil.addChildElement(body, NODE_ELEMENT, SV_NAMESPACE);
-                    DomUtil.setAttribute(nodeElement, NAME_ATTRIBUTE, SV_NAMESPACE, Text.getName(uri,
true));
-
-                    if (nodetypeName != null) {
-                        Element propElement = DomUtil.addChildElement(nodeElement, PROPERTY_ELEMENT,
SV_NAMESPACE);
-                        DomUtil.setAttribute(propElement, NAME_ATTRIBUTE, SV_NAMESPACE, NameFormat.format(QName.JCR_PRIMARYTYPE,
nsResolver));
-                        DomUtil.setAttribute(propElement, TYPE_ATTRIBUTE, SV_NAMESPACE, PropertyType.nameFromValue(PropertyType.NAME));
-                        DomUtil.addChildElement(propElement, VALUE_ELEMENT, SV_NAMESPACE,
NameFormat.format(nodetypeName, nsResolver));
-                    }
-                    if (uuid != null) {
-                        Element propElement = DomUtil.addChildElement(nodeElement, PROPERTY_ELEMENT,
SV_NAMESPACE);
-                        DomUtil.setAttribute(propElement, NAME_ATTRIBUTE, SV_NAMESPACE, NameFormat.format(QName.JCR_UUID,
nsResolver));
-                        DomUtil.setAttribute(propElement, TYPE_ATTRIBUTE, SV_NAMESPACE, PropertyType.nameFromValue(PropertyType.STRING));
-                        DomUtil.addChildElement(propElement, VALUE_ELEMENT, SV_NAMESPACE,
uuid);
-                    }
-                    method.setRequestBody(body);
+                Document body = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument();
+                Element nodeElement = DomUtil.addChildElement(body, NODE_ELEMENT, SV_NAMESPACE);
+                String nameAttr = NameFormat.format(nodeName, nsResolver);
+                DomUtil.setAttribute(nodeElement, NAME_ATTRIBUTE, SV_NAMESPACE, nameAttr);
+
+                // nodetype must never be null
+                Element propElement = DomUtil.addChildElement(nodeElement, PROPERTY_ELEMENT,
SV_NAMESPACE);
+                DomUtil.setAttribute(propElement, NAME_ATTRIBUTE, SV_NAMESPACE, NameFormat.format(QName.JCR_PRIMARYTYPE,
nsResolver));
+                DomUtil.setAttribute(propElement, TYPE_ATTRIBUTE, SV_NAMESPACE, PropertyType.nameFromValue(PropertyType.NAME));
+                DomUtil.addChildElement(propElement, VALUE_ELEMENT, SV_NAMESPACE, NameFormat.format(nodetypeName,
nsResolver));
+                // optional uuid
+                if (uuid != null) {
+                    propElement = DomUtil.addChildElement(nodeElement, PROPERTY_ELEMENT,
SV_NAMESPACE);
+                    DomUtil.setAttribute(propElement, NAME_ATTRIBUTE, SV_NAMESPACE, NameFormat.format(QName.JCR_UUID,
nsResolver));
+                    DomUtil.setAttribute(propElement, TYPE_ATTRIBUTE, SV_NAMESPACE, PropertyType.nameFromValue(PropertyType.STRING));
+                    DomUtil.addChildElement(propElement, VALUE_ELEMENT, SV_NAMESPACE, uuid);
                 }
+                method.setRequestBody(body);
 
                 methods.add(method);
             } catch (IOException e) {

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java?view=diff&rev=463335&r1=463334&r2=463335
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/URIResolverImpl.java
Thu Oct 12 10:25:16 2006
@@ -103,7 +103,7 @@
     }
 
     String getRootItemUri(String workspaceName) {
-        return getWorkspaceUri(workspaceName) + Text.escapePath(ItemResourceConstants.ROOT_ITEM_RESOURCEPATH)
+ "/";
+        return getWorkspaceUri(workspaceName) + Text.escapePath(ItemResourceConstants.ROOT_ITEM_RESOURCEPATH);
     }
 
     String getItemUri(ItemId itemId, String workspaceName,
@@ -162,19 +162,14 @@
             if (path != null && !path.denotesRoot()) {
                 try {
                     String jcrPath = PathFormat.format(path, nsResolver);
-                    if (path.isAbsolute()) {
-                        jcrPath = jcrPath.substring(1);
+                    if (!path.isAbsolute()) {
+                        uriBuffer.append("/");
                     }
                     uriBuffer.append(Text.escapePath(jcrPath));
                 } catch (NoPrefixDeclaredException e) {
                     throw new RepositoryException(e);
                 }
             }
-            // add training / for nodes
-            if (itemId.denotesNode() && uriBuffer.charAt(uriBuffer.length()-1) !=
'/') {
-                uriBuffer.append('/');
-            }
-
             String itemUri = uriBuffer.toString();
             if (!cache.containsItemId(itemId)) {
                 cache.add(itemUri, itemId);
@@ -283,9 +278,6 @@
                 parentId = null;
             } else {
                 String parentUri = Text.getRelativeParent(uri, 1, true);
-                if (!parentUri.endsWith("/")) {
-                    parentUri += "/";
-                }
                 parentId = getNodeId(parentUri, sessionInfo);
             }
 



Mime
View raw message