jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Takuya Matsuhira <taku...@kenroku.kanazawa-u.ac.jp>
Subject Please tell me how to create webdav client
Date Tue, 31 Mar 2009 02:02:39 GMT
HI.
I am Takuya Matsuhira.
(I am not good at English.)

I am tring to create webdav client using jackrabbit api.
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();
	}

}

-- 
+---------------------------------------+
Takuya MATSUHIRA
Information Media Center of Kanazawa University
E-mail:takusng@kenroku.kanazawa-u.ac.jp
+---------------------------------------+


Mime
View raw message