#!/usr/bin/perl -w # # mob 2010-03-24 # The usual free license verbiage here. Make it better and send it back. # # This code is cleaner than the others I have of this style, since some vars are # passed into the stages. # # # perl program to mimic the display from metacat. I have discovered that this is a # really clunky operation. It re-reads the EML doc for every "display module". # I guess it needs to, since it is generating a new web page each time. (You # could get on with that project to pull the entire EML only once,and hide # sections with tabs. # # ## NOTE on versions of XML-LibXML and XSLT which are available on Penguin: # XML-LibXML # Currently penguin is running http://search.cpan.org/~pajas/XML-LibXML-1.69/ # which uses this syntax for parsing: # my $source = $parser->parse_file( "${xml_dataset_query_url}${docid}" ); # But the current version as of march 2010 is 1.7 which has a different syntax: # my $source = XML::LibXML->load_xml(location => 'test.xml'); # my $style_doc = XML::LibXML->load_xml(location=>'test_person.xsl', no_cdata=>1); # XML-LibXSLT: # per http://search.cpan.org/~msergeant/XML-LibXSLT-1.58/LibXSLT.pm # print $stylesheet->output_string($results); # The 1.7 version is # print $stylesheet->output_as_bytes($results); #--------------------------------------------------------------------------80c-> # load perl modules use strict; # turn on strict syntax checking. use CGI; use XML::LibXSLT; use XML::LibXML; use URI; # for parsing URL syntax. not curently used use LWP::Simple; # for grabbing url. not currently used, but might need its "get" method for URIs use File::Basename; # app must know its own name so stylesheets can create new URLs back #--------------------------------------------------------------------------80c-> # Set up pgm configuration - use template vars here. my $xslt_root_path = '/var/www/sbc-dev.lternet.edu/lib/xslt'; # The XML is pulled from the internal fileserver. # There is a site.url version of this,but I cannot make GCI read from https, my $xml_dataset_query_url = '/data01/sbclter/internal/research/Metadata/EML_data_packages'; # create a name for yourself! my $referrer = 'showDraftDataset.cgi'; #--------------------------------------------------------------------------80c-> # instantiate common objects and variables # create an object for the input params my $query = new CGI; my $docid = $query->param('docid'); # these for reading XML and transforming my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); # set path for EML xslt stylesheets: my $xslt_path = "${xslt_root_path}/eml"; my $source=""; ## parse 2 XML files: the eml dataset and the xslt eval { $source = $parser->parse_file( "${xml_dataset_query_url}/${docid}" ) || die $source = $parser->parse_file("unavailable") ; }; if ($@) { # print '';print $@;print''; # $source = "$@"; } # the xsl has logic to change the look slightly when the referrer is this script my $style_doc = $parser->parse_file("${xslt_path}/eml-2.0.0.xsl"); my $stylesheet = $xslt->parse_stylesheet($style_doc); #--------------------------------------------------------------------------80c-> # Define the main program logic that calls subroutines to do the work #--------------------------------------------------------------------------80c-> # The processing steps we are handling. A dataset summary view is the default. # "displaymodule" is analogous to "stage" in other cgis, but consistent with # existing wording in eml-*.xsl my $displaymodule = $query->param('displaymodule') || 'dataset'; # define the possible stages my %displaymodules = ( 'dataset' => \&dataset, 'entity' => \&entity, 'attribute' => \&attribute, 'attributedomain' => \&attributeDomain, 'attributecoverage' => \&attributeCoverage, 'attributedetail' => \&attributeDetail, # not sure of use 'attributemethod' => \&attributeMethod, # not yet tested 'inlinedata' => \&inlineData, # not yet tested 'additionalmetadata'=> \&additionalMetadata, 'responsibleparties'=> \&responsibleParties, 'coverage' => \&coverage, # local coveral 'coverageall' => \&coverageall, 'methodsall' => \&methodsall, ); # call the appropriate routine based on the stage. # all stages use the vars for docid, source_xml and xsl_stylesheet # 2010-05-04: referrer, too! if ( $displaymodules{$displaymodule} ) { $displaymodules{ $displaymodule }->("$docid", "$source", "$stylesheet", "$referrer"); } else { &handleResponseMessage(); } #--------------------------------------------------------------------------80c-> # Define the subroutines to do the work #--------------------------------------------------------------------------80c-> ##### ### Default stage, show a dataset # sub dataset { # no other query params needed # create HTML output from EML and stylesheet and send it back my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", referrer => "$referrer", withOriginalXMLLink => '0', )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### stage to show all the people as a separate webpage # sub responsibleParties { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); # create HTML output from EML and stylesheet and send it back my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### stage to show all the coverage elements as a separate webpage # sub coverage { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); # create HTML output from EML and stylesheet and send it back my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### stage to show all the coverage elements as a separate webpage # sub coverageall { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); # create HTML output from EML and stylesheet and send it back my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### stage to show all the coverage elements as a separate webpage # sub methodsall { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); # create HTML output from EML and stylesheet and send it back my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub entity { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub attribute { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } # note that attributeDomain","attributeCoverage" "attributeMethod", all use the same params, # only the displaymodule changes [HAVE NOT YET TESTED attributeMethod ] ##### ### # sub attributeDomain { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $attributeindex = $query->param('attributeindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", attributeindex => "$attributeindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub attributeCoverage { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $attributeindex = $query->param('attributeindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", attributeindex => "$attributeindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub attributeMethod { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $attributeindex = $query->param('attributeindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", attributeindex => "$attributeindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub inlineData { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $entitytype = $query->param('entitytype'); my $entityindex = $query->param('entityindex'); my $distributionlevel = $query->param('distributionlevel'); my $physicalindex = $query->param('physicalindex'); my $distributionindex = $query->param('distributionindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", entitytype => "$entitytype", entityindex => "$entityindex", distributionlevel => "$distributionlevel", physicalindex => "$physicalindex", distributionindex => "$distributionindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### # sub additionalMetadata { # get the other params from CGI my $displaymodule = $query->param('displaymodule'); my $additionalmetadataindex = $query->param('additionalmetadataindex'); my $results = $stylesheet->transform($source, XML::LibXSLT::xpath_to_string( docid => "$docid", displaymodule => "$displaymodule", additionalmetadataindex => "$additionalmetadataindex", referrer => "$referrer", )); print "Content-type: text/html\n\n"; print $stylesheet->output_string($results); } ##### ### HandleResponseMssage # sub handleResponseMessage { # user picked a stage that does not exist yet. send an error msg. # user picked an EML docid that does not exist # (handled by returning the metacat error xslt) # metacat is not returning data }