Java::JCR - Use JSR 170 (JCR) repositories from Perl


Java-JCR documentation Contained in the Java-JCR distribution.

Index


Code Index:

NAME

Top

Java::JCR - Use JSR 170 (JCR) repositories from Perl

SYNOPSIS

Top

  use Java::JCR;
  use Java::JCR::Jackrabbit;

  my $repository = Java::JCR::Jackrabbit->new;
  my $session = $repository->login(
      Java::JCR::SimpleCredentials->new('username', 'password')
  );

  my $root = $session->get_root_node;
  my $node = $root->add_node('foo', 'nt:unstructured');
  $node->set_property('bar', 10);
  $node->set_property('baz', 'blah');
  $node->set_property('qux', 4.8');
  $session->save;

DESCRIPTION

Top

The JSR 170 specification describes a Java-based API for access hierarchical databases. This is generally referred to by the abbreviation JCR, which is an abbreviation for Content Repository API for Java Technology Specification.

The biggest OSS implementation, as of this writing, is Jackrabbit, which is a project at the Apache Software Foundation, http://jackrabbit.apache.org/. Currently, this library allows Perl programmers to develop using the JCR and Jackrabbit, though, there's no reason why connectors can't be written for other implementations, such as Jaceira, CRX, eXoplatform, etc. The JCR library wrappers included are not at all specific to Jackrabbit.

JAVA DOCUMENTATION

Top

At this time, this library does not have documentation for any of the methods used. However, the Perl documentation included with each package links to the Java documentation for that package. That documentation can be used with this API by keeping the following in mind:

IMPLEMENTATION

Top

Here's my opportunity to plug Inline::Java. It works very well and made this possible. There are some deficiencies in exception handling and other places that one would expect difficulties, but all-in-all it works very well. The actual mapping to Java is done through this facility.

In addition, I've created a pure-Perl wrapper object for each to allow me to easily cope with problems in the mappings and to provide an opportunity to hook in better features.

For example, the Java Date object isn't really an ideal solution for Perl coders. Therefore, it is planned that dates be mapped to a Perl equivalent (probably with the option of choosing your favorite since there are quite a few to choose from). This wouldn't be possible if the mapping was just the raw Inline::Java one.

The wrappers also help smooth off some of the rough edges of the mapping from Java.

BUGS

Top

Some things don't work. As of this writing, this is the first release, and I've only done just enough to get the first three "hops" from the Jackrabbit documentation going. You should be able to connect to a repository, login, get nodes and properties by path, create nodes and properties, and import XML using the examples on the Jackrabbit web site. (Perl ports of those are in the ex/ directory of the distribution, by the way.)

If you would like to contribute, let me know of a bug, or make a comment, please send me email at <hanenkamp@@cpan.org> or post a ticket to CPAN RT at http://rt.cpan.org/NoAuth/Bugs.html?Dist=Java-JCR.

SEE ALSO

Top

http://www.jcp.org/en/jsr/detail?id=170, http://www.day.com/maven/jsr170/javadocs/jcr-1.0/, Inline::Java, Java::JCR::Lock, Java::JCR::Nodetype, Java::JCR::Observation, Java::JCR::Query, Java::JCR::Util, Java::JCR::Version, Java::JCR::Jackrabbit

AUTHOR

Top

Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>

LICENSE AND COPYRIGHT

Top


Java-JCR documentation Contained in the Java-JCR distribution.
package Java::JCR;

use strict;
use warnings;

use Carp;
use File::Spec;

our $VERSION = '0.08';

# Setup the Java Classpath
my $classpath;
BEGIN {
    my @classpath;
    my $this_path = $INC{'Java/JCR.pm'};
    $this_path =~ s/\.pm$//;
    my $jar_glob = File::Spec->catfile($this_path, "*.jar");
    for my $jar_file (glob $jar_glob) {
        push @classpath, $jar_file;
    }
    $classpath = join ':', @classpath, ($ENV{'CLASSPATH'} || '');
    $ENV{'CLASSPATH'} = $classpath;
}

use Inline (
    Java => <<'END_OF_JAVA',

class PerlUtils {
    public static char[] charArray(String str) {
        return str.toCharArray();
    }
}

END_OF_JAVA
    STUDY => [],
    CLASSPATH => $classpath,
);

sub import_my_packages {
    my ($package_name, $package_file) = caller;
    my %excludes = map { $_ => 1 } @_;

    my $package_dir = $package_file;
    $package_dir =~ s/\.pm$//;
    my $package_glob = File::Spec->catfile($package_dir, '*.pm');

    for my $package (glob $package_glob) {
        $package =~ s/^$package_dir\///;
        $package =~ s/\.pm$//;
        $package =~ s/\//::/g;

        next if $excludes{$package};

        eval "use ${package_name}::$package;";
        if ($@) { carp "Error loading $package: $@" }
    }
}

import_my_packages( 
    qw(
        Lock
        Nodetype
        Observation
        Query
        Util
        Version
    )
);

1