--- foxridge-archiver/makemeta-lib.pl 2005/08/23 15:01:08 1.5 +++ foxridge-archiver/makemeta-lib.pl 2017/03/16 17:00:43 1.13 @@ -1,24 +1,27 @@ -#!/usr/local/bin/perl -w +#!/usr/bin/perl -w use strict; use XML::LibXML; -use lib '/usr/local/mpiwg/archive_devel'; +use lib '/usr/local/mpiwg/archive'; use MPIWGStor; # make output unbuffered $|=1; # program version -my $version = "0.2.1 (15.8.2005)"; +my $version = "0.2.6 (11.12.2006 ROC)"; my $help = "use: makemeta-lib [options] file.xml options: -debug show debugging info -dry-run simulate, dont'do anything - -cw-mode mode for copying einstein_cq documents + -online-mode mode for creating online/permanent files + -online-base=dir base directory for online ids (for online mode) + -cw-mode mode for copying einstein_cw archive documents -digifiles-mode mode for copying files from digifiles -map-file=mapfile.xml digilib mapping file (for digifiles mode) + -access=free adds free access tag (use access=mpiwg for restricted access) "; logger("INFO", "makemeta-lib $version"); @@ -104,7 +107,8 @@ my %lang_map = ( 'Latin' => 'la', 'Japanese' => 'ja', 'Dutch' => 'nl', - 'Spanish' => 'es' + 'Spanish' => 'es', + 'Swedish' => 'sv' ); # storage fields my $arch_id_field = 'ID_Archive'; @@ -135,6 +139,13 @@ $debug = (exists $$args{'debug'}) ? $$ar my $dry_run = (exists $$args{'dry-run'}) ? $$args{'dry-run'} : 0; logger('DEBUG', "dry-run: $dry_run"); +# use online mode +my $online_mode = (exists $$args{'online-mode'}) ? $$args{'online-mode'} : 0; +logger('DEBUG', "online_mode: $online_mode"); +# online base dir +my $online_base_dir = (exists $$args{'online-base'}) ? $$args{'online-base'} : ""; +logger('DEBUG', "online_base_dir: $online_base_dir"); + # use einstein-cw mode my $cw_mode = (exists $$args{'cw-mode'}) ? $$args{'cw-mode'} : 0; logger('DEBUG', "cw_mode: $cw_mode"); @@ -148,6 +159,9 @@ logger('DEBUG', "map_file_name: $map_fil my $mapping_doc; my $mapping_root; +# access type +my $access_type = (exists $$args{'access'}) ? $$args{'access'} : ""; + # index.meta namespace (not really implemented!) my $namespace = ""; @@ -165,7 +179,7 @@ if (! $infile) { exit 1; } # strip double slashes -$infile =~ s/\/\//\//; +$infile = sstrip($infile, 1); if (! -f $infile) { logger("ABORT", "input file \'$infile\' doesn't exist!"); exit 1; @@ -266,6 +280,26 @@ sub find_cw_dir { return; } +sub find_permanent_dir { + my ($input_node) = @_; + my $online_id = sstrip($input_node->findvalue("fm:$online_id_field")); + # try online_base_dir + online_id first + if (($online_base_dir)&&($online_id)) { + my $dir = sstrip("$online_base_dir/$online_id", 1); + return $dir; + } + # then online_url + my $online_base = '/mpiwg/online/permanent'; + my $online_dir = find_online_dir($input_node, $online_base, 'pageimg'); + if ((! $online_dir)) { + logger('ERROR', "no ID or URL for online permanent entry"); + $errcnt++; + return; + } + my $dir = sstrip("$online_base/$online_dir", 1); + return $dir; +} + # # $dir = find_online_dir($input_node, $base_dir, $page_dir) # @@ -289,12 +323,14 @@ sub find_online_dir { } #logger('DEBUG', "online_dir1: $online_dir"); if ($online_dir) { + $online_dir =~ s/\/$//; # strip ending slashes if ($page_dir) { - $online_dir =~ s/\/${page_dir}$//; + # strip page_dir + $online_dir =~ s/\/${page_dir}$//; } #logger("DEBUG", "dir: $base_dir/$online_dir"); if (-d "$base_dir/$online_dir") { - logger('DEBUG', "directory $base_dir/$online_dir exists"); + logger('DEBUG', "directory $base_dir/$online_dir exists"); return $online_dir; } } @@ -397,10 +433,14 @@ sub process_fm_entry { $index_root->addChild($index_doc->createAttributeNS($namespace, 'version', '1.1')); $index_root->addChild($index_doc->createAttributeNS($namespace, 'type', 'MPIWG')); $index_doc->setDocumentElement($index_root); + my $derived_from = ""; # try to find the document directory my $doc_dir = ""; - if ($cw_mode) { + if ($online_mode) { + $doc_dir = find_permanent_dir($input_node); + $derived_from = find_arch_dir($input_node); + } elsif ($cw_mode) { $doc_dir = find_cw_dir($input_node); } elsif ($digifiles_mode) { $doc_dir = find_digifiles_dir($input_node); @@ -428,6 +468,19 @@ sub process_fm_entry { # media create_text_path('media-type', 'image', $index_root, $namespace); create_text_path('meta/content-type', 'scanned document', $index_root, $namespace); + # derived-from + if ($derived_from) { + create_text_path('derived-from/archive-path', $derived_from, $index_root, $namespace); + } + # access + if ($access_type) { + if ($access_type eq "free") { + create_element_path('meta/access-conditions/access@type=free', $index_root, $namespace); + } else { + my $acc_tag = create_element_path('meta/access-conditions/access@type=institution', $index_root, $namespace); + create_text_path('name', $access_type, $acc_tag, $namespace); + } + } # convert bib entries my $cnt = convert_bib($input_node, $index_root, $index_doc);