DAISY JAVA ADAPTER

This documentation refers to an alpha version of the Daisy Java Adapter. This means that any interfaces or contracts can change without a preceding deprecation period.

The Daisy Java Adapter requires a Daisy 1.5.1 repository. It won't work with any higher or lower version.

The main goal of the Daisy Java Adapter is making the connection to a Daisy CMS repository as simple as possible from any Java application.

Features

  • Single point of entry. There is one connection object that can be used whether you want to talk to Daisy directly or if you use the Daisy publisher API.
  • There is one Daisy document implementation that gives access to a document using direct Java API calls but also to the XML version returned by the publisher. For this particular purpose the usage of the publisher doesn't require the manual setup of a request object but only configuring a properties object that is used by a builder that creates the publisher request.
  • The repository and the credentials objects are designed setter injection friendly. If used together with Spring, this enables the usage of the PropertyOverriderConfigurer.
  • There is a POM that contains all necessary dependencies on Daisy libraries. If used together with Maven 2, you don't have to do any further investigations on what libraries you need because Maven 2 does everything for you.

Usage

Start your project

Using Maven 2

Maven 2 makes is very simple to bootstrap a Java project that uses the Daisy Java adapter. If you don't have Maven 2 installed or you are not familiar with it, go through the Maven in 5 Minutes tutorial and the Maven Getting Started Guide.

The first step is creating a Maven 2 module. The simplest thing is using a Maven archetype:

mvn archetype:create
  -DarchetypeGroupId=org.apache.maven.archetypes
  -DgroupId=com.mycompany.app
  -DartifactId=my-java-adapter-app

Add a dependency on the Daisy Java Adapter in the pom.xml of the newly created module and add the cocoondev.org Maven 2 repository so that Maven 2 finds all libraries:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-java-adapter-app</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>my-java-adapter-app</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>org.daisycms</groupId>
      <artifactId>daisy-java-adapter</artifactId>  
      <version>1.5.1.0-alpha-2</version> 
    </dependency>     
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <repositories>  
    <repository>
      <id>cocoon.dev</id>
      <url>http://cocoondev.org/repository2</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>        
  </repositories>  
</project>

Maven takes care that all transitive dependencies are resolved correctly.

Without Maven

In the case that you don't like to use Maven 2 as build tool, setup your Java project in the way you prefer. Download the Java Adapter library  and all required dependencies

  • cglib:cglib-nodep:jar:2.1 (scope = compile)
  • commons-collections:commons-collections:jar:3.1 (scope = compile)
  • commons-httpclient:commons-httpclient:jar:2.0.2 (scope = compile)
  • commons-io:commons-io:jar:1.2 (scope = compile)
  • commons-lang:commons-lang:jar:2.1 (scope = compile)
  • commons-logging:commons-logging:jar:1.1 (scope = compile)
  • concurrent:concurrent:jar:1.3.4 (scope = compile)
  • daisy:daisy-jmsclient-api:jar:1.5.1 (scope = compile)
  • daisy:daisy-linkextractors:jar:1.5.1 (scope = compile)
  • daisy:daisy-publisher-api:jar:1.5.1 (scope = compile)
  • daisy:daisy-publisher-client-impl:jar:1.5.1 (scope = compile)
  • daisy:daisy-publisher-xmlschema-bindings:jar:1.5.1 (scope = compile)
  • daisy:daisy-repository-api:jar:1.5.1 (scope = compile)
  • daisy:daisy-repository-client-impl:jar:1.5.1 (scope = compile)
  • daisy:daisy-repository-common-impl:jar:1.5.1 (scope = compile)
  • daisy:daisy-repository-spi:jar:1.5.1 (scope = compile)
  • daisy:daisy-repository-xmlschema-bindings:jar:1.5.1 (scope = compile)
  • daisy:daisy-textextraction-api:jar:1.5.1 (scope = compile)
  • daisy:daisy-util:jar:1.5.1 (scope = compile)
  • easymock:easymock:jar:1.1 (scope = compile)
  • easymock:easymockclassextension:jar:1.1 (scope = compile)
  • javax.servlet:servlet-api:jar:2.3 (scope = compile)
  • junit:junit:jar:3.8.1 (scope = test)
  • log4j:log4j:jar:1.2.12 (scope = compile)
  • logkit:logkit:jar:1.0.1 (scope = compile)
  • org.apache.avalon.framework:avalon-framework-api:jar:4.3 (scope = compile)
  • org.daisycms:daisy-java-adapter:jar:1.5.1.0-alpha-1 (scope = compile)
  • stax:stax-api:jar:1.0 (scope = compile)
  • xmlbeans:xbean:jar:2.1.0 (scope = compile)

and make sure that they are available on your classpath. The daisy:* libraries can be found and downloaded from http://cocoondev.org/repository, all other libraries from http://repo1.maven.org.

Accessing your Daisy repository

Let's assume that your use case is accessing a Daisy document with the id 5 available in your Daisy repository at http://localhost:9263.

First, setup your Daisy repository object:

DaisyCredentials credentials = new DaisyCredentials("admin", "admin-password");
DaisyRepositoryAccessFacade f =  new DaisyRepositoryAccessFacade();
f.setServerUrl("http://localhost:9263");
f.setRemoteAccessCredentials(credentials);
f.setRepoCredentials(credentials);

In order to get a Daisy document, you have to use the DaisyDocumentProxy class. For your convenience, it provides several constructors. For the simples one you only have to know the document id and you have to provide a DaisyRepositoryAccessFacade:

DaisyDocument doc = new DaisyDocumentProxy(222, f);

The DaisyDocument object gives you access to the content of the document. It provides several methods to get the whole document in form of an InputStream, as a byte array, as a String or as SAX events streamed to a provided ContentHandler object.

If the DaisyDocumentProxy class is created while using one its constructors that enables setting a PRDocumentConfiguration object, you can provide more information that will be used to make a proper Publisher request. For example, you can provide information which navigation document should be used to annotate the returned XML.The publisher provides more features that are very useful!

Spring integration

If you want Spring to manage your repository, you only have to define your repository object in a Spring application context, e.g.:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="org.daisycms.clientapps.adapter.credentials.repo" class="org.daisycms.clientapp.adapter.DaisyCredentials"
    scope="singleton" p:login="admin" p:password="admin-password"/>
  
  <bean id="org.daisycms.clientapps.adapter.credentials.remote" class="org.daisycms.clientapp.adapter.DaisyCredentials"
    scope="singleton" p:login="admin" p:password="admin-password"/>
  
  <bean id="org.daisycms.clientapp.adapter.DaisyRepositoryAccessFacade" class="org.daisycms.clientapp.adapter.DaisyRepositoryAccessFacade"
    scope="singleton" lazy-init="true"
    p:serverUrl="http://localhost:9263">
    <property name="repoCredentials" ref="org.daisycms.clientapps.adapter.credentials.repo"/>
    <property name="remoteAccessCredentials" ref="org.daisycms.clientapps.adapter.credentials.remote"/>
  </bean>
  
</beans>

Now its Spring that manages your repository object which supports to be used in a thread safe style, or in Spring terminology the beans scope can be set to singleton (which is the default in Spring anyway).