1package Net::OAI::ResumptionToken;
2
3use strict;
4use warnings;
5use base qw( XML::SAX::Base );
6use Carp qw( carp );
7
8
9=head1 NAME
10
11Net::OAI::ResumptionToken - An OAI-PMH resumption token.
12
13=head1 SYNOPSIS
14
15=head1 DESCRIPTION
16
17This SAX filter records resumption token elements.
18
19=head1 METHODS
20
21=head2 new()
22
23=cut
24
25sub new {
26    my ( $class, %opts ) = @_;
27    my $self = bless \%opts, ref( $class ) || $class;
28    $self->{ _insideResumptionToken } = 0;
29    $self->{ token } = $self->{ expirationDate } = $self->{ completeListSize } = $self->{ cursor } = undef;
30    return( $self );
31}
32
33=head2 token()
34
35(Sets and) returns the contents of the resumptionToken element.
36
37All methods return C<undef> if no token was encountered.
38
39=cut
40
41sub token {
42    my ( $self, $token ) = @_;
43    if ( $token ) { $self->{ token } = $token; }
44    return( $self->{ resumptionTokenText } );
45}
46
47=head2 expirationDate()
48
49=cut
50
51sub expirationDate {
52    my ( $self, $date ) = @_;
53    if ( $date ) { $self->{ expirationDate } = $date; }
54    return( $self->{ expirationDate } );
55}
56
57=head2 completeListSize()
58
59=cut
60
61sub completeListSize {
62    my ( $self, $size ) = @_;
63    if ( $size ) { $self->{ completeListSize } = $size; }
64    return( $self->{ completeListSize } );
65}
66
67=head2 cursor()
68
69=cut 
70
71sub cursor {
72    my ( $self, $cursor ) = @_;
73    if ( $cursor ) { $self->{ cursor } = $cursor; }
74    return( $self->{ cursor } );
75}
76
77
78=head1 AUTHORS
79
80Ed Summers <ehs@pobox.com>
81
82=cut
83
84## internal stuff
85
86## all children of Net::OAI::Base should call this to make sure
87## certain object properties are set
88sub start_prefix_mapping {
89  my ($self, $mapping) = @_;
90  die "rT: self not defined" unless defined $self;
91  return $self->SUPER::start_prefix_mapping( $mapping ) if $self->get_handler();
92  die "rT: start_prefix_mapping @{[$mapping]} w/o Handler";
93}
94
95
96sub start_element {
97    my ( $self, $element ) = @_;
98    return $self->SUPER::start_element( $element ) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
99
100    if ( $element->{ LocalName } eq 'resumptionToken' ) {
101	my $attr = $element->{ Attributes };
102	$self->{ expirationDate } = $attr->{ '{}expirationDate' }{ Value } if $attr->{ '{}expirationDate' };
103	$self->{ completeListSize } = $attr->{ '{}completeListSize' }{ Value } if $attr->{ '{}completeListSize' };
104	$self->{ cursor } = $attr->{ '{}cursor' }{ Value } if $attr->{ '{}cursor' };
105	$self->{ resumptionTokenText } = "";
106	$self->{ _insideResumptionToken } = 1;
107    } elsif ( $self->{ _insideResumptionToken } ) {
108        carp "start of unhandled subelement ".$element->{ Name }." within resumptionToken";
109    } else {
110	$self->SUPER::start_element( $element );
111    }
112}
113
114sub end_element {
115    my ( $self, $element ) = @_;
116    return $self->SUPER::end_element( $element ) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI;
117
118    if ( $element->{ LocalName } eq 'resumptionToken' ) {
119        Net::OAI::Harvester::debug( "caught resumption token" );
120	$self->{ _insideResumptionToken } = 0;
121    } elsif ( $self->{ _insideResumptionToken } ) {
122        carp "end of unhandled subelement ".$element->{ Name }." within resumptionToken";
123    } else {
124	$self->SUPER::end_element( $element );
125    }
126}
127
128sub characters {
129    my ( $self, $characters ) = @_;
130
131    if ( $self->{ _insideResumptionToken } ) {
132	$self->{ resumptionTokenText } .= $characters->{ Data };
133    } else {
134	$self->SUPER::characters( $characters );
135    }
136}
137
1381;
139
140