diff --git a/bin/slubsipbuilder.pl b/bin/slubsipbuilder.pl index 8def33525db69652d30a1f0fb8dcab2b53b7bdb5..e2b76c7ad2b290564e390dc05d2109f9cda36540 100755 --- a/bin/slubsipbuilder.pl +++ b/bin/slubsipbuilder.pl @@ -181,11 +181,43 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn) my $ppn = shift; # example: "457035137" for "Der Fichtelberg" #### where to find XSLT # my $marc_dc_url = 'http://www.loc.gov/standards/marcxml/xslt/MARC21slim2RDFDC.xsl'; - my $marc_mods_url = 'http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl'; + my $marc_mods_url = 'http://www.loc.gov/standards/mods/v3/MARC21slim2MODS3-6.xsl'; + my $marc_mods_path = $xsl_dir . basename($marc_mods_url); + my $marc_mods_modified_path = $xsl_dir . basename($marc_mods_url, ".xsl") . ".modified.xsl"; + my $marc_utils_url = 'http://www.loc.gov/standards/marcxml/xslt/MARC21slimUtils.xsl'; + my $marc_utils_path = $xsl_dir . basename($marc_utils_url); my $ua = LWP::UserAgent->new; $ua->agent("MyApp/0.1 "); $ua->timeout(3600); #1h + + # check MARC21 utility xsl + if (! -f $marc_utils_path) { + say "Downloading MARC21 utility xsl '$marc_utils_url'"; + my $result = $ua->get($marc_utils_url); + if ($result->is_error) { + die "Failed to download '$marc_utils_url', " . $result->error_as_HTML; + } + say "Saving MARC21 utility xsl to file '$marc_utils_path'"; + my $xsl = $result->decoded_content; + write_file($marc_utils_path, $xsl); + } + + # check MARC21->MODS xsl + if (! -f $marc_mods_path) { + say "Downloading MARC21->MODS xsl '$marc_mods_url'"; + my $result = $ua->get($marc_mods_url); + if ($result->is_error) { + die "Failed to download '$marc_mods_url', " . $result->error_as_HTML; + } + say "Modifying MARC21->MODS xsl for offline use"; + my $xsl = $result->decoded_content; + write_file($marc_mods_path, $xsl); + my $xsl_modified = $xsl; + $xsl_modified =~ s#$marc_utils_url#$marc_utils_path#g; + say "Saving MARC21->MODS xsl to file '$marc_mods_path'"; + write_file($marc_mods_modified_path, $xsl_modified); + } my $srubase=$url; # host my $srusearchkey="pica.ppn"; my $sruvalue=$ppn;