Ignore:
Timestamp:
2010-02-16T19:57:37+13:00 (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.