Code Monkey home page Code Monkey logo

pydio-sdk-java-v2's Introduction

The pydio java sdk provides a Java implementation of Pydio features for communicating with a Pydio server. All the features are wrapped by the PydioClient class that contains simple methods to do the main file system operations.

The data model:

Pydio model is based on the notion of tree. In fact a server is the root node of a tree which has WorkspaceNode as children. Each WorkspaceNode has a list of FileNodes as children which have other FileNodes as children too. So a hierarchy is defined by an abstract Node class and concrete classes like ServerNode, WorkspaceNode and FileNode.

Configuring a Pydio server:

Confuguring a Pydio server is configuring a ServerNode. The SDK provides two method for configuring a serverNode. A simple one that consist of setting manully the server properties, and the other one is based on a resolution process.

  • Simple configuration
	//step 1: create an empty instance of a ServerNode using the NodeFactory
	ServerNode server = (ServerNode) NodeFactory.createNode(Node.TYPE_SERVER);

	//step 2: set server info like host, protocol, path, has self-signed ssl certicicate
	server.setHost("hostname");
	server.setPath("path_of_your_pydio_install");
	server.setSelfSigned(boolvalue); //only if the target server use self-signed certificate
	server.setLegacy(PYDIO_SERVER_VERSION > 5);	//for version pydio version greater than 5
  • Resolution-based configuration

this case depend on the context in which you use the sdk. For example, let's suppose you're building an application that connect to a server that has not a fixed domain name or ip. But you have a way to retrieve it using a special protocol. The resolution process allows you to handle this case. The SDK provides an interface that need to be implemented to spécify the way your app retrieve te properties of your serverNode. here is an exmaple of using a Resolver.

	...
	//step 1: create an instance of ServerResolver

	String KEY = "key";
	ServerResolver resolver = new ServerResolver(){
		@override
		public void resolve(ServerNode server){
			// do your resolution stuff here
			// and set your serverNode properties
		}
	};

	//step 2: register your resolver like this
	Resolution.register(KEY, resolver);
	ServerNode server = NodeFactory.createNode(Node.TYPE_SERVER);

	// specify that your serverNode properties need to resolved
	// by setting the hostname with the same key you've just 
	// when registering your resolver	
	server.setHost(KEY);

Creation of a Pydio Client:

The creation of a PydioClient is based on an an instance of a ServerNode and an instance of a credentials provider. A credential provider is a an object that carry/fetches credentials for pydio authentication. Here is the simplest way to instantiate a PydioClient:

	...
	PydioClient client = PydioClient.configure(server, new CredentialsProvider(){
        @Override
        public UsernamePasswordCredentials requestForLoginPassword() {
            return new UsernamePasswordCredentials("login", "password");
        }
        @Override
        public X509Certificate requestForCertificate() {
            return null;
        }
	});

Performing simple actions:

Once your pydio client is configured, you can start calling the client methods to perform file operations on your server.

Note that PydioClient is design to perform asynchrone operations. So for operation that requires result like file listing, you need to pass a callback to process one by one every parsed node. The example below stores and displays the name of each child of a given node.

	...
	final ArrayList<Node> children = new ArrayList<>();
	client.listChildren(givenNode, new NodeHandler(){
		@Override
		public void processNode(Node node){
			//filter to exclude the recyclebin file
			if(!node.label().equals("Recycle Bin")){
				System.out.println(node.label());
				children.add(node);
			}
		}
	}, offset, max);
	//note that is the given node is null, the client automatically list the workspaces of the serverNode.
	// the offset and max arguments are both integer that allows you to list only subset of the givenNode children

pydio-sdk-java-v2's People

Contributors

jabarkarim avatar

Watchers

James Cloos avatar Ahmed Omarjee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.