mod_perl handler for idl2js transform w/ configs
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Nov 2010 15:37:04 +0000 (15:37 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 11 Nov 2010 15:37:04 +0000 (15:37 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@18700 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/apache/eg_vhost.conf
Open-ILS/examples/apache/startup.pl
Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm [new file with mode: 0644]

index 4a2266f..5b81f7a 100644 (file)
@@ -576,3 +576,27 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT]
     CustomLog /var/log/apache2/deflate_log deflate
 </IfModule>
 
+
+<Location /IDL2js>
+
+    SetHandler perl-script
+    PerlHandler OpenILS::WWW::IDL2js
+    Options +ExecCGI
+    PerlSendHeader On
+    allow from all
+
+    <IfModule mod_headers.c>
+        Header append Cache-Control "public"
+    </IFModule>
+
+    <IfModule mod_deflate.c>
+        SetOutputFilter DEFLATE
+        BrowserMatch ^Mozilla/4 gzip-only-text/html
+        BrowserMatch ^Mozilla/4\.0[678] no-gzip
+        BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
+        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
+        <IfModule mod_headers.c>
+            Header append Vary User-Agent env=!dont-vary
+        </IfModule>
+    </IfModule>
+</Location>
index 0ebc73f..da7a4c4 100755 (executable)
@@ -8,6 +8,7 @@ use OpenILS::WWW::Vandelay qw( /openils/conf/opensrf_core.xml );
 use OpenILS::WWW::TemplateBatchBibUpdate qw( /openils/conf/opensrf_core.xml );
 use OpenILS::WWW::EGWeb ('/openils/conf/oils_web.xml');
 use OpenILS::WWW::PasswordReset ('/openils/conf/opensrf_core.xml');
+use OpenILS::WWW::IDL2js ('/openils/conf/opensrf_core.xml', '/openils/var/xsl/fm_IDL2js.xsl');
 
 # - Uncoment the following 2 lines to make use of the IP redirection code
 # - The IP file should to contain a map with the following format:
diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm b/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm
new file mode 100644 (file)
index 0000000..610c80d
--- /dev/null
@@ -0,0 +1,69 @@
+package OpenILS::WWW::IDL2js;
+use strict; use warnings;
+use XML::LibXML;
+use XML::LibXSLT;
+use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
+use Error qw/:try/;
+use OpenSRF::System;
+use OpenSRF::Utils::SettingsClient;
+
+my $bs_config;
+my $stylesheet;
+my $idl_doc;
+
+
+# load and parse the stylesheet
+sub import {
+    my $self = shift;
+    $bs_config = shift;
+    my $xsl_file = shift;
+
+    my $xslt = XML::LibXSLT->new();
+
+    try {
+
+        my $style_doc = XML::LibXML->load_xml(location => $xsl_file, no_cdata=>1);
+        $stylesheet = $xslt->parse_stylesheet($style_doc);
+
+    } catch Error with {
+        my $e = shift;
+        warn "Invalid XSL File: $xsl_file: $e\n";
+    };
+}
+
+# parse the IDL, loaded from the network
+my $__initted = 0;
+sub child_init {
+       $__initted = 1;
+       OpenSRF::System->bootstrap_client(config_file => $bs_config);
+       my $sclient     = OpenSRF::Utils::SettingsClient->new();
+       my $idl_file = $sclient->config_value("IDL");
+    $idl_doc = XML::LibXML->load_xml(location => $idl_file);
+}
+
+
+sub handler {
+    my $r = shift;
+    my $args = $r->args || '';
+    child_init() unless $__initted;
+
+    return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $stylesheet and $idl_doc;
+    return Apache2::Const::DECLINED if $args and $args !~ /^[a-zA-Z,]*$/;
+
+    my $output;
+    try {
+        my $results = $stylesheet->transform($idl_doc, class_list => "'$args'");
+        $output = $stylesheet->output_as_bytes($results);
+    } catch Error with {
+        my $e = shift;
+        $r->log->error("IDL XSL Error: $e");
+    };
+
+    return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $output;
+
+    $r->content_type('application/x-javascript; encoding=utf8');
+    $r->print($output);
+    return Apache2::Const::OK;
+}
+
+1;