Oracle Beehive Java Content Repository API

Oracle Beehive Java Content Repository API

Oracle Beehive Java Content Repository (JCR) API implements the Content Repository API for Java Technology specification (Java Specification Request 170, version 1.0). You may find this specification at http://jcp.org/en/jsr/detail?id=170. The Content Repository API is a common, standardized Java interface for content repositories. With the Oracle Beehive JCR API, you may access and manipulate an Oracle Beehive instance’s workspaces and its data like a content repository.

The Content Repository API specification is divided into two compliance levels and a set of additional optional features that repositories of either level may support. Level 1 consists of read functions while level 2 adds additional write functions. Oracle Beehive JCR API supports the following features specified by the Content Repository API specification:

  • Level 1 Repository Features
    • Retrieval and traversal of nodes and properties
    • Reading values of properties
    • Transient namespace remapping
    • Discovery of available node types
    • Discovery of access control permissions
  • Level 2 Repository Features
    • Adding and removing nodes and properties
    • Writing values of properties
  • Optional Features
    • Versioning
    • Locking

This module covers the following topics:

  • Requirements
  • Javadoc
  • Oracle Beehive Java Content Repository API Operations
  • Oracle Beehive Java Content Repository API Samples
  • Compiling and Running Samples

Requirements

To compile the examples in this module, the following .jar files must be in your classpath:

  • <Oracle home>/beehive/jlib/beehive_jcr-1.0.jar
  • <Oracle home>/j2ee/home/lib/ejb.jar
  • <Oracle home>/j2ee/home/lib/ejb30.jar
  • <Oracle home>/j2ee/home/lib/oc4j-internal.jar
  • <Oracle home>/j2ee/home/oc4jclient.jar
  • <Oracle home>/lib/xmlparserv2.jar
  • <Oracle home>/opmn/lib/optic.jar

Note: For a standalone client (for example, EntList.java and JcrClient.java), you only require beehive_jcr-1.0.jar in your classpath.

Javadoc

Refer to Oracle Beehive Java Content Repository Java API Reference.

Oracle Beehive Java Content Repository API Operations

The Oracle Beehive JCR API enables you to manipulate an Oracle Beehive instance’s workspaces and its data like a content repository as defined by the Content Repository API.

The content repository as a whole is represented by a javax.jcr.Repository object, which is acquired from the oracle.ocs.jcr.client.impl.RepositoryFactory class. A client connects to the repository by calling Repository.login(). This method takes one argument, an object of type javax.jcr.Credentials (in particular, a SimpleCredentials object). This object contains the user name and password of a user that may look up the JCR service. The login() method returns a Session object with which the client accesses the repository.

Content in a repository, such as folders and documents, are represented by nodes in a tree structure. You may access nodes by traversal access or direct access. Traversal access involves accessing nodes in relation to other nodes. For example, you may call Node.getNodes() to retrieve a NodeIterator, which will enable you to iterate through a given node’s child nodes. Direct access involves accessing nodes with absolute paths. If a node is referenceable, you can directly access a node by its Universally Unique Identifier (UUID). For example, you may directly access a node by its absolute path with Session.getItem() or by its UUID with Session.getNodeByUUID().

Oracle Beehive Java Content Repository API Samples

This section lists the following samples:

  • Sample of Level 1 Operations
  • Sample of Level 2 Operations
  • Sample of Invoking JCR API in a Servlet Application

Sample of Level 1 Operations

The following sample initializes the repository and performs a high-level traversal of the repository.

EntList.java

The following is the output of EntList.java. The output will vary depending on the content of your repository:

Root node path: /
Root node name: /
Traversing workspace...
-------------------------------
/
  oracle
    doc
    beeadmin's Personal Workspace
      INBOX
      Documents
      Notifications
      Public Documents
      Subscriptions
      Workspace Trash
-------------------------------
DONE

Sample of Level 2 Operations

The following sample performs the following:

  • Initializes the repository
  • Adds a folder node and saves it
  • Adds a content node and accesses it
  • Removes the content node

The path specified by docFolderPath must exist in your repository.

JcrClient.java

The following is the output of JcrClient.java:

Successfully logged in. Session Object oracle.ocs.jcr.client.impl.SessionImpl@1dc0e7a
Added Folder Node to Workspace Node
About to add file NewFile1197504256484
Setting property of type BEEHIVE_CONTENT
Added the file and updated the content
Content = I got updated
Removed node

Sample of Invoking JCR API in a Servlet Application

The following servlet lists the enterprise node:

ListEntNode.java

You should see text similar to the following in a browser when you access the servlet:

Oracle Beehive Java Content Repository Test

Retrieved the repository object from the repository factory

Finished setting credentials

Retrieved session: oracle.ocs.jcr.client.impl.SessionImpl@6d1750

Retrieved root node of the workspace: /

User ID used to acquire the session: beeadmin

List of nodes in the oracle node:

  • doc
  • beeadmin’s Personal Workspace

Compiling and Running Samples

This section covers the following topics:

  • Compiling and Running Stand-Alone Applications
  • Deploying Servlets on Apache Tomcat

Compiling and Running Stand-Alone Applications

To compile and run "Sample of Level 1 Operations" or "Sample of Level 2 Operations", ensure that all the .jar files listed in "Requirements" are in your classpath. Compile these samples with JDK 1.5 or later.

Deploying Servlets on Apache Tomcat

The following steps describe how to deploy the sample listed in "Sample of Invoking JCR API in a Servlet Application".

Requirements

  • JDK 1.5 or later
  • Apache Tomcat 5.5.2 or later
  • The .jar files listed in "Requirements" are available in the Apache Tomcat library path

Steps to Deploy JCR API Servlet

  1. Create the directory jcrtest to hold the files of the servlet.

  2. In the directory jcrtest, create the directory WEB-INF.

  3. In the WEB-INF directory, create the following directory structure:

    • classes

    • lib

    • src

  4. In the src directory, create the nested directory oracle/sample/jcr. Save the file ListEntNode.java in the jcr directory.

  5. Copy the .jar files listed in "Requirements" to the lib directory.

  6. In the WEB-INF directory, create a file named web.xml that contains the following (the string specified by the attribute xsi:schemaLocation should appear on one line):

    
    <?xml version="1.0" encoding="ISO-8859-1"?>
    
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4">
    
      <servlet>
        <servlet-name>ListEntNode</servlet-name>
        <servlet-class>oracle.sample.jcr.ListEntNode</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>ListEntNode</servlet-name>
        <url-pattern>/listnodes</url-pattern>
      </servlet-mapping>
    </web-app>
    
    
  7. Compile ListEntNode.java as described in "Compiling and Running Stand-Alone Applications". Ensure that the compiled ListEntNode.class file appears in the classes/oracle/sample/jcr directory.

  8. Copy the jcrtest directory to <Apache Tomcat install directory>/webapps. Restart Apache Tomcat. Apache Tomcat will automatically deploy the servlet for you. Access the servlet with http://localhost:8080/jcrtest/listnodes (assuming that you are running Apache Tomcat on port 8080.

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy