Changeset 16692 for gsdl/trunk/perllib/plugins/MARCXMLPlugin.pm
- Timestamp:
- 2008-08-11T10:44:04+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/MARCXMLPlugin.pm
r16521 r16692 31 31 32 32 use ReadXMLFile; 33 use marcmapping; 33 34 34 35 use strict; … … 85 86 86 87 87 sub _parse_marc_metadata_mapping88 {89 my $self = shift(@_);90 my ($mm_file,$metadata_mapping) = @_;91 92 my $outhandle = $self->{'outhandle'};93 94 if (open(MMIN, "<$mm_file"))95 {96 my $l=0;97 my $line;98 while (defined($line=<MMIN>))99 {100 $l++;101 chomp $line;102 $line =~ s/#.*$//; # strip out any comments, including end of line103 next if ($line =~ m/^\s*$/);104 $line =~ s/\s+$//; # remove any white space at end of line105 106 my $parse_error_count = 0;107 if ($line =~ m/^-(\d+)\s*$/) {108 # special "remove" rule syntax109 my $marc_info = $1;110 if (defined $metadata_mapping->{$marc_info}) {111 delete $metadata_mapping->{$marc_info};112 }113 else {114 print $outhandle "Parse Warning: Did not file pre-existing rule $marc_info to remove";115 print $outhandle " on line $l of $mm_file:\n";116 print $outhandle " $line\n";117 }118 }119 elsif ($line =~ m/^(.*?)->\s*([\w\^]+)$/)120 {121 my $lhs = $1;122 my $gsdl_info = $2;123 124 my @fields = split(/,\s*/,$lhs);125 my $f;126 while ($f = shift (@fields)) {127 $f =~ s/\s+$//; # remove any white space at end of line128 129 if ($f =~ m/^(\d+)\-(\d+)$/) {130 # number range => genrate number in range and131 # push on to array132 push(@fields,$1..$2);133 next;134 }135 136 if ($f =~ m/^(\d+)((?:(?:\$|\^)\w)*)\s*$/) {137 138 my $marc_info = $1;139 my $opt_sub_fields = $2;140 141 if ($opt_sub_fields ne "") {142 my @sub_fields = split(/\$|\^/,$opt_sub_fields);143 shift @sub_fields; # skip first entry, which is blank144 145 foreach my $sub_field (@sub_fields) {146 $metadata_mapping->{$marc_info."\$".$sub_field} = $gsdl_info;147 }148 }149 else {150 # no subfields to worry about151 $marc_info =~ s/\^/\$/;152 $metadata_mapping->{$marc_info} = $gsdl_info;153 }154 }155 else {156 $parse_error_count++;157 }158 }159 }160 else161 {162 $parse_error_count++;163 }164 165 if ($parse_error_count>0) {166 167 print $outhandle "Parse Error: $parse_error_count syntax error(s) on line $l of $mm_file:\n";168 print $outhandle " $line\n";169 }170 }171 close(MMIN);172 }173 else174 {175 print STDERR "Unable to open $mm_file: $!\n";176 }177 }178 179 180 sub parse_marc_metadata_mapping181 {182 my $self = shift(@_);183 my ($mm_file_or_files) = @_;184 185 my $metadata_mapping = {};186 187 if (ref ($mm_file_or_files) eq 'SCALAR') {188 my $mm_file = $mm_file_or_files;189 $self->_parse_marc_metadata_mapping($mm_file,$metadata_mapping);190 }191 else {192 my $mm_files = $mm_file_or_files;193 194 # Need to process files in reverse order. This is so in the195 # case where we have both a "collect" and "main" version,196 # the "collect" one tops up the main one197 198 my $mm_file;199 while ($mm_file = pop(@$mm_files)) {200 $self->_parse_marc_metadata_mapping($mm_file,$metadata_mapping);201 }202 }203 204 return $metadata_mapping;205 }206 207 208 88 sub init { 209 89 my $self = shift (@_); … … 216 96 } 217 97 218 # read in the metadata mapping file 98 # read in the metadata mapping files 219 99 my $mm_files = &util::locate_config_files($self->{'metadata_mapping_file'}); 220 100 … … 233 113 } 234 114 else { 235 $self->{'metadata_mapping'} = $self->parse_marc_metadata_mapping($mm_files);115 $self->{'metadata_mapping'} = &marcmapping::parse_marc_metadata_mapping($mm_files, $outhandle); 236 116 } 237 117 … … 316 196 } 317 197 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}"); 318 $doc_obj->add_metadata($doc_obj->get_top_section(), "FileFormat", " XML");198 $doc_obj->add_metadata($doc_obj->get_top_section(), "FileFormat", "MARCXML"); 319 199 320 200 my $outhandle = $self->{'outhandle'};
Note:
See TracChangeset
for help on using the changeset viewer.