From 978aeda288cef79bb7b243b04d88c3086991339f Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 11 Nov 2010 15:37:04 +0000 Subject: [PATCH] mod_perl handler for idl2js transform w/ configs git-svn-id: svn://svn.open-ils.org/ILS/trunk@18700 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/apache/eg_vhost.conf | 24 ++++++++++ Open-ILS/examples/apache/startup.pl | 1 + Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm | 69 +++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm diff --git a/Open-ILS/examples/apache/eg_vhost.conf b/Open-ILS/examples/apache/eg_vhost.conf index 4a2266fc0d..5b81f7a973 100644 --- a/Open-ILS/examples/apache/eg_vhost.conf +++ b/Open-ILS/examples/apache/eg_vhost.conf @@ -576,3 +576,27 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT] CustomLog /var/log/apache2/deflate_log deflate + + + + SetHandler perl-script + PerlHandler OpenILS::WWW::IDL2js + Options +ExecCGI + PerlSendHeader On + allow from all + + + Header append Cache-Control "public" + + + + 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 + + Header append Vary User-Agent env=!dont-vary + + + diff --git a/Open-ILS/examples/apache/startup.pl b/Open-ILS/examples/apache/startup.pl index 0ebc73f0e8..da7a4c4a1a 100755 --- a/Open-ILS/examples/apache/startup.pl +++ b/Open-ILS/examples/apache/startup.pl @@ -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 index 0000000000..610c80d6e1 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm @@ -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; -- 2.11.0