######################################################################## # 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 <

$BIB_FIELDS{"title"}

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 < $BIB_FIELDS{"id"}
$BIB_FIELDS{"date"}

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 () { print $_; } close (E); } } ######################################################################## # Subroutine: display_scanned_element # Purpose: displays a package as a group of objects. taken from the # NACA DL # Called by: display # Created: 08/04/98 MLN ######################################################################## sub display_scanned_element { local($package, $element) = @_; # if we're here, look for these values too... local($page) = $in{"page"}; local($thumbnail) = $in{"thumbnail"}; if ($page) { &display_scanned_page($package,$element,$page); } elsif ($thumbnail) { &display_scanned_thumbnails($package,$element,$thumbnail); } else { # start at page 1 if no page is provided... &display_scanned_thumbnails($package,$element,"1"); } # go back up so &log will work chdir($real_current_dir); } ######################################################################## # Subroutine: display_scanned_page # Purpose: displays a scanned image # Called by: display_scanned_element # # Note: this is taken from the NACA DL... # Created: 08/04/98 MLN ######################################################################## sub display_scanned_page { local($package, $element, $page) = @_; local($title) = $BIB_FIELDS{"title"}; &http_header("text/html"); chdir ("$package/$element"); opendir (D, "."); # # *[0-9].gif eliminates the thumbnails (*-t.gif) # @allgifs = sort(grep(/.*[0-9]\.gif/,readdir(D))); $firstpage = $allgifs[0]; # first in list $lastpage = $allgifs[$#allgifs]; # last in list foreach $p (@allgifs) { if (defined($last)) { $next = $p; last; } if ($p ne $page) { $previous = $p; next; } else { $last = 1; next; } } print " $title "; print "

"; $print_now = 1; foreach $i (0 .. 1) { $top = &MyBaseUrl; $top =~ s/index.cgi//; $top =~ s/$restricted//; print "Top | "; if ($page eq $lastpage) { print "Next | "; } else { print "Next | "; } if ($page eq $firstpage) { print "Previous | "; } else { print "Previous | "; } print "First | "; print "Last "; if (defined($print_now)) { $url = &MyBaseUrl; $url =~ s/index.cgi//g; $url =~ s/$restricted//g; print "

"; undef($print_now); } } # end of for loop print "

Note: no documents have access restrictions, even if the individual page indicates otherwise.


"; print "

"; closedir(D); } ######################################################################## # Subroutine: display_scanned_thumbnails # Purpose: displays the scanned thumbnails # Called by: display_scanned_element # # Note: this is taken from the NACA DL... # Created: 08/04/98 MLN ######################################################################## sub display_scanned_thumbnails { local($package, $element,$start) = @_; chdir ("$package/$element"); &http_header("text/html"); opendir(D,"."); print < $BIB_FIELDS{"title"} EOF &display_metadata; # a bunch of other stuff has to go here... $end = $start + $thumbnail_increment - 1; @allthumbnails = sort(grep(/.*-t\.gif/,readdir(D))); $total = $#allthumbnails + 1; # add 1 b/c array index starts at 0 print "\n"; $counter = 1; foreach $t (@allthumbnails) { if ($counter < $start) { $counter = $counter + 1; next; } if ( ($counter > $end) || ($counter > $total) ) { last; } $big = $t; $big =~ s/-t.gif/.gif/g; $url = &MyBaseUrl; $url =~ s/index.cgi//g; $url =~ s/$restricted//g; print "\"$t\"\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 < EOF } ######################################################################## # Subroutine: display_default # Purpose: displays bucket contents when nothing else was asked for # Called by: display # Created: 08/03/98 MLN ######################################################################## sub display_default { local($line, $pkg_dir, $pkg_title); local($element, $element_title); &http_header("text/html"); print < $BIB_FIELDS{"title"} EOF &display_metadata; print "

Contents:

\n"; 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 "
  • $pkg_title\n"; # uncomment the above if we will allow "displaying" # a package... - mln print "

    \n

  • $pkg_title\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 "
  • $element_title"; } elsif ($element =~ /\.html?/) { # add redirect print "
  • $element_title $size\n"; } else { print "
  • $element_title $size\n"; } } } print "
\n"; print < EOF } ######################################################################## # Subroutine: isaurl # Purpose: returns true if the argument appears to be an absolute # URL, false if otherwise # Called by: display # Created: 08/03/98 MLN ######################################################################## sub isaurl { local($check) = @_; @urls = ("http://", "ftp://", "gopher://", "mailto://", "wais://", "https://"); foreach $u (@urls) { if ($check =~ /$u/) { return(1) }; } return (0); } 1;