JCR Basics

Get low level access to your content.

Introduction

Hippo Repository provides a standard Java Content Repository (JCR) interface that is also known as Java Specification Request 170. It uses an Apache JackRabbit implementation. This page explains how to connect with the repository, and how to use the JCR interface and work with the content inside the repository.

Connecting with Hippo Repository

A Java client that wants to use the interface must retrieve a javax.jcr.Session object. A static factory class is available to help with that. A simple example on how to connect and login to a Hippo Repository based on location, user name and password is:

HippoRepository repository = HippoRepositoryFactory.getHippoRepository("rmi://localhost:1099/hipporepository"); Session session = repository.login(<userName>, <password>);

Working with JCR

Once you have obtained a session object, you have access to the content inside the repository. You can for example retrieve the root node through the session object, and iterate through its child nodes:

Node rootNode = session.getRootNode(); NodeIterator nodes = rootNode.getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); System.out.println(node.getPath()); }

See the JCR API for a complete reference.

Dependencies

Connecting with Hippo Repository, and using its JCR interface, requires the following jar files on your classpath:

  • jcr
  • jta
  • hippo-ecm-api
  • hippo-ecm-repository-connector
  • slf4j-api
  • jcl104-over-slf4j
  • slf4j-log4j12

If you use Maven 2 to build your project, you need to add the following dependencies to your pom:

<dependency> <groupId>javax.jcr</groupId> <artifactId>jcr</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>javax.transaction</groupId> <artifactId>jta</artifactId> <version>1.0.1B</version> </dependency> <dependency> <groupId>org.hippoecm</groupId> <artifactId>hippo-ecm-api</artifactId> <version>2.01.00.13536</version> </dependency> <dependency> <groupId>org.hippoecm</groupId> <artifactId>hippo-ecm-repository-connector</artifactId> <version>2.01.00.13536</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.3</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl104-over-slf4j</artifactId> <version>1.5.3</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.5.3</version> </dependency>

Complete Example Class

package org.example; import javax.jcr.LoginException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; import org.hippoecm.repository.HippoRepository; import org.hippoecm.repository.HippoRepositoryFactory; public class App { public static void main( String[] args ) { try { HippoRepository repository = HippoRepositoryFactory.getHippoRepository("rmi://localhost:1099/hipporepository"); Session session = repository.login("admin", "admin".toCharArray()); Node rootNode = session.getRootNode(); NodeIterator nodes = rootNode.getNodes(); while (nodes.hasNext()) { Node node = nodes.nextNode(); System.out.println(node.getPath()); } } catch (LoginException e) { System.out.println(e.getMessage()); } catch (RepositoryException e) { e.printStackTrace(); } } }

Next

Now that you know how to connect with Hippo Repository, proceed to the examples to get an idea of what functionality is available through the JCR interface.

Hippo Europe: +31 (0)20 5224466
Hippo North America: +1 (707) 773-4646