jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angela Schreiber <anch...@day.com>
Subject Re: Please tell me how to create webdav client
Date Tue, 31 Mar 2009 08:25:02 GMT
hi

first of all: i'm not sure i got what you are trying to do.
maybe you have to rephrase your question....

> I am tring to create webdav client using jackrabbit api.

the jackrabbit-api project doesn't provide any webdav functionality.
rather it provides some jackrabbit specific extensions to the JCR
api.

what is available regarding webdav is present in the
jackrabbit-webdav project:

- webdav specific interfaces
- common implementations without any dependency to JCR
- a couple of extensions to the HttpClient project which does
  not specifically cover webdav.

if you want to create a Webdav client, you first of all
have to make sure, you are having a Webdav server running.
Jackrabbit ships one (simple webdav server) with the
jackrabbit-webapp and jackrabbit-jcr-server project, respectively.
but you may use whatever dav-server you are having at hand.

the simple server exposes a 'file-based' view of the underlying
JCR repository. means: the dav client doesn't need to know
anything about JCR. it just deals with Webdav resources. all
you have to know are the DAV 1,2 and ev. DeltaV RFCs.

Hope that helps
angela

> And I will use some jface class like WebTreeContentProvider and
> WebTreeLabelProvider.
> But I cannot  resolve setInput value.
> (Maybe File class using File.listRoots)
> 
> I read the Website http://wiki.apache.org/jackrabbit/WebDAV .
> But I cannot resolve my trouble.
> 
> So,would you tell me how to make webdav client using
> this method ?
> 
> Souce which I am creating is below.
> -------
> import java.io.IOException;
> import java.util.*;
> import org.apache.commons.httpclient.*;
> import org.eclipse.jface.viewers.*;
> import org.eclipse.jface.window.*;
> import org.eclipse.jface.action.*;
> import org.eclipse.swt.*;
> import org.eclipse.swt.widgets.*;
> import org.eclipse.swt.custom.*;
> import org.eclipse.swt.layout.FillLayout;
> import org.apache.commons.httpclient.auth.AuthScope;
> import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
> import org.apache.jackrabbit.webdav.*;
> import org.apache.jackrabbit.webdav.client.methods.DavMethod;
> import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
> 
> public class JackClient extends ApplicationWindow {
> 	TreeViewer tree;
> 	@SuppressWarnings("unchecked")
> 	Vector sites;
> 	final static String URL = "http://example.kanazawa-u.ac.jp";
> 	
> 	@SuppressWarnings("unchecked")
> 	public JackClient() {
> 		this(new Vector());
> 	}
> 	
> 	@SuppressWarnings("unchecked")
> 	public JackClient(Vector sites){
> 		super(null);
> 		this.sites = sites;
> 	}
> 	protected Control createContents(Composite parent){
> 		
> 		getShell().setText(URL);
>                 getShell().setSize(250, 450);
> 		
> 		Composite composite = new Composite(parent,SWT.NONE);
> 		composite.setLayout(new FillLayout());
> 		tree = new TreeViewer(composite);
> 		tree.setContentProvider(new WebTreeContentProvider());
> 		tree.setLabelProvider(new WebTreeLabelProvider());
> 		tree.setInput(sites);
> 		
> 		return composite;
> 	}
> 	
> 	public class WebTreeContentProvider  implements ITreeContentProvider{
> 		
> 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput){
> 		}
> 		
> 		@SuppressWarnings("unchecked")
> 		public Object[] getElements(Object inputElement){
> 			
> 			Vector list = new Vector();
> 			
> 			try {
> 				DavMethod pFind = new PropFindMethod
> 				("URL",DavConstants.PROPFIND_ALL_PROP,DavConstants.DEPTH_1);
> 				HttpClient client = InitClient();
> 				client.executeMethod(pFind);
> 				MultiStatus multiStatus = pFind.getResponseBodyAsMultiStatus();
> 				MultiStatusResponse[] responses = multiStatus.getResponses();
> 				MultiStatusResponse currResponse;
> 				
> 				for(int i=0; i<responses.length; i++){
> 					currResponse = responses[i];
> 					if(!(currResponse.getHref().equals("/"))){
> 						list.add(currResponse.getHref());
> 					}
> 				}
> 			} catch (Exception e) {
> 				e.printStackTrace();
> 			}
> 			return list.toArray();
> 		}
> 		
> 		public Object[] getChildren(Object elements){
> 			return ((DavResource)elements).getCollection();
> 		}
> 		
> 		public boolean hasChildren(Object object){
> 			return((DavResource)object).isCollection();
> 		}	
> 		
> 		public Object getParent(Object child){
> 			return getChildren(child);
> 		}
> 		
> 		public void dispose(){
> 		}	
> 	}
> 
> 	public class WebTreeLabelProvider extends LabelProvider{
> 		public String getText(Object element){
> 			String name = ((DavResource)element).getHref();
> 			return name;
> 		}	
> 	}
> 	
> 	public class NamedAction extends Action{
> 		String name;
> 		
> 		public String getText(){
> 			return name;
> 		}
> 		
> 	}
> 	
> 	public static HttpClient InitClient(){
> 		HostConfiguration hostConfig = new HostConfiguration();
> 		hostConfig.setHost(URL);
> 		HttpConnectionManager connectionManager = new
> MultiThreadedHttpConnectionManager();
> 		HttpConnectionManagerParams params = new HttpConnectionManagerParams();
> 		int maxHostConnection;
> 		maxHostConnection = 20;
> 		params.setMaxConnectionsPerHost(hostConfig, maxHostConnection);
> 		connectionManager.setParams(params);
> 		HttpClient client = new HttpClient(connectionManager);
> 		Credentials creds = new UsernamePasswordCredentials("","");
> 		client.getState().setCredentials(AuthScope.ANY, creds);
> 		client.setHostConfiguration(hostConfig);
> 
> 		return client;	
> 	}
> 
> 	public static void main(String[] args){
> 		JackClient window = new JackClient();
> 		window.setBlockOnOpen(true);
> 		window.open();
> 		Display.getCurrent().dispose();
> 	}
> 
> }
> 


Mime
View raw message