Author: reto
Date: Wed Mar 28 13:18:19 2012
New Revision: 1306308

URL: http://svn.apache.org/viewvc?rev=1306308&view=rev
Log:
passing over to alessandro

Removed:
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/JcrFileResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/JcrFolderResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/PlatformFileResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/PlatformFolderResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/ReadOnlyFileResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/ReadOnlyFolderResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingCollectionResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingFileResource.java
Modified:
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResource.java
    
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java

Modified: 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResource.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResource.java?rev=1306308&r1=1306307&r2=1306308&view=diff
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResource.java
 (original)
+++ 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResource.java
 Wed Mar 28 13:18:19 2012
@@ -18,147 +18,77 @@
  */
 package org.apache.sling.whiteboard.fmeschbe.miltondav.impl.resources;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Date;
 import java.util.Map;
 
-import javax.jcr.Node;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceMetadata;
-
 import com.bradmcevoy.http.Auth;
 import com.bradmcevoy.http.GetableResource;
-import com.bradmcevoy.http.LockInfo;
-import com.bradmcevoy.http.LockResult;
-import com.bradmcevoy.http.LockTimeout;
-import com.bradmcevoy.http.LockToken;
-import com.bradmcevoy.http.LockableResource;
 import com.bradmcevoy.http.PropFindableResource;
 import com.bradmcevoy.http.Range;
 import com.bradmcevoy.http.Request;
 import com.bradmcevoy.http.Request.Method;
+import com.bradmcevoy.http.exceptions.BadRequestException;
 import com.bradmcevoy.http.exceptions.NotAuthorizedException;
-import com.ettrema.http.fs.LockManager;
-import com.ettrema.http.fs.SimpleLockManager;
-
-public class SlingResource implements PropFindableResource, GetableResource,
-        LockableResource {
-
-    private static final LockManager lockManager = new SimpleLockManager();
-
-    private final Resource slingResource;
-
-    protected SlingResource(final Resource slingResource) {
-        this.slingResource = slingResource;
-    }
-
-    protected Resource getSlingResource() {
-        return slingResource;
-    }
-
-    protected Node getNode() {
-        return slingResource.adaptTo(Node.class);
-    }
-
-    protected File getFile() {
-        return slingResource.adaptTo(File.class);
-    }
-
-    protected String getAbsPath(final SlingResource parent, final String 
child) {
-        String parentPath = parent.getSlingResource().getPath();
-        if (!parentPath.endsWith("/")) {
-            parentPath += "/";
-        }
-        return parentPath + child;
-    }
-
-    public Date getModifiedDate() {
-        return new Date(
-            slingResource.getResourceMetadata().getModificationTime());
-    }
-
-    public Date getCreateDate() {
-        return new Date(slingResource.getResourceMetadata().getCreationTime());
-    }
-
-    public String getName() {
-        return slingResource.getName();
-    }
-
-    public String getUniqueId() {
-        return getName();
-    }
-
-    public String checkRedirect(Request request) {
-        return null;
-    }
-
-    public Object authenticate(String user, String password) {
-        // should return the request's slingResource resolver ??
-        return null;
-    }
-
-    public boolean authorise(Request request, Method method, Auth auth) {
-        return true;
-    }
-
-    public String getRealm() {
-        return "<notused>";
-    }
-
-    // ---------- GetableResource
-
-    public Long getContentLength() {
-        Object length = getSlingResource().getResourceMetadata().get(
-            ResourceMetadata.CONTENT_LENGTH);
-        return (length instanceof Long) ? (Long) length : null;
-    }
-
-    public String getContentType(String accepts) {
-        // TODO: ensure not null
-        return getSlingResource().getResourceMetadata().getContentType();
-    }
-
-    public Long getMaxAgeSeconds(Auth auth) {
-        // TODO: no caching for now ... might reconsider
-        return null;
-    }
-
-    public void sendContent(OutputStream out, Range range,
-            Map<String, String> params, String contentType) throws IOException 
{
-        // just spool the content, ignore are arguments (for now)
-        InputStream ins = getSlingResource().adaptTo(InputStream.class);
-        if (ins != null) {
-            try {
-                IOUtils.copy(ins, out);
-            } finally {
-                IOUtils.closeQuietly(ins);
-            }
-        }
-    }
-
-    // ---------- LockableResource
-
-    public LockResult lock(LockTimeout timeout, LockInfo lockInfo)
-            throws NotAuthorizedException {
-        return lockManager.lock(timeout, lockInfo, this);
-    }
-
-    public LockResult refreshLock(String token) throws NotAuthorizedException {
-        return lockManager.refresh(token, this);
-    }
-
-    public void unlock(String tokenId) throws NotAuthorizedException {
-        lockManager.unlock(tokenId, this);
-    }
-
-    public LockToken getCurrentLock() {
-        return lockManager.getCurrentToken(this);
-    }
 
-}
+public class SlingResource implements PropFindableResource, GetableResource {
+        
+       private static final String FILENAME = "scratchpad.txt";
+       private static final String MESSAGE = "Hello world";
+ 
+       public static String getFilename() {
+               return FILENAME;
+       }
+ 
+       public String getUniqueId() {
+               return getFilename();
+       }
+ 
+
+       public String getName() {
+               return getFilename();
+       }
+ 
+       public Object authenticate(String user, String password) {
+               return "anonymous";
+       }
+ 
+       public boolean authorise(Request request, Method method, Auth auth) {
+               return true;
+       }
+ 
+       public String getRealm() {
+               return null;
+       }
+ 
+       public Date getCreateDate() {
+               return new Date();
+       }
+ 
+       public Date getModifiedDate() {
+               return new Date();
+       }
+ 
+
+       public String checkRedirect(Request request) {
+               return null;
+       }
+ 
+
+       public Long getMaxAgeSeconds(Auth auth) {
+               return null;
+       }
+ 
+       public String getContentType(String accepts) {
+               return "text/plain";
+       }
+ 
+       public Long getContentLength() {
+               return Long.valueOf(MESSAGE);
+       }
+ 
+       public void sendContent(OutputStream out, Range range, Map params, 
String contentType) throws IOException, NotAuthorizedException, 
BadRequestException {
+               out.write(MESSAGE.getBytes());
+       }
+}
\ No newline at end of file

