Java::JCR::Jackrabbit - Java::JCR connector for Jackrabbit
my $repository = Java::JCR::Jackrabbit->new; # Or if you'd like to be more specific: my $other_repository = Java::JCR::Jackrabbit->new('other/repository.xml', 'other');
This is a simple wrapper for
org.apache.jackrabbit.core.TransientRepository. This creates a transient Jackrabbit repository using this class. To learn more about this class, see the Jackrabbit documentation:
This package provides a
new method, which returns a repository object that's ready to use. There are two forms for using
my $repository = Java::JCR::Jackrabbit->new;
This is the fastest and easiest way to get started. However, the Derby database is written in Java and isn't very fast. It's great for quickly getting started, but I wouldn't recommend it for most production environments.
You can use this version of the constructor, but create a file named repository.xml before performing the first login to the database. See the Jackrabbit documentation for more information on how to build such a configuration file.
newmethod. The first is the name of the configuration file to use and the second is the directory to use as the repository home directory. This can be used to connect to repositories named something different or not in the current working directory.
my $repository = Java::JCR::Jackrabbit->new('config.xml', 'jackrabbit');
If the repository doesn't exist, the same action as happens for the first form happens, Jackrabbit creates a generic configuration and directory for storing a Derby-based database, but using the file and directory names you specify instead of repository.xml and repository.
You can customize the configuration as suggested above as well.
There is an additional method provided by this package that allows your Perl program to register custom node types with Jackrabbit.
The JCR (as of JSR 170) does not specify a mechanism for creating custom node types. Therefore, use the
register_node_types() method, to do so:
my $repository = Java::JCR::Jackrabbit->new; my $session = $repository->login( Java::JCR::SimpleCredentials->new('system', 'secret') ); Java::JCR::Jackrabbit->register_node_types($session, 'nodetypes.cnd');
register_nodetypes() method takes two arguments:
After this method returns, all the custom node types found in the given CND file should be registered with Jackrabbit.
Here are a few additional cautionary notes you should consider when using this method:
This code is very basic and is only intended to let you get your nodetypes registered with a minimum of fuss. If you more complex handling of node type or namespace registration, you should write your own Java code to do so.
If you want that code to be accessible from Perl and are not sure where to get started or just need something to start with, see the source of the Java::JCR::Jackrabbit package. The Java class used to perform namespace and node type registration is defined within this package. This code was originally taken from the Jackrabbit documentation and modified to make it work here.
Andrew Sterling Hanenkamp, <firstname.lastname@example.org>
Copyright 2006 Andrew Sterling Hanenkamp <email@example.com>. All Rights Reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.