#! /cdlcommon/products/perl-5.8.1/bin/perl -w
eval 'exec /cdlcommon/products/perl-5.8.1/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
# Brian Tingle, California Digital Library, UC Regents
# under the terms of perl itself
use strict;
use File::Find ();
use Data::Dumper;
use XML::LibXML;
use Sys::Hostname;
my $host = hostname;
print $host;
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
use Config::Properties;
my %toc;
# reading...
my $properties = new Config::Properties();
open PROPS, "> profiles.props"
or die "unable to open configuration file for writing";
my $dirroot = "/ark/code/dor/htdocs/mets/profiles/";
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, $dirroot);
$properties->format( '%s => %s' );
$properties->store(*PROPS);
close (PROPS);
open (TOC, ">toc.html");
print TOC printToc(%toc);
close (TOC);
exit;
sub printToc {
my (%toc) = @_;
my $out = "\n
";
for (sort keys %toc) {
my $abs = $toc{$_}->[0];
my $file = $toc{$_}->[1];
my $URI = $toc{$_}->[2];
# ->[0]=abs ->[1]=filename ->[2]=URI
my $mainlink;
if ( $URI =~ m,^http://ark.cdlib.org/, ) {
$mainlink = qq{HTML};
} else {
$mainlink = "";
}
my $xml1link = qq{XML1};
my $xml2link = qq{XML2};
$out .= qq{\n- $_ $mainlink $xml1link $xml2link
};
$out .= "\n- $abs
";
}
$out .= "\n
\n";
return $out;
}
sub wanted {
return unless (/^.*\.profile\.xml/s);
setProp($_);
xinclude($_);
}
sub setProp {
my $parser = XML::LibXML->new() ||
carp ("$0: could not make new parser");
my $doc;
if (!($doc = $parser->parse_file($_) ) ) {
print STDERR "$0: LibXML parse_file($_) failed";
return 0;
}
$_ =~ m,([^/]*).profile.xml$,;
print $_;
my $part = $1;
print "\n|$part|\n";
my $root = $doc->getDocumentElement;
my $URI = $root->findvalue("/METS_Profile/URI[1]");
## need to make this generic, so it will pull all
# tools with URIs into file inventory.
my $dcX = $root->findvalue("/METS_Profile/tool/URI[..//\@ID='toQDC']");
my $htmlX = $root->findvalue("/METS_Profile/tool/URI[..//\@ID='toHTML']");
my $label = $root->findvalue("/METS_Profile/title");
my $abs = $root->findvalue("/METS_Profile/abstract");
#print "$abs";
if ($host eq "dali") {
$dcX =~ s,/ark.cdlib.org/,/ark-dev.cdlib.org:8086/,;
$htmlX =~ s,/ark.cdlib.org/,/ark-dev.cdlib.org:8086/,;
}
$properties->setProperty( $URI, "http://ark-dev.cdlib.org:8086/mets/profiles/$_" );
$properties->setProperty( "$URI/toQDC", $dcX );
$properties->setProperty( "$URI/toHTML", $htmlX );
$properties->setProperty( "profile.$URI", $part );
print "$URI http://ark-dev.cdlib.org:8086/mets/profiles/$_\n";
$toc{$label} = [ $abs, $_, $URI, ] ;
}
sub xinclude {
my ($file) = @_;
my $m_file = $file;
$m_file =~ s,\.profile,.mets,;
system("xmllint --xinclude -o /ark/code/dor/htdocs/mets/profiles/full-profiles/$file $file");
my $cmd = "xsltproc --xinclude -o /ark/code/dor/htdocs/mets/profiles/full-profiles/$m_file /ark/code/dor/htdocs/mets/profiles/profile2mets.xslt $file";
#print $cmd;
system($cmd);
}
sub html {
}