Changeset 21719


Ignore:
Timestamp:
2010-02-16T19:57:37+13:00 (13 years ago)
Author:
ak19
Message:

For Fedora: the Greenstone server's prefix URL is obtained from gsdlsite.cfg for GS2 and from greenstone3.xml in packages/tomcat for GS3 and this is used by FedoraMETSPlugout so it can refer to the relative paths for associated files like images.

Location:
main/trunk/greenstone2/perllib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/g2futil.pm

    r21687 r21719  
    320320 
    321321    # b. Use the collectParentDir to create the contents of gsdl.xml
     322    my $greenstone_url_prefix = &util::get_greenstone_url_prefix(); # would have the required slash at front
    322323    my $gsdlXMLcontents = "<?xml version='1.0' encoding='utf-8'?>\n<Context docBase=\"";
    323     $gsdlXMLcontents = $gsdlXMLcontents.$collectParentDir."\" path=\"/gsdl\"></Context>";
     324    $gsdlXMLcontents = $gsdlXMLcontents.$collectParentDir."\" path=\"$greenstone_url_prefix\"></Context>";
    324325   
    325326    # 3. If there is already a gsdl.xml file in host_path, compare the string we
  • main/trunk/greenstone2/perllib/plugouts/FedoraMETSPlugout.pm

    r21687 r21719  
    6868   
    6969    my $self = new METSPlugout($plugoutlist,$inputargs,$hashArgOptLists);
    70    
     70
    7171    return bless $self, $class;
    7272}
     
    544544    $gsdl_href =~ s/\\/\//g;                   # make sure we have url paths (which only use / not \)
    545545    my $localfedora = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "packages", "tomcat", "conf", "Catalina", "localhost", "fedora.xml");
    546     if($ENV{'GSDL3SRCHOME'} && -e $localfedora) {                   # prepend gsdl
    547         $gsdl_href = "/greenstone3/sites/localsite/$gsdl_href";     # Fedora uses Greenstone's tomcat
     546   
     547    my $greenstone_url_prefix = &util::get_greenstone_url_prefix();
     548    # prepend url_prefix (which will contain the forward slash upfront)
     549    if($ENV{'GSDL3SRCHOME'} && -e $localfedora) {               # Fedora uses Greenstone's tomcat.
     550        $gsdl_href = "$greenstone_url_prefix/sites/localsite/$gsdl_href";     # Default: /greenstone3/sites/localsite/$gsdl_href
    548551    } else {
    549         $gsdl_href = "/gsdl/$gsdl_href";
     552        $gsdl_href = "$greenstone_url_prefix/$gsdl_href";       # By default: "/greenstone/$gsdl_href";
    550553    }
    551554
     
    680683           $gsdl_href =~ s/\\/\//g;                   # make sure we have url paths (which only use / not \)
    681684           my $localfedora = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "packages", "tomcat", "conf", "Catalina", "localhost", "fedora.xml");
    682            if($ENV{'GSDL3SRCHOME'} && -e $localfedora) {                   # prepend gsdl
    683            $gsdl_href = "/greenstone3/sites/localsite/$gsdl_href";     # Fedora uses Greenstone's tomcat
     685
     686           my $greenstone_url_prefix = &util::get_greenstone_url_prefix();
     687           # prepend url_prefix (which will contain the forward slash upfront)
     688           if($ENV{'GSDL3SRCHOME'} && -e $localfedora) {                 # Fedora uses Greenstone's tomcat.
     689           $gsdl_href = "$greenstone_url_prefix/sites/localsite/$gsdl_href";    # Default: /greenstone3/sites/localsite/$gsdl_href
    684690           } else {
    685            $gsdl_href = "/gsdl/$gsdl_href";
     691           $gsdl_href = "$greenstone_url_prefix/$gsdl_href";         # By default: "/greenstone/$gsdl_href";
    686692           }
    687693
  • main/trunk/greenstone2/perllib/util.pm

    r21664 r21719  
    11421142
    11431143
     1144# Returns the greenstone URL prefix extracted from the appropriate GS2/GS3 config file.
     1145# By default, /greenstone3 for GS3 or /greenstone for GS2.
     1146sub get_greenstone_url_prefix() {
     1147    # if already set on a previous occasion, just return that
     1148    # (Don't want to keep repeating this: cost of re-opening and scanning files.)
     1149    return $ENV{'GREENSTONE_URL_PREFIX'} if($ENV{'GREENSTONE_URL_PREFIX'});
     1150
     1151    my ($configfile, $urlprefix, $defaultUrlprefix);
     1152    my @propertynames = ();
     1153
     1154    if($ENV{'GSDL3SRCHOME'}) {
     1155    $defaultUrlprefix = "/greenstone3";
     1156    $configfile = &util::filename_cat($ENV{'GSDL3SRCHOME'}, "packages", "tomcat", "conf", "Catalina", "localhost", "greenstone3.xml");
     1157    push(@propertynames, qw/path\s*\=/);
     1158    } else {
     1159    $defaultUrlprefix = "/greenstone";
     1160    $configfile = &util::filename_cat($ENV{'GSDLHOME'}, "cgi-bin", "gsdlsite.cfg");
     1161    push(@propertynames, (qw/\nhttpprefix/, qw/\ngwcgi/)); # inspect one property then the other
     1162    }
     1163
     1164    $urlprefix = &extract_propvalue_from_file($configfile, \@propertynames);
     1165
     1166    if(!$urlprefix) { # no values found for URL prefix, use default values
     1167    $urlprefix = $defaultUrlprefix;
     1168    } else {
     1169    #gwcgi can contain more than the wanted prefix, we split on / to get the first "directory" level
     1170    $urlprefix =~ s/^\///; # remove the starting slash
     1171    my @dirs = split(/(\\|\/)/, $urlprefix);
     1172    $urlprefix = shift(@dirs);
     1173
     1174    if($urlprefix !~ m/^\//) { # in all cases: ensure the required forward slash is at the front
     1175        $urlprefix = "/$urlprefix";
     1176    }
     1177    }
     1178
     1179    # set for the future
     1180    $ENV{'GREENSTONE_URL_PREFIX'} = $urlprefix;
     1181#    print STDERR "*** in get_greenstone_url_prefix(): $urlprefix\n\n";
     1182    return $urlprefix;
     1183}
     1184
     1185
     1186# Given a config file (xml or java properties file) and a list/array of regular expressions
     1187# that represent property names to match on, this function will return the value for the 1st
     1188# matching property name. If the return value is undefined, no matching property was found.
     1189sub extract_propvalue_from_file() {
     1190    my ($configfile, $propertynames) = @_;
     1191
     1192    my $value;
     1193    unless(open(FIN, "<$configfile")) {
     1194    print STDERR "extract_propvalue_from_file(): Unable to open $configfile. $!\n";
     1195    return $value; # not initialised
     1196    }
     1197
     1198    # Read the entire file at once, as one single line, then close it
     1199    my $filecontents;
     1200    {
     1201    local $/ = undef;       
     1202    $filecontents = <FIN>;
     1203    }
     1204    close(FIN);
     1205
     1206    foreach my $regex (@$propertynames) {
     1207        ($value) = $filecontents=~ m/$regex\s*(\S*)/s; # read value of the property given by regex up to the 1st space
     1208    if($value) {
     1209            $value =~ s/^\"//;     # remove any startquotes
     1210        $value =~ s/\".*$//;   # remove the 1st endquotes (if any) followed by any xml
     1211        last;              # found value for a matching property, break from loop
     1212    }
     1213    }
     1214
     1215    return $value;
     1216}
     1217
    11441218
    114512191;
Note: See TracChangeset for help on using the changeset viewer.