Java-JCR
    
    
  
  
  
view release on metacpan or search on metacpan
Java::JCR Revision History
0.07    2006-07-30 22:48    Andrew Sterling Hanenkamp
    * [rt.cpan.org #20758] FIXED: Static methods work correctly now.
    * [rt.cpan.org #20767] FIXED: Changed calendar routines so that they use the
      HOUR_OF_DAY constant rather than HOUR so that dates work correctly.
    * Added t/09-jackrabbit-timezone.t to better test time zone handling and
      reveal [rt.cpan.org #20767].
    * Added t/10-property-type.t to test constants and such and to identify
      [rt.cpan.org #20758].
0.06    2006-06-25 14:52    Andrew Sterling Hanenkamp
    * Added register_node_types() to Java::JCR::Jackrabbit to allow for very
      simple node type registration.
      properly.
0.05    2006-06-17 21:21    Andrew Sterling Hanenkamp
    * Added the Java::JCR::Calendar class for handling Java-to-Perl and
    * Perl-to-Java date conversions.
    * Added built-in support for DateTime and Class::Date classes when using any
    * JCR method that returns a date or takes a date as an argument.
    * Added support for allowing the end-user to add custom conversions to use
    * other date classes instead of just those built-in.
    * Added t/07-jackrabbit-calendar.t t test the new date support.
0.04    2006-06-16 20:19    Andrew Sterling Hanenkamp
    * Added the Java::JCR::Exception class for handling exceptions.
    * Updated inc/package-generator.pl to use the new exception class.
    * Added t/06-jackrabbit-exception.t to test the new exception class.
    * Altered inc/package-generator.pl so that it does not generate any class
      ending with "Exception".
    * All classes ending with "Exception" (other than Java::JCR::Exception) have
      been removed.
LICENSE
MANIFEST			This list of files
META.yml
README
t/01-use.t
t/02-pod.t
t/03-jackrabbit-anonymous.t
t/04-jackrabbit-add-node.t
t/05-jackrabbit-multiple.t
t/06-jackrabbit-exception.t
t/07-jackrabbit-calendar.t
t/08-jackrabbit-nodetypes.t
t/09-jackrabbit-timezone.t
t/10-property-type.t
t/nodetypes.cnd
inc/specials.yml view on Meta::CPAN
javax.jcr.Node:
  set_property: |-
    sub set_property {
        my $self = shift;
        my ($name, $value) = @_;
        my @args;
        if (Java::JCR::Calendar::_perl_date_has_conversion($value)) {
            @args = ($name, Java::JCR::Calendar::_perl_date_to_java_calendar($value));
        }
        else {
            @args = Java::JCR::Base::_process_args(@_);
        }
        my $result = eval { $self->{obj}->setProperty(@args) };
        if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
        return Java::JCR::Base::_process_return($result, 'javax.jcr.Property', 'Java::JCR::Property');
    }
javax.jcr.Property:
  get_date: |-
    sub get_date {
        my ($self, $class) = @_;
        my $result = $self->{obj}->getDate();
        return Java::JCR::Calendar::_java_calendar_to_perl_date($result, $class);
    }
javax.jcr.Session:
  import_xml: |-
    sub import_xml {
        my $self = shift;
        my $path = shift;
        my $handle = shift;
        my $behavior = shift;
inc/specials.yml view on Meta::CPAN
        }, $class;
    }
javax.jcr.Value:
  get_date: |-
    sub get_date {
        my ($self, $class) = @_;
        my $result = $self->{obj}->getDate();
        return Java::JCR::Calendar::_java_calendar_to_perl_date($result, $class);
    }
javax.jcr.ValueFactory:
  create_value: |-
    sub create_value {
        my $self = shift;
        my ($value) = @_;
        my @args;
        if (Java::JCR::Calendar::_perl_date_has_conversion($value)) {
            @args = (Java::JCR::Calendar::_perl_date_to_java_calendar($value));
        }
        else {
            @args = Java::JCR::Base::_process_args(@_);
        }
        my $result = eval { $self->{obj}->createValue(@args) };
        if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
        return Java::JCR::Base::_process_return($result, 'javax.jcr.Value', 'Java::JCR::Value');
lib/Java/JCR/Calendar.pm view on Meta::CPAN
  GMT+10:45
The time zone may also be specified as a named zone (which is usually better because named zones can cope with local rules dealing with Daylight Savings Time and other adjustments---such as new legislation changing DST). However, Java doesn't specify...
Since L<DateTime::TimeZone> uses the Olson database for it's time zones, you may use that as a reference.
If no time zone is specified during deflation, Java will be told to assume the default time zone. The default is generally the local time zone, but may vary depending upon your JVM configuration.
=item locale
I'm not certain if this is actually significant to how the JCR stores a calendar object, but I've included it for completeness (and it doesn't require much in the way of extra effort either way).
The locale must be specified using the ISO-639 and ISO-3166 standards with the possiblity of vendor or browser-specific variant codes. See the Javadoc for C<java.util.Locale> if you want more specific details.
If no locale is specified during deflation, the default Java locale will be used.
=item lenient
By setting this to a true value, the C<java.util.Calendar> object will have the lenient setting set to true. This will allow you to specify month, day, hour, minute, second, and nanosecond values outside the normal range without throwing an exception...
This value defaults to false. Thus, if it isn't given, an exception will be thrown when an out of bounds value is given.
The hash given to the inflation function will always have this value set to false. However, your inflation function may be as lenient or strict as desired. The Calendar implementation on your JVM should return valid dates, so it shouldn't be an issue...
=back
All dates are, obviously, according to the Gregorian calendar, which is due to the fact that the Calendar API of Java only fully supports Gregorian-style calendars. However, since we're using Perl, we're not limited to that calendar. If you want to, ...
The inflation function, C<\&inflater>, can expect a single argument, which is the hash (as described above), containing all the above fields filled. The inflation function must return an object of the specified class, C<$class>, or throw an exception...
During inflation, the hash will be created by reading in the fields set on the C<java.util.Calendar> object returned by the JCR.
The deflation function, C<\&deflater>, can expect a single argument, which is an object blessed into the specified class, C<$class>. The deflation function must return a hash containing the date (as described above). The date fields must be set.
During deflation, a C<java.util.Calendar> object will be created by fetching a Calendar instance according to the time zone and locale specified in the hash returned by the C<\&deflater> function. Then, each field will be set in the following order: ...
=cut
lib/Java/JCR/Calendar.pm view on Meta::CPAN
sub _perl_date_has_conversion {
    my ($date) = @_;
    my $class = blessed $date;
    return !defined $class                    ? 0
         :  defined $date_conversions{$class} ? 1
         :                                      0;
}
sub _perl_date_to_java_calendar {
    my ($date) = @_;
    my $class = blessed $date;
    croak 'Cannot use an unblessed date object' if not defined $class;
    croak qq(No Perl-to-Java date conversion is available for "$class")
        if not defined $date_conversions{$class};
    my $conversion = $date_conversions{$class};
    my $deflater = $conversion->{deflater};
    return Java::JCR::JavaUtils::hash_to_calendar($deflater->($date));
}
sub _java_calendar_to_perl_date {
    my ($calendar, $class) = @_;
    $class ||= $default_date_class;
    croak 'Cannot convert date from Java to Perl: ',
          'No date class was given and no default is available.'
        if not defined $class;
    croak qq(No Java-to-Perl date conversion is available for "$class")
        if not defined $date_conversions{$class};
    my $conversion = $date_conversions{$class};
    my $inflater = $conversion->{inflater};
    return $inflater->(Java::JCR::JavaUtils::calendar_to_hash($calendar));
}
eval 'use DateTime';
if (!$@) {
    __PACKAGE__->register_date_conversion(
        'DateTime',
        sub { # inflater
            my ($hash) = @_;
            my $time_zone = $hash->{timezone};
lib/Java/JCR/JavaUtils.pm view on Meta::CPAN
}
sub input_stream {
    my $glob = shift;
    my $glob_val = $$glob;
    $glob_val =~ s/^\*//;
    my $glob_caller = Java::JCR::GlobCaller->new($glob_val);
    return Java::JCR::GlobInputStream->new($glob_caller);
}
sub calendar_to_hash {
    my ($calendar) = @_;
    $calendar    = cast('java.util.Calendar', $calendar);
    my $timezone = cast('java.util.TimeZone', $calendar->getTimeZone());
    my $tz_offset = $timezone;
    return {
        year       => $calendar->get($Java::JCR::java::util::Calendar::YEAR),
        month      => $calendar->get($Java::JCR::java::util::Calendar::MONTH),
        day        => $calendar->get(
                          $Java::JCR::java::util::Calendar::DAY_OF_MONTH),
        hour       => $calendar->get(
                          $Java::JCR::java::util::Calendar::HOUR_OF_DAY),
        minute     => $calendar->get($Java::JCR::java::util::Calendar::MINUTE),
        second     => $calendar->get($Java::JCR::java::util::Calendar::SECOND),
        nanosecond => $calendar->get(
                          $Java::JCR::java::util::Calendar::MILLISECOND) 
                          * 1_000_000,
        timezone   => $timezone->getID(),
        lenient    => 0,
    };
}
sub hash_to_calendar {
    my ($hash) = @_;
    my $calendar;
    if (defined $hash->{timezone} && defined $hash->{locale}) {
        my ($language, $country, $variant) = split /_/, $hash->{locale};
        $calendar = Java::JCR::java::util::Calendar->getInstance(
            Java::JCR::java::util::TimeZone->getTimeZone($hash->{timezone}),
            Java::JCR::java::util::Locale->new($language, $country, $variant),
        );
    }
    elsif (defined $hash->{timezone}) {
        $calendar = Java::JCR::java::util::Calendar->getInstance(
            Java::JCR::java::util::TimeZone->getTimeZone($hash->{timezone}),
        );
    }
    elsif (defined $hash->{locale}) {
        my ($language, $country, $variant) = split /_/, $hash->{locale};
        $calendar = Java::JCR::java::util::Calendar->getInstance(
            Java::JCR::java::util::Locale->new($language, $country, $variant),
        );
    }
    else {
        $calendar = Java::JCR::java::util::Calendar->getInstance();
    }
    $calendar = cast('java.util.Calendar', $calendar);
    $calendar->setLenient($hash->{lenient}) if defined $hash->{lenient};
    $calendar->set($Java::JCR::java::util::Calendar::YEAR, $hash->{year});
    $calendar->set($Java::JCR::java::util::Calendar::MONTH, $hash->{month});
    $calendar->set($Java::JCR::java::util::Calendar::DAY_OF_MONTH, 
        $hash->{day});
    $calendar->set($Java::JCR::java::util::Calendar::HOUR_OF_DAY, 
        $hash->{hour});
    $calendar->set($Java::JCR::java::util::Calendar::MINUTE, $hash->{minute});
    $calendar->set($Java::JCR::java::util::Calendar::SECOND, $hash->{second});
    return $calendar;
}
=head1 AUTHOR
Andrew Sterling Hanenkamp, E<lt>hanenkamp@cpan.orgE<gt>
=head1 LICENSE AND COPYRIGHT
Copyright 2006 Andrew Sterling Hanenkamp E<lt>hanenkamp@cpan.orgE<gt>.  All 
Rights Reserved.
lib/Java/JCR/Node.pm view on Meta::CPAN
    return $result;
}
sub set_property {
    my $self = shift;
    my ($name, $value) = @_;
    my @args;
    if (Java::JCR::Calendar::_perl_date_has_conversion($value)) {
        @args = ($name, Java::JCR::Calendar::_perl_date_to_java_calendar($value));
    }
    else {
        @args = Java::JCR::Base::_process_args(@_);
    }
    my $result = eval { $self->{obj}->setProperty(@args) };
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return Java::JCR::Base::_process_return($result, 'javax.jcr.Property', 'Java::JCR::Property');
lib/Java/JCR/Property.pm view on Meta::CPAN
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return $result;
}
sub get_date {
    my ($self, $class) = @_;
    my $result = $self->{obj}->getDate();
    return Java::JCR::Calendar::_java_calendar_to_perl_date($result, $class);
}
sub get_ancestor {
    my $self = shift;
    my @args = Java::JCR::Base::_process_args(@_);
    my $result = eval { $self->{obj}->getAncestor(@args) };
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return Java::JCR::Base::_process_return($result, "javax.jcr.Item", "Java::JCR::Item");
lib/Java/JCR/Value.pm view on Meta::CPAN
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return $result;
}
sub get_date {
    my ($self, $class) = @_;
    my $result = $self->{obj}->getDate();
    return Java::JCR::Calendar::_java_calendar_to_perl_date($result, $class);
}
sub get_type {
    my $self = shift;
    my @args = Java::JCR::Base::_process_args(@_);
    my $result = eval { $self->{obj}->getType(@args) };
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return $result;
lib/Java/JCR/ValueFactory.pm view on Meta::CPAN
use Inline::Java qw( study_classes );
study_classes(['javax.jcr.ValueFactory'], 'Java::JCR');
sub create_value {
    my $self = shift;
    my ($value) = @_;
    my @args;
    if (Java::JCR::Calendar::_perl_date_has_conversion($value)) {
        @args = (Java::JCR::Calendar::_perl_date_to_java_calendar($value));
    }
    else {
        @args = Java::JCR::Base::_process_args(@_);
    }
    my $result = eval { $self->{obj}->createValue(@args) };
    if ($@) { my $e = Java::JCR::Exception->new($@); croak $e }
    return Java::JCR::Base::_process_return($result, 'javax.jcr.Value', 'Java::JCR::Value');
( run in 0.742 second using v1.01-cache-2.11-cpan-5dc5da66d9d )