source: gsdl/trunk/perllib/manifest.pm@ 18379

Last change on this file since 18379 was 17249, checked in by kjdon, 16 years ago

need to ignore Manifest tag in xml_start_tag

  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1package manifest;
2
3
4use XMLParser;
5use strict;
6no strict 'refs'; # allow filehandles to be variables and viceversa
7
8
9our $self;
10
11sub new {
12 my ($class) = shift (@_);
13
14 $self = {} ;
15
16 $self->{'index'} = {};
17 $self->{'reindex'} = {};
18 $self->{'delete'} = {};
19
20 return bless $self, $class;
21}
22
23sub parse
24{
25 my ($self) = shift (@_);
26 my ($filename) = @_;
27
28 my $parser = new XML::Parser('Style' => 'Stream',
29 'Handlers' => {'Char' => \&Char,
30 'XMLDecl' => \&XMLDecl,
31 'Entity' => \&Entity,
32 'Doctype' => \&Doctype,
33 'Default' => \&Default
34 });
35
36 $parser->parsefile($filename);
37}
38
39sub StartDocument {$self->xml_start_document(@_);}
40sub XMLDecl {$self->xml_xmldecl(@_);}
41sub Entity {$self->xml_entity(@_);}
42sub Doctype {$self->xml_doctype(@_);}
43sub StartTag {$self->xml_start_tag(@_);}
44sub EndTag {$self->xml_end_tag(@_);}
45sub Text {$self->xml_text(@_);}
46sub PI {$self->xml_pi(@_);}
47sub EndDocument {$self->xml_end_document(@_);}
48sub Default {$self->xml_default(@_);}
49
50# This Char function overrides the one in XML::Parser::Stream to overcome a
51# problem where $expat->{Text} is treated as the return value, slowing
52# things down significantly in some cases.
53sub Char {
54 use bytes; # Necessary to prevent encoding issues with XML::Parser 2.31+
55 $_[0]->{'Text'} .= $_[1];
56 return undef;
57}
58
59# Called at the beginning of the XML document.
60sub xml_start_document {
61 my $self = shift(@_);
62 my ($expat) = @_;
63
64}
65
66# Called for XML declarations
67sub xml_xmldecl {
68 my $self = shift(@_);
69 my ($expat, $version, $encoding, $standalone) = @_;
70}
71
72# Called for XML entities
73sub xml_entity {
74 my $self = shift(@_);
75 my ($expat, $name, $val, $sysid, $pubid, $ndata) = @_;
76}
77
78# Called for DOCTYPE declarations - use die to bail out if this doctype
79# is not meant for this plugin
80sub xml_doctype {
81 my $self = shift(@_);
82 my ($expat, $name, $sysid, $pubid, $internal) = @_;
83 die "Manifest Cannot process XML document with DOCTYPE of $name";
84}
85
86# Called for every start tag. The $_ variable will contain a copy of the
87# tag and the %_ variable will contain the element's attributes.
88sub xml_start_tag
89{
90 my $self = shift(@_);
91 my ($expat, $element) = @_;
92
93 if ($element eq "Filename")
94 {
95 $self->{'filename'} = "";
96 }
97 elsif ($element eq "Manifest") {
98 }
99 else
100 {
101 if (defined($self->{'file-type'}))
102 {
103 print STDERR "Warning: Malformed XML manifest ($element nested inside " . $self->{'file-type'} . ")\n";
104 }
105
106 $self->{'file-type'} = $element;
107 }
108}
109
110# Called for every end tag. The $_ variable will contain a copy of the tag.
111sub xml_end_tag
112{
113 my $self = shift(@_);
114 my ($expat, $element) = @_;
115
116 if ($element eq "Filename")
117 {
118 $self->{lc($self->{'file-type'})}->{$self->{'filename'}} = 1;
119 $self->{'filename'} = undef;
120 }
121 else
122 {
123 $self->{'file-type'} = undef;
124 }
125}
126
127# Called just before start or end tags with accumulated non-markup text in
128# the $_ variable.
129sub xml_text {
130 my $self = shift(@_);
131 my ($expat) = @_;
132
133 if (defined $self->{'filename'}) {
134 my $text = $_;
135 chomp($text);
136
137 $text =~ s/^\s+//;
138 $text =~ s/\s+$//;
139
140 $self->{'filename'} .= $text if ($text !~ m/^\s*$/);
141 }
142}
143
144# Called for processing instructions. The $_ variable will contain a copy
145# of the pi.
146sub xml_pi {
147 my $self = shift(@_);
148 my ($expat, $target, $data) = @_;
149}
150
151# Called at the end of the XML document.
152sub xml_end_document {
153 my $self = shift(@_);
154 my ($expat) = @_;
155
156}
157
158# Called for any characters not handled by the above functions.
159sub xml_default {
160 my $self = shift(@_);
161 my ($expat, $text) = @_;
162}
163
164
1651;
Note: See TracBrowser for help on using the repository browser.