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