]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/scripts/init.d/loadPredefinedStylesheets.pl
ocaml 3.09 transition
[helm.git] / helm / scripts / init.d / loadPredefinedStylesheets.pl
index 387a6fc2c6dcbfcc5acde0fd854b3fdbae9e188d..700cf68f5d3ff854c4de116dbb07e8adab24aade 100755 (executable)
@@ -1,12 +1,22 @@
 #!/usr/bin/perl -w
 use strict;
 
-my $confile = $ENV{"UWOBO_PANEL_CONF"} || die "UWOBO_PANEL_CONF not defined";
-
 use LWP::UserAgent;
 use URI::Escape;
 
-sub getPredefinedStylesheets () {
+my $usage = <<EOHELP;
+loadPredefinedStylesheets.pl [ uwobo_panel_conf_file ]
+loadPredefinedStylesheets.pl { -u | --unload } [ uwobo_panel_conf_file ]
+loadPredefinedStylesheets.pl { -r | --reload } [ uwobo_panel_conf_file ]
+loadPredefinedStylesheets.pl { -h | --help   } [ uwobo_panel_conf_file ]
+
+If uwobo_panel_conf_file is provided, it's used as HTML file from which
+parse XSLT stylesheets, otherwise UWOBO_PANEL_CONF environment variable
+is used.
+EOHELP
+
+sub getPredefinedStylesheets ($) {
+  my $confile = shift;
   my %stylesconf;
   my $inForm = 0; # currenlty inside 'predefinedStylesheets' form
   open(CONF, "< $confile") || die "Can't open $confile";
@@ -39,11 +49,24 @@ sub getPredefinedStylesheets () {
   return %stylesconf;
 }
 
-sub main () {
-  my $getter_url = $ENV{"HELM_GETTER_URL"} || die "HELM_GETTER_URL not defined";
-  my $uwobo_url = $ENV{"HELM_UWOBO_URL"} || die "HELM_UWOBO_URL not defined";
-  my %styles = getPredefinedStylesheets();
-  my $request_url = "";
+my $action = "load";
+my $opt = shift || "";
+die $usage if (($opt eq "-h") or ($opt eq "--help"));
+if (($opt eq "-u") or ($opt eq "--unload")) {
+  $action = "unload";
+} elsif (($opt eq "-r") or ($opt eq "--reload")) {
+  $action = "reload";
+} else {
+  unshift (@ARGV, $opt);
+}
+my $confile =
+  shift || $ENV{"UWOBO_PANEL_CONF"} || die "UWOBO_PANEL_CONF not defined";
+my $getter_url = $ENV{"HELM_GETTER_URL"} || die "HELM_GETTER_URL not defined";
+my $uwobo_url = $ENV{"HELM_UWOBO_URL"} || die "HELM_UWOBO_URL not defined";
+my %styles = getPredefinedStylesheets($confile);
+my $request_url = "";
+
+if ($action eq "load") {  # load predefined stylesheets
   foreach my $k (keys %styles) {
     $request_url .= "&" unless ($request_url eq "");
     my $ur = $styles{$k}[0];
@@ -51,17 +74,25 @@ sub main () {
     $request_url .= "bind=$k,";
     my $tmp = "";
     if ($use_getter) {
-      $tmp .= $getter_url . "getxslt?uri="
+      $tmp .= $getter_url . "/getxslt?uri="
     }
     $tmp .= $ur;
     $request_url .= uri_escape($tmp);
   }
-  $request_url = $uwobo_url . "add?$request_url";
-  my $agent = LWP::UserAgent->new();
-  my $response = $agent->get($request_url);
-  print $response->as_string();
-#   print "$request_url\n";
+  $request_url = $uwobo_url . "/add?$request_url";
+
+} elsif ($action eq "unload") { # unload predefined stylesheets
+  $request_url = $uwobo_url . "/remove?keys=" . join(',', keys %styles);
+
+} elsif ($action eq "reload") { # reload predefined stylesheets
+  $request_url = $uwobo_url . "/reload?keys=" . join(',', keys %styles);
+
+} else {  # unknown action
+  die "Unknown action '$action'";
 }
 
-main();
+my $agent = LWP::UserAgent->new();
+my $response = $agent->get($request_url);
+print $response->as_string();
+#   print "$request_url\n";