Modified: 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java?rev=1306308&r1=1306307&r2=1306308&view=diff
==============================================================================
--- 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
 (original)
+++ 
incubator/stanbol/branches/ontonet-showcase/webdav/src/main/java/org/apache/sling/whiteboard/fmeschbe/miltondav/impl/resources/SlingResourceFactory.java
 Wed Mar 28 13:18:19 2012
@@ -18,108 +18,27 @@
  */
 package org.apache.sling.whiteboard.fmeschbe.miltondav.impl.resources;
 
-import java.io.File;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.auth.core.AuthenticationSupport;
-import org.apache.sling.whiteboard.fmeschbe.miltondav.impl.MiltonDavServlet;
-
-import com.bradmcevoy.http.MiltonServlet;
+import com.bradmcevoy.common.Path;
 import com.bradmcevoy.http.Resource;
 import com.bradmcevoy.http.ResourceFactory;
 
 public class SlingResourceFactory implements ResourceFactory {
-
-    public static final String NAME = 
"org.apache.sling.whiteboard.fmeschbe.miltondav.impl.resources.SlingResourceFactory";
-
-    private String prefix;
-
-    public SlingResourceFactory() {
-    }
-
-    public Resource getResource(final String host, String path) {
-
-        // cut off prefix
-        final String prefixPath = getPrefix();
-        if (path.startsWith(prefixPath)) {
-            path = path.substring(prefixPath.length());
-        }
-
-        // ensure non-empty path
-        if (path.length() == 0) {
-            path = "/";
-        }
-
-        org.apache.sling.api.resource.Resource slingResource = 
getResourceResolver().getResource(
-            path);
-        return createResource(slingResource);
-    }
-
-    static ResourceResolver getResourceResolver() {
-        return (ResourceResolver) MiltonServlet.request().getAttribute(
-            AuthenticationSupport.REQUEST_ATTRIBUTE_RESOLVER);
-    }
-
-    static Resource createResource(
-            final org.apache.sling.api.resource.Resource slingResource) {
-        if (slingResource == null) {
-            return null;
-        }
-
-        Node node = slingResource.adaptTo(javax.jcr.Node.class);
-        if (node != null) {
-            try {
-                if (node.isNodeType("nt:file")) {
-                    return new JcrFileResource(slingResource);
-                }
-            } catch (RepositoryException re) {
-                // TODO: log
-            }
-
-            return new JcrFolderResource(slingResource);
-        }
-
-        File file = slingResource.adaptTo(File.class);
-        if (file != null) {
-            if (file.isFile()) {
-                return new PlatformFileResource(slingResource);
-            }
-            return new PlatformFolderResource(slingResource);
-        }
-
-        if ("nt:file".equals(slingResource.getResourceType())) {
-            return new ReadOnlyFileResource(slingResource);
-        }
-
-        return new ReadOnlyFolderResource(slingResource);
-    }
-
-    private String getPrefix() {
-        if (prefix == null) {
-            StringBuilder b = new StringBuilder();
-            HttpServletRequest request = MiltonDavServlet.request();
-
-            // start with context path if not null (may be empty)
-            if (request.getContextPath() != null) {
-                b.append(request.getContextPath());
-            }
-
-            // append servlet path if not null (may be empty)
-            if (request.getServletPath() != null) {
-                b.append(request.getServletPath());
-            }
-
-            // cut off trailing slash
-            if (b.length() > 1 && b.charAt(b.length() -1) == '/') {
-                b.setLength(b.length()-1);
-            }
-
-            prefix = b.toString();
-        }
-        return prefix;
-    }
-}
+                
+       final public static String NAME = "dks";
+       
+               public Resource getResource(String host, String strPath) {
+                       Path path = Path.path(strPath);
+        
+                       //STRIP PRECEEDING PATH
+                       path = path.getStripFirst().getStripFirst();
+        
+                       if (path.isRoot()) {
+                               return new RootResource();
+                       } else if 
(path.getFirst().equals(SlingResource.getFilename())) {
+                               return new SlingResource();
+                       }
+        
+                       return null;
+               }
+        
+       }
\ No newline at end of file


Reply via email to