[13486] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # MARCXMLPlugin.pm
|
---|
[13486] | 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 2001 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
| 26 | # Processes MARCXML documents. Note that this plugin does no
|
---|
| 27 | # syntax checking (though the XML::Parser module tests for
|
---|
| 28 | # well-formedness).
|
---|
| 29 |
|
---|
[15872] | 30 | package MARCXMLPlugin;
|
---|
[13486] | 31 |
|
---|
[15872] | 32 | use ReadXMLFile;
|
---|
[16693] | 33 | use ReadTextFile;
|
---|
[16692] | 34 | use marcmapping;
|
---|
[13486] | 35 |
|
---|
| 36 | use strict;
|
---|
| 37 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 38 |
|
---|
| 39 | sub BEGIN {
|
---|
[16693] | 40 | @MARCXMLPlugin::ISA = ('ReadXMLFile', 'ReadTextFile');
|
---|
[13486] | 41 | }
|
---|
| 42 |
|
---|
| 43 | my $arguments = [{'name' => "metadata_mapping_file",
|
---|
[15872] | 44 | 'desc' => "{MARCXMLPlugin.metadata_mapping_file}",
|
---|
[13486] | 45 | 'type' => "string",
|
---|
[18563] | 46 | 'deft' => "marc2dc.txt",
|
---|
[13486] | 47 | 'reqd' => "no" }];
|
---|
| 48 |
|
---|
[15872] | 49 | my $options = { 'name' => "MARCXMLPlugin",
|
---|
| 50 | 'desc' => "{MARCXMLPlugin.desc}",
|
---|
[13486] | 51 | 'abstract' => "no",
|
---|
| 52 | 'inherits' => "yes",
|
---|
| 53 | 'args' => $arguments
|
---|
| 54 | };
|
---|
| 55 |
|
---|
| 56 | sub new {
|
---|
| 57 | my ($class) = shift (@_);
|
---|
| 58 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 59 | push(@$pluginlist, $class);
|
---|
| 60 |
|
---|
[15872] | 61 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 62 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[13486] | 63 |
|
---|
[16693] | 64 | # we want to be able to use the textcat methods from ReadTextFile
|
---|
| 65 | # to get the language and encoding
|
---|
| 66 | new ReadTextFile($pluginlist, $inputargs, $hashArgOptLists, 1);
|
---|
| 67 |
|
---|
[15872] | 68 | my $self = new ReadXMLFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[18900] | 69 |
|
---|
| 70 | # we want to strip namespaces, so have to create a new XML parser
|
---|
| 71 | my $parser = new XML::Parser('Style' => 'Stream',
|
---|
| 72 | 'Pkg' => 'ReadXMLFile',
|
---|
| 73 | 'PluginObj' => $self,
|
---|
| 74 | 'Namespaces' => 1, # strip out namespaces
|
---|
| 75 | 'Handlers' => {'Char' => \&ReadXMLFile::Char,
|
---|
| 76 | 'XMLDecl' => \&ReadXMLFile::XMLDecl,
|
---|
| 77 | 'Entity' => \&ReadXMLFile::Entity,
|
---|
| 78 | 'Doctype' => \&ReadXMLFile::Doctype,
|
---|
| 79 | 'Default' => \&ReadXMLFile::Default
|
---|
| 80 | });
|
---|
| 81 |
|
---|
| 82 | $self->{'parser'} = $parser;
|
---|
| 83 |
|
---|
[13486] | 84 | $self->{'content'} = "";
|
---|
[15018] | 85 | $self->{'xmlcontent'} = "";
|
---|
[13486] | 86 | $self->{'record_count'} = 1;
|
---|
| 87 | $self->{'language'} = "";
|
---|
| 88 | $self->{'encoding'} = "";
|
---|
| 89 | $self->{'marc_mapping'} = {};
|
---|
| 90 | $self->{'current_code'} = "";
|
---|
| 91 | $self->{'current_tag'} = "";
|
---|
| 92 | $self->{'current_element'} = "";
|
---|
| 93 | $self->{'metadata_mapping'} = undef;
|
---|
| 94 | $self->{'num_processed'} = 0;
|
---|
[13496] | 95 | $self->{'indent'} = 0;
|
---|
| 96 |
|
---|
[13486] | 97 | return bless $self, $class;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[16694] | 100 |
|
---|
| 101 |
|
---|
[13486] | 102 | sub get_doctype {
|
---|
| 103 | my $self = shift(@_);
|
---|
| 104 |
|
---|
| 105 | return "collection";
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | sub init {
|
---|
| 110 | my $self = shift (@_);
|
---|
| 111 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
| 112 |
|
---|
| 113 | ## the mapping file has already been loaded
|
---|
| 114 | if (defined $self->{'metadata_mapping'} ){
|
---|
| 115 | $self->SUPER::init(@_);
|
---|
| 116 | return;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
[16692] | 119 | # read in the metadata mapping files
|
---|
[15018] | 120 | my $mm_files = &util::locate_config_files($self->{'metadata_mapping_file'});
|
---|
[13486] | 121 |
|
---|
| 122 |
|
---|
[15018] | 123 | if (scalar(@$mm_files)==0)
|
---|
[13486] | 124 | {
|
---|
[15872] | 125 | my $msg = "MARCXMLPlugin ERROR: Can't locate mapping file \"" .
|
---|
[15018] | 126 | $self->{'metadata_mapping_file'} . "\".\n " .
|
---|
[16697] | 127 | " No metadata will be extracted from MARCXML files.\n";
|
---|
[13486] | 128 |
|
---|
| 129 | print $outhandle $msg;
|
---|
| 130 | print $failhandle $msg;
|
---|
| 131 | $self->{'metadata_mapping'} = undef;
|
---|
| 132 | # We pick up the error in process() if there is no $mm_file
|
---|
| 133 | # If we exit here, then pluginfo.pl will exit too!
|
---|
| 134 | }
|
---|
[15018] | 135 | else {
|
---|
[16692] | 136 | $self->{'metadata_mapping'} = &marcmapping::parse_marc_metadata_mapping($mm_files, $outhandle);
|
---|
[13486] | 137 | }
|
---|
| 138 |
|
---|
| 139 |
|
---|
[16695] | 140 | ##map { print STDERR $_."=>".$self->{'metadata_mapping'}->{$_}."\n"; } keys %{$self->{'metadata_mapping'}};
|
---|
[13486] | 141 |
|
---|
| 142 | $self->SUPER::init(@_);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | # Called for DOCTYPE declarations - use die to bail out if this doctype
|
---|
| 146 | # is not meant for this plugin
|
---|
| 147 | sub xml_doctype {
|
---|
| 148 | my $self = shift(@_);
|
---|
| 149 |
|
---|
| 150 | my ($expat, $name, $sysid, $pubid, $internal) = @_;
|
---|
| 151 | return;
|
---|
| 152 |
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | sub xml_start_document {
|
---|
| 157 | my $self = shift(@_);
|
---|
| 158 |
|
---|
| 159 | my ($expat, $name, $sysid, $pubid, $internal) = @_;
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | my $file = $self->{'file'};
|
---|
| 163 | my $filename = $self->{'filename'};
|
---|
[13496] | 164 |
|
---|
[13486] | 165 | my ($language, $encoding) = $self->textcat_get_language_encoding ($filename);
|
---|
| 166 |
|
---|
| 167 | $self->{'language'} = $language;
|
---|
| 168 | $self->{'encoding'} = $encoding;
|
---|
| 169 | $self->{'element_count'} = 1;
|
---|
[13496] | 170 | $self->{'indent'} = 0;
|
---|
[13486] | 171 | my $outhandle = $self->{'outhandle'};
|
---|
[15872] | 172 | print $outhandle "MARCXMLPlugin: processing $self->{'file'}\n" if $self->{'verbosity'} > 1;
|
---|
| 173 | print STDERR "<Processing n='$self->{'file'}' p='MARCXMLPlugin'>\n" if $self->{'gli'};
|
---|
[17026] | 174 |
|
---|
| 175 | # reset the base id
|
---|
| 176 | $self->{'base_oid'} = undef;
|
---|
[13486] | 177 |
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 | sub xml_end_document {
|
---|
| 181 |
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | sub xml_start_tag {
|
---|
| 185 | my $self = shift;
|
---|
| 186 | my $expat = shift;
|
---|
| 187 | my $element = shift;
|
---|
[13496] | 188 |
|
---|
[15018] | 189 | my $text = $_;
|
---|
| 190 | my $escaped_text = $self->escape_text($_);
|
---|
[13486] | 191 |
|
---|
| 192 | $self->{'current_element'} = $element;
|
---|
| 193 |
|
---|
| 194 | ##get all atributes of this element and store it in a map name=>value
|
---|
| 195 | my %attr_map = ();
|
---|
| 196 | my $attrstring = $_;
|
---|
| 197 | while ($attrstring =~ /(\w+)=\"(\w+)\"/){
|
---|
| 198 | $attr_map{$1}=$2;
|
---|
[13496] | 199 | $attrstring = $'; #'
|
---|
[13486] | 200 | }
|
---|
| 201 |
|
---|
[15018] | 202 |
|
---|
[13486] | 203 | my $processor = $self->{'processor'};
|
---|
| 204 |
|
---|
| 205 | ##create a new document for each record
|
---|
| 206 | if ($element eq "record") {
|
---|
[13496] | 207 | my $filename = $self->{'filename'};
|
---|
[13486] | 208 | my $language = $self->{'language'};
|
---|
| 209 | my $encoding = $self->{'encoding'};
|
---|
| 210 | my $file = $self->{'file'};
|
---|
[18327] | 211 | my $doc_obj = new doc($filename, undef, $self->{'file_rename_method'});
|
---|
[13486] | 212 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Language", $language);
|
---|
| 213 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Encoding", $encoding);
|
---|
| 214 | my ($filemeta) = $file =~ /([^\\\/]+)$/;
|
---|
[15872] | 215 | $self->set_Source_metadata($doc_obj, $filemeta, $encoding);
|
---|
[13486] | 216 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "SourceSegment", "$self->{'record_count'}");
|
---|
| 217 | if ($self->{'cover_image'}) {
|
---|
| 218 | $self->associate_cover_image($doc_obj, $filename);
|
---|
| 219 | }
|
---|
| 220 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
|
---|
[16692] | 221 | $doc_obj->add_metadata($doc_obj->get_top_section(), "FileFormat", "MARCXML");
|
---|
[13486] | 222 |
|
---|
| 223 | my $outhandle = $self->{'outhandle'};
|
---|
[16697] | 224 | print $outhandle "Record $self->{'record_count'}\n" if $self->{'verbosity'} > 1;
|
---|
[13486] | 225 |
|
---|
| 226 | $self->{'record_count'}++;
|
---|
| 227 | $self->{'doc_obj'} = $doc_obj;
|
---|
| 228 | $self->{'num_processed'}++;
|
---|
[17026] | 229 | if (!defined $self->{'base_oid'}) {
|
---|
| 230 | $self->SUPER::add_OID($doc_obj);
|
---|
| 231 | $self->{'base_oid'} = $doc_obj->get_OID();
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[13486] | 234 |
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | ## get the marc code, for example 520
|
---|
| 238 | if ($element eq "datafield") {
|
---|
[13496] | 239 | if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
|
---|
[13486] | 240 | $self->{'current_tag'} = $attr_map{tag};
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 | ## append the subcode to the marc code for example 520a or 520b
|
---|
| 246 | if ($element eq "subfield"){
|
---|
[13496] | 247 | if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
|
---|
[13486] | 248 | $self->{'current_code'} = $attr_map{'code'};
|
---|
| 249 | }
|
---|
| 250 | }
|
---|
[13496] | 251 |
|
---|
| 252 | if ($element eq "record"){
|
---|
| 253 | $self->{'indent'} = 0;
|
---|
[15018] | 254 | $self->{'content'} = "";
|
---|
| 255 | $self->{'xmlcontent'} = "";
|
---|
[13496] | 256 | }
|
---|
| 257 | else {
|
---|
| 258 | if ($element ne "subfield"){
|
---|
| 259 | $self->{'indent'} = 1;
|
---|
| 260 | }
|
---|
| 261 | else{
|
---|
| 262 | $self->{'indent'} = 2;
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
[15018] | 266 |
|
---|
| 267 | if ($element eq "collection") {
|
---|
| 268 | # remember the full start tag for <collection ...>
|
---|
| 269 | # This is needed to wrap around each <record> when generating its associate MARCXML file
|
---|
| 270 |
|
---|
| 271 | $self->{'xmlcollectiontag'} = $text;
|
---|
| 272 | }
|
---|
| 273 | else {
|
---|
| 274 | $self->{'content'} .= "<br/>" if ($element ne "record");
|
---|
| 275 | $self->{'content'} .= $self->calculate_indent($self->{'indent'}).$escaped_text;
|
---|
| 276 | $self->{'xmlcontent'} .= $text;
|
---|
| 277 | }
|
---|
[13496] | 278 |
|
---|
[13486] | 279 | }
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | sub xml_end_tag {
|
---|
| 284 | my $self = shift(@_);
|
---|
| 285 | my ($expat, $element) = @_;
|
---|
[15018] | 286 |
|
---|
| 287 | my $text = $_;
|
---|
| 288 | my $escaped_text = $self->escape_text($_);
|
---|
[13496] | 289 |
|
---|
[13486] | 290 | if ($element eq "record" and defined $self->{'doc_obj'}) {
|
---|
| 291 | # process the document
|
---|
| 292 | my $processor = $self->{'processor'};
|
---|
| 293 | my $doc_obj = $self->{'doc_obj'};
|
---|
[15018] | 294 | $self->{'content'} .= "<br/>".$escaped_text;
|
---|
| 295 | $self->{'xmlcontent'} .= $text;
|
---|
[13496] | 296 |
|
---|
[15018] | 297 |
|
---|
| 298 | my $top_section = $doc_obj->get_top_section();
|
---|
| 299 |
|
---|
[16521] | 300 | my $tmp_marcxml_filename = &util::get_tmp_filename("xml");
|
---|
[15018] | 301 | if (open (XMLOUT,">$tmp_marcxml_filename")) {
|
---|
| 302 |
|
---|
| 303 | print XMLOUT "<?xml-stylesheet type=\"text/xsl\" href=\"MARC21slim2English.xsl\"?>\n";
|
---|
| 304 | my $xml_content = $self->{'xmlcontent'};
|
---|
| 305 |
|
---|
| 306 | $xml_content = $self->{'xmlcollectiontag'}.$xml_content."</collection>";
|
---|
| 307 |
|
---|
| 308 | print XMLOUT $xml_content;
|
---|
| 309 |
|
---|
| 310 | close(XMLOUT);
|
---|
| 311 |
|
---|
| 312 | $doc_obj->associate_file($tmp_marcxml_filename,"marcxml.xml","text/xml", $top_section);
|
---|
| 313 |
|
---|
| 314 | # assicate xsl style file for presentation as HTML
|
---|
| 315 | my $xsl_filename = &util::filename_cat($ENV{'GSDLHOME'},"etc","MARC21slim2English.xsl");
|
---|
| 316 | $doc_obj->associate_file($xsl_filename,"MARC21slim2English.xsl","text/xml", $top_section);
|
---|
| 317 |
|
---|
| 318 | }
|
---|
| 319 | else {
|
---|
| 320 | my $outhandle = $self->{'outhandle'};
|
---|
| 321 | print $outhandle "Warning: Unable for write out associated MARCXML file $tmp_marcxml_filename\n";
|
---|
| 322 | }
|
---|
[15178] | 323 |
|
---|
| 324 | # include any metadata passed in from previous plugins
|
---|
| 325 | # note that this metadata is associated with the top level section
|
---|
| 326 |
|
---|
| 327 | $self->extra_metadata ($doc_obj,
|
---|
| 328 | $doc_obj->get_top_section(),
|
---|
| 329 | $self->{'metadata'});
|
---|
| 330 |
|
---|
[15018] | 331 |
|
---|
[17026] | 332 | $self->add_OID($doc_obj, $self->{'base_oid'}, $self->{'record_count'});
|
---|
[15018] | 333 |
|
---|
[13496] | 334 | $doc_obj->add_utf8_text($doc_obj->get_top_section(),$self->{'content'});
|
---|
[13486] | 335 | $processor->process($doc_obj);
|
---|
| 336 |
|
---|
| 337 | ##clean up
|
---|
| 338 | $self->{'content'} = "";
|
---|
[15018] | 339 | $self->{'xmlcontent'} = "";
|
---|
[13486] | 340 | $self->{'doc_obj'} = undef;
|
---|
[13496] | 341 | return;
|
---|
[13486] | 342 | }
|
---|
| 343 |
|
---|
| 344 | ## map the xmlmarc to gsdl metadata
|
---|
[16697] | 345 | if ($element eq "datafield" and defined $self->{'doc_obj'} and defined $self->{'marc_mapping'} and defined $self->{'metadata_mapping'}){
|
---|
[13486] | 346 | my $metadata_mapping = $self->{'metadata_mapping'};
|
---|
| 347 | my $marc_mapping = $self->{'marc_mapping'};
|
---|
| 348 | my $doc_obj = $self->{'doc_obj'};
|
---|
| 349 |
|
---|
[15018] | 350 | ## print STDERR "**** Marc Record\n";
|
---|
| 351 | ## map { print STDERR $_."=>".$marc_mapping->{$_}."\n"; } keys %$marc_mapping;
|
---|
| 352 | ## print STDERR "**** Metadata Mapping\n";
|
---|
| 353 | ## map { print STDERR $_."=>".$metadata_mapping->{$_}."\n"; } keys %$metadata_mapping;
|
---|
[13486] | 354 |
|
---|
[15018] | 355 |
|
---|
[13486] | 356 | foreach my $marc_field (keys %$metadata_mapping){
|
---|
[15018] | 357 |
|
---|
| 358 | ## test whether this field has subfield
|
---|
[13486] | 359 | my $subfield = undef;
|
---|
[15018] | 360 | if ($marc_field =~ /(\d\d\d)(?:\$|\^)?(\w)/){
|
---|
| 361 | $marc_field = $1;
|
---|
| 362 | $subfield = $2;
|
---|
| 363 | }
|
---|
[13486] | 364 |
|
---|
[15018] | 365 | my $matched_field = $marc_mapping->{$marc_field};
|
---|
| 366 |
|
---|
| 367 | if (defined $matched_field) {
|
---|
| 368 |
|
---|
| 369 | my $meta_name = undef;
|
---|
| 370 | my $meta_value = undef;
|
---|
| 371 |
|
---|
[13486] | 372 | if (defined $subfield){
|
---|
[15018] | 373 | $meta_name = $metadata_mapping->{$marc_field."\$".$subfield};
|
---|
| 374 |
|
---|
| 375 | $meta_value = $matched_field->{$subfield};
|
---|
| 376 |
|
---|
| 377 | if (!defined $meta_value) {
|
---|
| 378 | # record read in does not have the specified subfield
|
---|
| 379 | next;
|
---|
| 380 | }
|
---|
[13486] | 381 | }
|
---|
[15018] | 382 | else {
|
---|
| 383 | $meta_name = $metadata_mapping->{$marc_field};
|
---|
| 384 |
|
---|
| 385 | # no subfield => get all the values
|
---|
| 386 | foreach my $value (sort keys %{$matched_field}) {
|
---|
| 387 | $meta_value .= $matched_field->{$value} ." ";
|
---|
[13486] | 388 | }
|
---|
[15018] | 389 |
|
---|
[13486] | 390 | }
|
---|
| 391 |
|
---|
| 392 | ## escape [ and ]
|
---|
| 393 | $meta_value =~ s/\[/\\\[/g;
|
---|
| 394 | $meta_value =~ s/\]/\\\]/g;
|
---|
| 395 | ##print STDERR "$meta_name=$meta_value\n";
|
---|
| 396 | $doc_obj->add_utf8_metadata($doc_obj->get_top_section(),$meta_name, $meta_value);
|
---|
| 397 |
|
---|
| 398 | }
|
---|
| 399 |
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | ##clean up
|
---|
| 403 | $self->{'marc_mapping'} = undef;
|
---|
| 404 | $self->{'current_tag'} = "";
|
---|
| 405 | }
|
---|
[13496] | 406 |
|
---|
| 407 | if ($element eq "datafield"){
|
---|
| 408 | $self->{'indent'} = 1;
|
---|
[15018] | 409 | $self->{'content'} .= "<br/>".$self->calculate_indent($self->{'indent'}).$escaped_text;
|
---|
| 410 | $self->{'xmlcontent'} .= $text;
|
---|
[13496] | 411 | }
|
---|
| 412 | else{
|
---|
[15018] | 413 | $self->{'content'} .= $escaped_text;
|
---|
| 414 | $self->{'xmlcontent'} .= $text;
|
---|
[13496] | 415 | }
|
---|
| 416 |
|
---|
[13486] | 417 | }
|
---|
| 418 |
|
---|
[17026] | 419 | sub add_OID {
|
---|
[13486] | 420 | my $self = shift (@_);
|
---|
[17026] | 421 | my ($doc_obj, $id, $record_number) = @_;
|
---|
[15018] | 422 |
|
---|
[17026] | 423 | my $full_id = $id . "r" . $record_number;
|
---|
| 424 | if ($self->{'OIDtype'} eq "assigned") {
|
---|
| 425 | my $identifier = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), $self->{'OIDmetadata'});
|
---|
| 426 | if (defined $identifier && $identifier ne "") {
|
---|
[17033] | 427 | $full_id = $identifier;
|
---|
| 428 | $full_id =~ s/\.//g; #remove any periods
|
---|
| 429 | if ($full_id =~ /^[\d]*$/) {
|
---|
| 430 | $full_id = "D" . $full_id;
|
---|
[17026] | 431 | print STDERR "OID only contains numbers, adding a D\n";
|
---|
| 432 | }
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | $doc_obj->set_OID($full_id);
|
---|
[13486] | 436 | }
|
---|
| 437 |
|
---|
| 438 | sub xml_text {
|
---|
| 439 | my $self = shift(@_);
|
---|
| 440 | my ($expat) = @_;
|
---|
| 441 |
|
---|
[15018] | 442 | my $text = $_;
|
---|
| 443 | my $escaped_text = $self->escape_text($_);
|
---|
[13486] | 444 |
|
---|
[15018] | 445 | # protect against & in raw text file
|
---|
| 446 | $text =~ s/&/&/g; # can't have & in raw form, even in 'raw' xml text
|
---|
| 447 |
|
---|
[13486] | 448 | ## store the text of a marc code, for exapmle 520a=>A poem about....
|
---|
| 449 | if ($self->{'current_element'} eq "subfield" and $self->{'current_code'} ne "" and $_ ne "" ){
|
---|
| 450 | ##stored it in the marc_mapping
|
---|
[15018] | 451 |
|
---|
| 452 | my $current_tag = $self->{'current_tag'};
|
---|
| 453 | my $current_code = $self->{'current_code'};
|
---|
| 454 |
|
---|
| 455 | $self->{'marc_mapping'}->{$current_tag}->{$current_code} .= $_;
|
---|
| 456 |
|
---|
[13486] | 457 | $self->{'current_code'} = "";
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[15018] | 460 | $self->{'content'} .= $escaped_text;
|
---|
| 461 | $self->{'xmlcontent'} .= $text;
|
---|
[13486] | 462 |
|
---|
| 463 | }
|
---|
| 464 |
|
---|
[13496] | 465 | sub calculate_indent{
|
---|
| 466 | my ($self,$num) = @_;
|
---|
[13486] | 467 |
|
---|
[13496] | 468 | my $indent ="";
|
---|
| 469 |
|
---|
| 470 | for (my $i=0; $i<$num;$i++){
|
---|
| 471 | $indent .= " ";
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | return $indent;
|
---|
| 475 |
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | sub escape_text {
|
---|
| 479 | my ($self,$text) = @_;
|
---|
| 480 | # special characters in the xml encoding
|
---|
| 481 | $text =~ s/&/&/g; # this has to be first...
|
---|
| 482 | $text =~ s/</</g;
|
---|
| 483 | $text =~ s/>/>/g;
|
---|
| 484 | $text =~ s/\"/"/g;
|
---|
| 485 |
|
---|
| 486 | return $text;
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 |
|
---|
[15018] | 490 | sub unescape_text {
|
---|
| 491 | my ($self,$text) = @_;
|
---|
| 492 | # special characters in the xml encoding
|
---|
| 493 | $text =~ s/</</g;
|
---|
| 494 | $text =~ s/>/>/g;
|
---|
| 495 | $text =~ s/"/\"/g;
|
---|
| 496 |
|
---|
| 497 | $text =~ s/&/&/g; # can't have & in raw form, even in unescaped xml!
|
---|
| 498 |
|
---|
| 499 | return $text;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 |
|
---|
[13486] | 503 | 1;
|
---|
| 504 |
|
---|
| 505 |
|
---|