[6107] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # ISISPlugin.pm -- A plugin for CDS/ISIS databases
|
---|
[6107] | 4 | #
|
---|
| 5 | # A component of the Greenstone digital library software
|
---|
| 6 | # from the New Zealand Digital Library Project at the
|
---|
| 7 | # University of Waikato, New Zealand.
|
---|
| 8 | #
|
---|
[7686] | 9 | # Copyright 1999-2004 New Zealand Digital Library Project
|
---|
[6107] | 10 | #
|
---|
| 11 | # This program is free software; you can redistribute it and/or modify
|
---|
| 12 | # it under the terms of the GNU General Public License as published by
|
---|
| 13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | # (at your option) any later version.
|
---|
| 15 | #
|
---|
| 16 | # This program is distributed in the hope that it will be useful,
|
---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | # GNU General Public License for more details.
|
---|
| 20 | #
|
---|
| 21 | # You should have received a copy of the GNU General Public License
|
---|
| 22 | # along with this program; if not, write to the Free Software
|
---|
| 23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | #
|
---|
| 25 | ###########################################################################
|
---|
| 26 |
|
---|
[15872] | 27 | package ISISPlugin;
|
---|
[6107] | 28 |
|
---|
| 29 |
|
---|
| 30 | use multiread;
|
---|
[15872] | 31 | use SplitTextFile;
|
---|
[6107] | 32 |
|
---|
[10254] | 33 | use strict;
|
---|
| 34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[6107] | 35 |
|
---|
[15872] | 36 | # ISISPlugin is a sub-class of SplitTextFile.
|
---|
[6107] | 37 | sub BEGIN {
|
---|
[15872] | 38 | @ISISPlugin::ISA = ('SplitTextFile');
|
---|
[6107] | 39 | }
|
---|
| 40 |
|
---|
| 41 |
|
---|
| 42 | my $arguments =
|
---|
[7686] | 43 | [ { 'name' => "process_exp",
|
---|
[15872] | 44 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 45 | 'type' => "regexp",
|
---|
| 46 | 'reqd' => "no",
|
---|
[6107] | 47 | 'deft' => &get_default_process_exp() },
|
---|
| 48 | { 'name' => "block_exp",
|
---|
[15872] | 49 | 'desc' => "{BasePlugin.block_exp}",
|
---|
[6408] | 50 | 'type' => "regexp",
|
---|
[7686] | 51 | 'reqd' => "no",
|
---|
[11329] | 52 | 'deft' => &get_default_block_exp(),
|
---|
| 53 | 'hiddengli' => "yes" },
|
---|
[7686] | 54 | { 'name' => "split_exp",
|
---|
[15872] | 55 | 'desc' => "{SplitTextFile.split_exp}",
|
---|
[7686] | 56 | 'type' => "regexp",
|
---|
| 57 | 'reqd' => "no",
|
---|
[11295] | 58 | 'deft' => &get_default_split_exp(),
|
---|
| 59 | 'hiddengli' => "yes" },
|
---|
[7686] | 60 |
|
---|
| 61 | # The interesting options
|
---|
| 62 | { 'name' => "entry_separator",
|
---|
[15872] | 63 | 'desc' => "{ISISPlugin.entry_separator}",
|
---|
[7686] | 64 | 'type' => "string",
|
---|
| 65 | 'reqd' => "no",
|
---|
| 66 | 'deft' => "<br>" },
|
---|
[6107] | 67 | { 'name' => "subfield_separator",
|
---|
[15872] | 68 | 'desc' => "{ISISPlugin.subfield_separator}",
|
---|
[6107] | 69 | 'type' => "string",
|
---|
| 70 | 'reqd' => "no",
|
---|
[8563] | 71 | 'deft' => ", " }
|
---|
[6408] | 72 | ];
|
---|
[6107] | 73 |
|
---|
[15872] | 74 | my $options = { 'name' => "ISISPlugin",
|
---|
| 75 | 'desc' => "{ISISPlugin.desc}",
|
---|
[6408] | 76 | 'abstract' => "no",
|
---|
| 77 | 'inherits' => "yes",
|
---|
[8762] | 78 | 'explodes' => "yes",
|
---|
[6107] | 79 | 'args' => $arguments };
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 | # This plugin processes files with the suffix ".mst"
|
---|
| 83 | sub get_default_process_exp {
|
---|
| 84 | return q^(?i)(\.mst)$^;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | # This plugin blocks files with the suffix ".fdt" and ".xrf"
|
---|
| 89 | sub get_default_block_exp {
|
---|
[17479] | 90 | return q^(?i)(\.fdt|\.xrf)$^;
|
---|
| 91 | #return "";
|
---|
[6107] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | # This plugin splits the input text at the "----------" lines
|
---|
| 96 | sub get_default_split_exp {
|
---|
[9998] | 97 | return q^\r?\n----------\r?\n^;
|
---|
[6107] | 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[8563] | 101 | sub new
|
---|
| 102 | {
|
---|
[10218] | 103 | my ($class) = shift (@_);
|
---|
| 104 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 105 | push(@$pluginlist, $class);
|
---|
[6107] | 106 |
|
---|
[15872] | 107 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 108 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[6107] | 109 |
|
---|
[15872] | 110 | my $self = new SplitTextFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[6107] | 111 |
|
---|
[13178] | 112 | if ($self->{'info_only'}) {
|
---|
| 113 | # don't worry about any options etc
|
---|
| 114 | return bless $self, $class;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[12833] | 117 | # isis plug doesn't care about encoding - it assumes ascii unless the user
|
---|
| 118 | # has specified an encoding
|
---|
| 119 | if ($self->{'input_encoding'} eq "auto") {
|
---|
| 120 | $self->{'input_encoding'} = "ascii";
|
---|
| 121 | }
|
---|
[6107] | 122 | return bless $self, $class;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[16392] | 125 | # we block the corresponding fdt and xrf
|
---|
[17479] | 126 | # a pain on windows. blocks xxx.FDT, but if actual file is xx.fdt then
|
---|
| 127 | # complains that no plugin can process it. Have put it back to using
|
---|
| 128 | # block exp for now
|
---|
| 129 | sub store_block_files_tmp {
|
---|
[16392] | 130 |
|
---|
| 131 | my $self =shift (@_);
|
---|
| 132 | my ($filename_full_path, $block_hash) = @_;
|
---|
[17479] | 133 | print STDERR "in store block files\n";
|
---|
[16392] | 134 | $self->check_auxiliary_files($filename_full_path);
|
---|
| 135 | if (-e $self->{'fdt_file_path'}) {
|
---|
[17479] | 136 | print STDERR "$self->{'fdt_file_path'}\n";
|
---|
[16392] | 137 | my $fdt_file = $self->{'fdt_file_path'};
|
---|
[23561] | 138 | &util::block_filename($block_hash,$fdt_file);
|
---|
[16392] | 139 | }
|
---|
| 140 | if (-e $self->{'xrf_file_path'}) {
|
---|
[17479] | 141 | print STDERR "$self->{'xrf_file_path'}\n";
|
---|
[16392] | 142 | my $xrf_file = $self->{'xrf_file_path'};
|
---|
[23561] | 143 | &util::block_filename($block_hash,$xrf_file);
|
---|
[16392] | 144 | }
|
---|
| 145 |
|
---|
[6107] | 146 |
|
---|
[16392] | 147 | }
|
---|
| 148 |
|
---|
| 149 | sub check_auxiliary_files {
|
---|
| 150 | my $self = shift (@_);
|
---|
| 151 | my ($filename) = @_;
|
---|
| 152 |
|
---|
| 153 | my ($database_file_path_root) = ($filename =~ /(.*)\.mst$/i);
|
---|
| 154 | # Check the associated .fdt and .xrf files exist
|
---|
| 155 | $self->{'fdt_file_path'} = $database_file_path_root . ".FDT";
|
---|
| 156 | if (!-e $self->{'fdt_file_path'}) {
|
---|
| 157 | $self->{'fdt_file_path'} = $database_file_path_root . ".fdt";
|
---|
| 158 | }
|
---|
| 159 | $self->{'xrf_file_path'} = $database_file_path_root . ".XRF";
|
---|
| 160 | if (!-e $self->{'xrf_file_path'}) {
|
---|
| 161 | $self->{'xrf_file_path'} = $database_file_path_root . ".xrf";
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
[8563] | 166 | sub read_file
|
---|
[7686] | 167 | {
|
---|
[6107] | 168 | my $self = shift (@_);
|
---|
| 169 | my ($filename, $encoding, $language, $textref) = @_;
|
---|
[11334] | 170 | my $outhandle = $self->{'outhandle'};
|
---|
[6107] | 171 |
|
---|
[11334] | 172 | my ($database_file_path_root) = ($filename =~ /(.*)\.mst$/i);
|
---|
| 173 | my $mst_file_path_relative = $filename;
|
---|
| 174 | $mst_file_path_relative =~ s/^.+import.(.*?)$/$1/;
|
---|
[6107] | 175 |
|
---|
[7048] | 176 | # Check the associated .fdt and .xrf files exist
|
---|
[16392] | 177 | $self->check_auxiliary_files($filename);
|
---|
| 178 |
|
---|
[11334] | 179 | if (!-e $self->{'fdt_file_path'}) {
|
---|
| 180 | print STDERR "<ProcessingError n='$mst_file_path_relative' r='Could not find ISIS FDT file $self->{'fdt_file_path'}'>\n" if ($self->{'gli'});
|
---|
| 181 | print $outhandle "Error: Could not find ISIS FDT file " . $self->{'fdt_file_path'} . ".\n";
|
---|
| 182 | return;
|
---|
[7048] | 183 | }
|
---|
[11334] | 184 | if (!-e $self->{'xrf_file_path'}) {
|
---|
| 185 | print STDERR "<ProcessingError n='$mst_file_path_relative' r='Could not find ISIS XRF file $self->{'xrf_file_path'}'>\n" if ($self->{'gli'});
|
---|
| 186 | print $outhandle "Error: Could not find ISIS XRF file " . $self->{'xrf_file_path'} . ".\n";
|
---|
| 187 | return;
|
---|
[7048] | 188 | }
|
---|
| 189 |
|
---|
[6107] | 190 | # The text to split is exported from the database by the IsisGdl program
|
---|
[7021] | 191 | open(FILE, "IsisGdl \"$filename\" |");
|
---|
[6107] | 192 |
|
---|
| 193 | my $reader = new multiread();
|
---|
[15872] | 194 | $reader->set_handle('ISISPlugin::FILE');
|
---|
[8563] | 195 | $reader->set_encoding($encoding);
|
---|
| 196 | $reader->read_file($textref);
|
---|
[6107] | 197 |
|
---|
| 198 | close(FILE);
|
---|
| 199 |
|
---|
| 200 | # Parse the associated ISIS database Field Definition Table file (.fdt)
|
---|
[11334] | 201 | my %fdt_mapping = &parse_field_definition_table($self->{'fdt_file_path'}, $encoding);
|
---|
[11332] | 202 | $self->{'fdt_mapping'} = \%fdt_mapping;
|
---|
[6107] | 203 |
|
---|
[11545] | 204 | # Remove the line at the start, and any blank lines, so the data is split and processed properly
|
---|
[7686] | 205 | $$textref =~ s/^----------\n//;
|
---|
[11545] | 206 | $$textref =~ s/\n\n/\n/g;
|
---|
[6107] | 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | sub process
|
---|
| 211 | {
|
---|
| 212 | my $self = shift (@_);
|
---|
[6332] | 213 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[6107] | 214 | my $outhandle = $self->{'outhandle'};
|
---|
| 215 |
|
---|
[20778] | 216 | # store the auxiliary files so we know which ones were used
|
---|
| 217 | # (mst file becomes the source file)
|
---|
| 218 | $doc_obj->associate_source_file($self->{'fdt_file_path'});
|
---|
| 219 | $doc_obj->associate_source_file($self->{'xrf_file_path'});
|
---|
| 220 |
|
---|
[11298] | 221 | my $section = $doc_obj->get_top_section();
|
---|
| 222 | my $fdt_mapping = $self->{'fdt_mapping'};
|
---|
[6107] | 223 | my $subfield_separator = $self->{'subfield_separator'};
|
---|
| 224 | my $entry_separator = $self->{'entry_separator'};
|
---|
[11466] | 225 | my $isis_record_html_metadata_value = "<table cellpadding=\"4\" cellspacing=\"0\">";
|
---|
[6107] | 226 |
|
---|
| 227 | # Process each line of the ISIS record, one at a time
|
---|
[10254] | 228 | foreach my $line (split(/\n/, $$textref)) {
|
---|
[11430] | 229 | $line =~ s/(\s*)$//; # Remove any nasty whitespace (very important for Windows)
|
---|
[8646] | 230 | $line =~ /^tag=(.*) data=(.+)$/;
|
---|
[11298] | 231 | my $tag = $1;
|
---|
| 232 | my $tag_data = $2;
|
---|
| 233 | # print STDERR "\nTag: $tag, Data: $tag_data\n";
|
---|
[6107] | 234 |
|
---|
[11298] | 235 | # Convert the tag number into a name, and remove any invalid characters
|
---|
| 236 | my $raw_metadata_name = $fdt_mapping->{$tag}{'name'} || "";
|
---|
[11300] | 237 | $raw_metadata_name =~ s/[,&\#\.\-\/]/ /g;
|
---|
[11298] | 238 | next if ($raw_metadata_name eq "");
|
---|
| 239 |
|
---|
[6107] | 240 | # Metadata field names: title case, then remove spaces
|
---|
[11298] | 241 | my $metadata_name = "";
|
---|
| 242 | foreach my $word (split(/\s+/, $raw_metadata_name)) {
|
---|
[6107] | 243 | substr($word, 0, 1) =~ tr/a-z/A-Z/;
|
---|
[11298] | 244 | $metadata_name .= $word;
|
---|
[6107] | 245 | }
|
---|
| 246 |
|
---|
[11298] | 247 | my $all_metadata_name = $metadata_name . "^all";
|
---|
| 248 | my $all_metadata_value = "";
|
---|
[6123] | 249 |
|
---|
[11298] | 250 | # Handle repeatable fields
|
---|
| 251 | if ($fdt_mapping->{$tag}{'repeatable'}) {
|
---|
| 252 | # Multiple values are separated using the '%' character
|
---|
| 253 | foreach my $raw_metadata_value (split(/%/, $tag_data)) {
|
---|
| 254 | my $metadata_value = "";
|
---|
[6107] | 255 |
|
---|
[11298] | 256 | # Handle subfields
|
---|
| 257 | while ($raw_metadata_value ne "") {
|
---|
| 258 | # If there is a subfield specifier, parse it off
|
---|
| 259 | my $sub_metadata_name = $metadata_name;
|
---|
[11299] | 260 | if ($raw_metadata_value =~ s/^\^// && $raw_metadata_value =~ s/^([a-z])//) {
|
---|
[11298] | 261 | $sub_metadata_name .= "^$1";
|
---|
| 262 | }
|
---|
| 263 |
|
---|
| 264 | # Parse the value off and add it as metadata
|
---|
| 265 | $raw_metadata_value =~ s/^([^\^]*)//;
|
---|
[12705] | 266 | my $sub_metadata_value = &escape_metadata_value($1);
|
---|
[11298] | 267 |
|
---|
| 268 | # print STDERR "Sub metadata name: $sub_metadata_name, value: $sub_metadata_value\n";
|
---|
| 269 | if ($sub_metadata_name ne $metadata_name) {
|
---|
| 270 | $doc_obj->add_utf8_metadata($section, $sub_metadata_name, $sub_metadata_value);
|
---|
| 271 | }
|
---|
| 272 |
|
---|
[13157] | 273 | # If this tag has subfields and this is the first, use the value for the CDS/ISIS ^* field
|
---|
| 274 | if ($fdt_mapping->{$tag}{'subfields'} ne "" && $metadata_value eq "") {
|
---|
[12703] | 275 | $doc_obj->add_utf8_metadata($section, $metadata_name . "^*", $sub_metadata_value);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
[11298] | 278 | $metadata_value .= $subfield_separator unless ($metadata_value eq "");
|
---|
| 279 | $metadata_value .= $sub_metadata_value;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | # Add the metadata value
|
---|
| 283 | # print STDERR "Metadata name: $metadata_name, value: $metadata_value\n";
|
---|
| 284 | $doc_obj->add_utf8_metadata($section, $metadata_name, $metadata_value);
|
---|
| 285 |
|
---|
| 286 | $all_metadata_value .= $entry_separator unless ($all_metadata_value eq "");
|
---|
| 287 | $all_metadata_value .= $metadata_value;
|
---|
| 288 | }
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | # Handle non-repeatable fields
|
---|
| 292 | else {
|
---|
| 293 | my $raw_metadata_value = $tag_data;
|
---|
| 294 | my $metadata_value = "";
|
---|
| 295 |
|
---|
| 296 | # Handle subfields
|
---|
| 297 | while ($raw_metadata_value ne "") {
|
---|
[6107] | 298 | # If there is a subfield specifier, parse it off
|
---|
[11298] | 299 | my $sub_metadata_name = $metadata_name;
|
---|
[11353] | 300 | if ($raw_metadata_value =~ s/^\^// && $raw_metadata_value =~ s/^([a-z])//) {
|
---|
[11379] | 301 | $sub_metadata_name .= "^$1";
|
---|
[6107] | 302 | }
|
---|
| 303 |
|
---|
[11298] | 304 | # Parse the value off and add it as metadata
|
---|
| 305 | $raw_metadata_value =~ s/^([^\^]*)//;
|
---|
| 306 | my $sub_metadata_value = $1;
|
---|
| 307 |
|
---|
| 308 | # Deal with the case when multiple values are specified using <...>
|
---|
[11545] | 309 | if ($sub_metadata_value =~ /\<(.+)\>/) {
|
---|
[11298] | 310 | my $sub_sub_metadata_name = $sub_metadata_name . "^sub";
|
---|
| 311 | my $tmp_sub_metadata_value = $sub_metadata_value;
|
---|
[11545] | 312 | while ($tmp_sub_metadata_value =~ s/\<(.+?)\>//) {
|
---|
[11298] | 313 | my $sub_sub_metadata_value = $1;
|
---|
| 314 | $doc_obj->add_utf8_metadata($section, $sub_sub_metadata_name, $sub_sub_metadata_value);
|
---|
[6107] | 315 | }
|
---|
| 316 | }
|
---|
[11546] | 317 | # Deal with the legacy case when multiple values are specified using /.../
|
---|
[11545] | 318 | elsif ($sub_metadata_value =~ /\/(.+)\//) {
|
---|
| 319 | my $sub_sub_metadata_name = $sub_metadata_name . "^sub";
|
---|
| 320 | my $tmp_sub_metadata_value = $sub_metadata_value;
|
---|
| 321 | while ($tmp_sub_metadata_value =~ s/\/(.+?)\///) {
|
---|
| 322 | my $sub_sub_metadata_value = $1;
|
---|
| 323 | $doc_obj->add_utf8_metadata($section, $sub_sub_metadata_name, $sub_sub_metadata_value);
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
[6107] | 326 |
|
---|
[12705] | 327 | # Escape the metadata value so it appears correctly in the final collection
|
---|
| 328 | $sub_metadata_value = &escape_metadata_value($sub_metadata_value);
|
---|
[9998] | 329 |
|
---|
[11298] | 330 | # print STDERR "Sub metadata name: $sub_metadata_name, value: $sub_metadata_value\n";
|
---|
| 331 | if ($sub_metadata_name ne $metadata_name) {
|
---|
| 332 | $doc_obj->add_utf8_metadata($section, $sub_metadata_name, $sub_metadata_value);
|
---|
[6107] | 333 | }
|
---|
| 334 |
|
---|
[13157] | 335 | # If this tag has subfields and this is the first, use the value for the CDS/ISIS ^* field
|
---|
| 336 | if ($fdt_mapping->{$tag}{'subfields'} ne "" && $metadata_value eq "") {
|
---|
[12703] | 337 | $doc_obj->add_utf8_metadata($section, $metadata_name . "^*", $sub_metadata_value);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[11298] | 340 | $metadata_value .= $subfield_separator unless ($metadata_value eq "");
|
---|
| 341 | $metadata_value .= $sub_metadata_value;
|
---|
[6107] | 342 | }
|
---|
| 343 |
|
---|
[11298] | 344 | # Add the metadata value
|
---|
| 345 | # print STDERR "Metadata name: $metadata_name, value: $metadata_value\n";
|
---|
| 346 | $doc_obj->add_utf8_metadata($section, $metadata_name, $metadata_value);
|
---|
| 347 |
|
---|
| 348 | $all_metadata_value .= $entry_separator unless ($all_metadata_value eq "");
|
---|
| 349 | $all_metadata_value .= $metadata_value;
|
---|
[6107] | 350 | }
|
---|
| 351 |
|
---|
[11298] | 352 | # Add the "^all" metadata value
|
---|
| 353 | # print STDERR "All metadata name: $all_metadata_name, value: $all_metadata_value\n";
|
---|
| 354 | $doc_obj->add_utf8_metadata($section, $all_metadata_name, $all_metadata_value);
|
---|
[11465] | 355 |
|
---|
| 356 | $isis_record_html_metadata_value .= "<tr><td valign=top><nobr><b>" . $fdt_mapping->{$tag}{'name'} . "</b></nobr></td><td valign=top>" . $all_metadata_value . "</td></tr>";
|
---|
[6107] | 357 | }
|
---|
[8563] | 358 |
|
---|
[11467] | 359 | # Add a reasonably formatted HTML table view of the record as the document text
|
---|
[11465] | 360 | $isis_record_html_metadata_value .= "</table>";
|
---|
[11467] | 361 | $doc_obj->add_utf8_text($section, $isis_record_html_metadata_value);
|
---|
[11465] | 362 |
|
---|
[11467] | 363 | # Add the full raw record as metadata
|
---|
[12705] | 364 | my $isis_raw_record_metadata_value = &escape_metadata_value($$textref);
|
---|
| 365 | $doc_obj->add_utf8_metadata($section, "ISISRawRecord", $isis_raw_record_metadata_value);
|
---|
[6107] | 366 |
|
---|
[8563] | 367 | # Add FileFormat metadata
|
---|
[11298] | 368 | $doc_obj->add_utf8_metadata($section, "FileFormat", "CDS/ISIS");
|
---|
[7686] | 369 |
|
---|
[11298] | 370 | # Record was processed successfully
|
---|
[6107] | 371 | return 1;
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 |
|
---|
| 375 | sub parse_field_definition_table
|
---|
| 376 | {
|
---|
[7686] | 377 | my $fdtfilename = shift(@_);
|
---|
[11262] | 378 | my $encoding = shift(@_);
|
---|
[6107] | 379 |
|
---|
[7686] | 380 | my %fdtmapping = ();
|
---|
[6107] | 381 |
|
---|
| 382 | open(FDT_FILE, "<$fdtfilename") || die "Error: Could not open file $fdtfilename.\n";
|
---|
| 383 |
|
---|
[11262] | 384 | my $fdtfiletext = "";
|
---|
| 385 | my $reader = new multiread();
|
---|
[15872] | 386 | $reader->set_handle('ISISPlugin::FDT_FILE');
|
---|
[11262] | 387 | $reader->set_encoding($encoding);
|
---|
| 388 | $reader->read_file($fdtfiletext);
|
---|
| 389 |
|
---|
[7686] | 390 | my $amongstdefinitions = 0;
|
---|
[11262] | 391 | foreach my $fdtfileline (split(/\n/, $$fdtfiletext)) {
|
---|
[6107] | 392 | $fdtfileline =~ s/(\s*)$//; # Remove any nasty spaces at the end of the lines
|
---|
| 393 |
|
---|
| 394 | if ($amongstdefinitions) {
|
---|
[13298] | 395 | my $fieldname = &unicode::substr($fdtfileline, 0, 30);
|
---|
| 396 | my $fieldsubfields = &unicode::substr($fdtfileline, 30, 20);
|
---|
| 397 | my $fieldspecs = &unicode::substr($fdtfileline, 50, 50);
|
---|
[6107] | 398 |
|
---|
| 399 | # Remove extra spaces
|
---|
[11298] | 400 | $fieldname =~ s/(\s*)$//;
|
---|
[6107] | 401 | $fieldsubfields =~ s/(\s*)$//;
|
---|
[11298] | 402 | $fieldspecs =~ s/(\s*)$//;
|
---|
[6107] | 403 |
|
---|
[11298] | 404 | # Map from tag number to metadata field title, subfields, and repeatability
|
---|
| 405 | my $fieldtag = (split(/ /, $fieldspecs))[0];
|
---|
| 406 | my $fieldrepeatable = (split(/ /, $fieldspecs))[3];
|
---|
| 407 | $fdtmapping{$fieldtag} = { 'name' => $fieldname,
|
---|
| 408 | 'subfields' => $fieldsubfields,
|
---|
| 409 | 'repeatable' => $fieldrepeatable };
|
---|
[6107] | 410 | }
|
---|
| 411 | elsif ($fdtfileline eq "***") {
|
---|
| 412 | $amongstdefinitions = 1;
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | close(FDT_FILE);
|
---|
| 417 |
|
---|
| 418 | return %fdtmapping;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 |
|
---|
[12705] | 422 | sub escape_metadata_value
|
---|
| 423 | {
|
---|
| 424 | my $value = shift(@_);
|
---|
| 425 | $value =~ s/\</</g;
|
---|
| 426 | $value =~ s/\>/>/g;
|
---|
| 427 | $value =~ s/\\/\\\\/g;
|
---|
| 428 | return $value;
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 |
|
---|
[11332] | 432 | sub clean_up_after_exploding
|
---|
| 433 | {
|
---|
| 434 | my $self = shift(@_);
|
---|
| 435 |
|
---|
| 436 | # Delete the FDT and XRF files too
|
---|
[11334] | 437 | &util::rm($self->{'fdt_file_path'});
|
---|
| 438 | &util::rm($self->{'xrf_file_path'});
|
---|
[11332] | 439 | }
|
---|
| 440 |
|
---|
| 441 |
|
---|
[6107] | 442 | 1;
|
---|