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.
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>);
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.
Connecting with Hippo Repository, and using its JCR interface, requires the following jar files on your classpath:
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>
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();
}
}
}
Hippo Europe: +31 (0)20 5224466
Hippo North America: +1 (707) 773-4646
© 1999-2010 Hippo B.V., All Rights Reserved