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

Last change on this file since 19617 was 18441, checked in by davidb, 15 years ago

Modifications for incremental building to support files that need to be deleted

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