######################################################################## # Method: display # Use: Default method, bucket "unveils" itself to requester # Branches to metadata if requested by other than a browser. # Created: 07/17/1997 Del Croom (d.r.croom@larc.nasa.gov) # Seriously Changed: 08/03/1998 MLN # # Assumptions: # - Bucket contents resides under this directory path # ######################################################################## sub display { local($package) = $in{"pkg_name"}; local($element) = $in{"element_name"}; local($redirect) = $in{"redirect"}; &parse_bibfile; if ($redirect) { print "Location: $redirect\n\n"; # http status 302 &log("display","OK","redirect = $redirect"); } elsif (!($element eq "") && !($package eq "") ) { &display_element($package,$element); &log("display","OK","package = $package, element = $element"); } else { &display_default; &log("display","OK","default display"); } } ######################################################################## # Subroutine: parse_bibfile # Called by: display # Use: populates the global assoc. array %BIB_FIELDS to prepare # for pretty HTML printing # Created: 08/03/1998 MLN ######################################################################## sub parse_bibfile { local($more_abstract); foreach $line (@BIBFILE) { chop $line; # get document id 'docid' from the ID tag in bib if ($line =~ /^ID::/) { @docid=split('//',$line); $BIB_FIELDS{"id"}=$docid[1]; } # get title (titles may be present in packages) if ($line =~ /^TITLE::/) { $BIB_FIELDS{"title"}=$line; $BIB_FIELDS{"title"} =~ s/TITLE:: //; $BIB_FIELDS{"title"} =~ s/\n//g; } # get authors (in array, not necessarily in consecutive order) if ($line =~ /^AUTHOR::/) { $line =~ s/AUTHOR:: //g; if ($BIB_FIELDS{"authors"} eq "") { $BIB_FIELDS{"authors"} = $line } else { $BIB_FIELDS{"authors"} .= $author_delimiter . $line; } } # get date (dates may be present in packages) if ($line =~ /^DATE::/) { $BIB_FIELDS{"date"}=$line; $BIB_FIELDS{"date"} =~ s/DATE:: //; } # get copyright (may be present in packages) if ($line =~ /^COPYRIGHT::/) { $BIB_FIELDS{"copyright"}=$line; $BIB_FIELDS{"copyright"} =~ s/COPYRIGHT:: //; } # get abstract (multiple lines with no tags following the first) # check for end of abstract first if ( ($more_abstract) && ($line =~ /^.*::/) ) { $more_abstract=0; } if ( ($line =~ /^ABSTRACT::/) || ($more_abstract) ) { $more_abstract=1; $line =~ s/ABSTRACT:://; if ($line =~/^\n/) { $line = "
"; }
# extra space to keep line1 and line2 from butting
$BIB_FIELDS{"abstract"} .= $line . " ";
}
} #end-foreach
$BIB_FIELDS{"abstract"} =~s/[\r\t\f\b\0]//g; # remove non-printing chars
}
########################################################################
# Subroutine: display_metadata
# Purpose: displays bucket metadata. this routine does not set up
# or close down the html page
# Called by: display_default, display_element
# Created: 08/04/98 MLN
########################################################################
sub display_metadata
{
print <
EOF
# do the right thing with "," and "and" in the author list
@authors = split(/$author_delimiter/,$BIB_FIELDS{"authors"});
while (@authors)
{
$a = shift(@authors);
print "$a";
if ($authors[1]) { print ", ";} # at least 2 more
elsif ($authors[0]) {print " and ";} # just 1 more
}
print <
Abstract
$BIB_FIELDS{"abstract"}
EOF
}
########################################################################
# Subroutine: display_element
# Purpose: "displays" an element
# if the element is a directory, we treat it as a scanned
# set of files (I don't like this assumption right now)
# otherwise, its a file, so we serve up the file ourselves
#
# need to think about how to handle URL elements...
#
# if an element is an html file, it can be a file in a dir
# below a package: 1.pkg/2.element/3.html
# its up to the html file to maintain its links correctly
#
# Called by: display
#
# Called by: display
# Created: 08/04/98 MLN
########################################################################
sub display_element
{
local($package,$element) = @_;
local($name, $first, @extension, $mime_header, $encoding_header);
if (-d "$package/$element") {
&display_scanned_element($package,$element);
} else { # default is that type is file
$name = $element;
@extension = split(/\./,$name);
$first = pop(@extension);
if ($encoding_type{"$first"}) {
$encoding_header = $encoding_type{"$first"};
$first = pop(@extension);
}
if ($mime_type{"$first"}) {
$mime_header= $mime_type{"$first"};
}
if ($encoding_header) {
$header = "$mime_header\nContent-encoding: $encoding_header";
} elsif (!$mime_header) {
$header = "text/plain"; # default mime type
} else {
$header = "$mime_header";
}
&http_header("$header");
open(E, "$package/$element");
while ( Note: no documents have access restrictions, even if the individual page indicates otherwise. ";
print " Contents: \n";
print " \n
$BIB_FIELDS{"title"}
$BIB_FIELDS{"date"}
";
undef($print_now);
}
} # end of for loop
print "\n";
$counter = $counter + 1;
}
print "
";
$base = &MyBaseUrl;
$base =~ s/index.cgi//;
$base =~ s/$restricted//;
print "Top | ";
if ( $end < $total)
{
$next = $end + 1;
print "Next | ";
}
else
{
print "Next | ";
}
if ( $start != 1 )
{
$previous = $start - $thumbnail_increment;
if ( $previous < 1 )
{
$previous = 1;
}
print "Previous | ";
}
else
{
print "Previous | ";
}
if ( $start !=1 )
{
print "First Page | ";
}
else
{
print "First Page | ";
}
if ( $total > $start + $thumbnail_increment - 1 )
{
$last = $total - $thumbnail_increment + 1;
print "Last Page ";
}
else
{
print "Last Page ";
}
print <
-Content is inside bucket
-outside service
-outside link \n";
print "\n";
foreach $line (@BIBFILE)
{
if ($line =~ /\s*PACKAGE::/) {
$line =~ s/\s*PACKAGE:: //;
$pkg_dir = $line;
}
if ($line =~ /\s*PACKAGE-TITLE::/) {
$line =~ s/\s*PACKAGE-TITLE:: //;
$pkg_title = $line;
#print "
\n";
print <\n";
}
if ($line =~ /\s*PACKAGE-END::/) {
print "
\n";
}
if ($line =~ /\s*ELEMENT::/) {
$line =~ s/\s*ELEMENT:: //;
$element = $line;
}
if ($line =~ /\s*ELEMENT-TITLE::/) {
$line =~ s/\s*ELEMENT-TITLE:: //;
$element_title = $line;
}
if ($line =~ /\s*ELEMENT-END::/) {
# compute some stuff that we might need below...
$size = &file_size("$pkg_dir/$element");
$base = &MyBaseUrl;
$base =~ s/index.cgi//;
$base =~ s/$restricted//;
if (&isaurl($element)) {
$element =~ s/$myurlhere/$base/g;
print "