Changeset 13192
- Timestamp:
- 2006-10-30T14:05:28+13:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/plugins/XMLPlug.pm
r13148 r13192 87 87 } 88 88 89 # the inheriting class must implement this method to tell whether to parse this doc type 90 sub get_doctype { 91 my $self = shift(@_); 92 die "The inheriting class must implement this method"; 93 } 94 95 89 96 sub apply_xslt 90 97 { … … 152 159 } 153 160 161 sub check_doctype { 162 $self = shift (@_); 163 164 my ($filename) = @_; 165 166 if (open(XMLIN,"<$filename")) { 167 my $doctype = $self->get_doctype(); 168 ## check whether the doctype has the same name as the root element tag 169 while (defined (my $line = <XMLIN>)) { 170 ## find the root element 171 if ($line =~ /<(\w+)[\s>]/){ 172 my $root = $1; 173 if ($root !~ $doctype){ 174 close(XMLIN); 175 return 0; 176 } 177 else { 178 close(XMLIN); 179 return 1; 180 } 181 } 182 } 183 close(XMLIN); 184 } 185 186 return undef; # haven't found a valid line 187 188 } 189 190 # because we are not just using process_exp to determine whether to process or not, we need to implement this too, so that a file can be passed down if we are not actually processing it 191 sub metadata_read { 192 $self = shift (@_); 193 194 my ($pluginfo, $base_dir, $file, $metadata, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli) = @_; 195 196 my $result = $self->SUPER::metadata_read($pluginfo, $base_dir, $file, $metadata, $extrametakeys, $extrametadata, $processor, $maxdocs, $gli); 197 198 if (defined $result) { 199 # we think we are processing this, but check that we actually are 200 my $filename = &util::filename_cat ($base_dir, $file) if $base_dir =~ /\w/; 201 202 if ($self->check_doctype($filename)) { 203 return $result; 204 } 205 } 206 return undef; 207 } 154 208 155 209 sub read { … … 162 216 my ($block_status,$filename) = $self->read_block(@_); 163 217 return $block_status if ((!defined $block_status) || ($block_status==0)); 218 219 ## check the doctype to see whether we really want to process the file 220 if (!$self->check_doctype($filename)) { 221 # this file is not for us 222 return undef; 223 } 164 224 165 225 $file =~ s/^[\/\\]+//; # $file often begins with / so we'll tidy it up … … 169 229 $self->{'processor'} = $processor; 170 230 $self->{'metadata'} = $metadata; 171 172 173 ##call the inheriting plugin's get_doctype method to decide whether to carry on the parsing174 if (open(XMLIN,"<$filename")) {175 my $doctype = $self->get_doctype();176 ## check whether the doctype have the same name as the root element tag177 while (defined (my $line = <XMLIN>)) {178 ## find the root element179 if ($line =~ /<(\w+)[\s>]/){180 my $root = $1;181 if ($root !~ $doctype){182 close(XMLIN);183 return undef;184 }185 else{186 close(XMLIN);187 last;188 }189 }190 }191 }192 193 231 194 232 eval { … … 302 340 die "XMLPlug Cannot process XML document with DOCTYPE of $name"; 303 341 } 304 305 # the inheriting class must implement this method to tell whether to parse this doc type306 sub get_doctype {307 my $self = shift(@_);308 die "The inheriting class must implement this method";309 }310 311 342 312 343
Note:
See TracChangeset
for help on using the changeset viewer.