package oracle.sample.jcr; import java.util.Hashtable; import javax.jcr.NodeIterator; import javax.jcr.Session; import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.SimpleCredentials; import javax.naming.Context; import oracle.ocs.jcr.RepositoryFactory; import oracle.ocs.jcr.BeehiveRepositoryConfiguration; public class EntList { static void traverseNode(Node root, int level) throws javax.jcr.RepositoryException { // Limit how deep this method traverses the workspace if (level > 3) return; String indent = ""; for (int i = 0; i < level; i++) { indent += " "; } System.out.println(indent + root.getName()); // Get a NodeIterator to iterate over all the child nodes of root NodeIterator iter = root.getNodes(); while (iter.hasNext()) { Node currentNode = iter.nextNode(); traverseNode(currentNode, level + 1); } } public static void main(String[] args) throws Exception { // Create new Hashtable, to pass connection attributes Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "oracle.j2ee.rmi.RMIInitialContextFactory"); env.put(Context.SECURITY_PRINCIPAL, "oc4jadmin"); env.put(Context.SECURITY_CREDENTIALS, "Welcome1"); env.put(Context.PROVIDER_URL, "opmn:ormi://example.com:6003:BEEAPP/jcr-service"); BeehiveRepositoryConfiguration config = new BeehiveRepositoryConfiguration(env); // Get the repository with the given beehive repository configuration Repository rep = (Repository) RepositoryFactory.createRepository(config); // Create the javax.jcr.SimpleCredentials object by giving the username and // password of the repository SimpleCredentials cred = new SimpleCredentials("beeadmin", "Welcome1".toCharArray()); // Authenticate Session sess = rep.login(cred); // Get the root node Node root = sess.getRootNode(); System.out.println("Root node path: " + root.getPath()); System.out.println("Root node name: " + root.getName()); try { System.out.println("Traversing workspace..."); System.out.println("-------------------------------"); traverseNode(root, 0); System.out.println("-------------------------------"); System.out.println("DONE"); } catch (Exception e) { System.out.println("Exception caught: " + e.toString()); e.printStackTrace(); } } }