jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paco Avila <pav...@git.es>
Subject Re: isCheckedOut bug?
Date Wed, 07 Jun 2006 08:12:29 GMT
Here is a sample code:

---------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Hashtable;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Workspace;
import javax.naming.Context;
import javax.naming.InitialContext;

import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.core.jndi.RegistryHelper;

public class IsCheckedOutTest {

	public static void main(String[] args) throws Exception {
		removeRepository();
		Session session = getSession();
		Node root = createRepository(session);
		
		// Add a new node
		Node child = root.addNode("prueba", "nt:file");
		child.addMixin("mix:referenceable");
		child.addMixin("mix:lockable");
		child.addMixin("mix:versionable");
		Node content = child.addNode("jcr:content", "nt:resource");
		content.setProperty("jcr:mimeType", "text/plain");
		content.setProperty("jcr:data", "En un lugar de La Mancha...");
		content.setProperty("jcr:lastModified", Calendar.getInstance());
		
		System.out.println("isCheckedOut: "+child.isCheckedOut());
		root.save();
		System.out.println("isCheckedOut: "+child.isCheckedOut());
	}
	
	/**
	 * 
	 */
	public static void removeRepository() {
		// Remove previous repo
		try {
			FileUtils.deleteDirectory(new File("repotest/repository"));
			FileUtils.deleteDirectory(new File("repotest/versions"));
			FileUtils.deleteDirectory(new File("repotest/workspaces"));
		} catch (IOException e) {
			System.err.println("No previous repo");
		}
	}

	/**
	 * 
	 */
	public static Session getSession() throws Exception {
		Hashtable env = new Hashtable();
		env.put(Context.INITIAL_CONTEXT_FACTORY,
			"org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
		env.put(Context.PROVIDER_URL, "localhost");
		InitialContext ctx = new InitialContext(env);

		// Repository config
		String configFile = "repotest/repository.xml";
		String repHomeDir = "repotest";
		RegistryHelper.registerRepository(ctx, "repo", configFile, repHomeDir,
true);

		// Obtain the repository through a JNDI lookup
		Repository r = (Repository) ctx.lookup("repo");

		// Create a new repository session, after authenticating
		Session session = r.login(new SimpleCredentials("paco",
"".toCharArray()), null);
		System.out.println("Session: "+session);
		return session;
	}
	
	/**
	 * 
	 */
	public static Node createRepository(Session session) throws Exception {
		// Namespace registration
		Workspace ws = session.getWorkspace();
		ws.getNamespaceRegistry().registerNamespace("okm",
"http://www.pepito.org/1.0");

		// Node creation
		Node root = session.getRootNode();
		Node okmRoot = root.addNode("okm:root", "nt:folder");
		okmRoot.addMixin("mix:referenceable");
		session.save();
		System.out.println("Repository created.");
		return okmRoot;
	}
}
---------------------------------------------

-- 
Paco Avila <pavila@git.es>


Mime
View raw message