[open-ils-commits] r18700 - in trunk/Open-ILS: examples/apache src/perlmods/OpenILS/WWW (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Nov 11 10:37:06 EST 2010
Author: erickson
Date: 2010-11-11 10:37:04 -0500 (Thu, 11 Nov 2010)
New Revision: 18700
Added:
trunk/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm
Modified:
trunk/Open-ILS/examples/apache/eg_vhost.conf
trunk/Open-ILS/examples/apache/startup.pl
Log:
mod_perl handler for idl2js transform w/ configs
Modified: trunk/Open-ILS/examples/apache/eg_vhost.conf
===================================================================
--- trunk/Open-ILS/examples/apache/eg_vhost.conf 2010-11-11 15:31:24 UTC (rev 18699)
+++ trunk/Open-ILS/examples/apache/eg_vhost.conf 2010-11-11 15:37:04 UTC (rev 18700)
@@ -576,3 +576,27 @@
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>
Modified: trunk/Open-ILS/examples/apache/startup.pl
===================================================================
--- trunk/Open-ILS/examples/apache/startup.pl 2010-11-11 15:31:24 UTC (rev 18699)
+++ trunk/Open-ILS/examples/apache/startup.pl 2010-11-11 15:37:04 UTC (rev 18700)
@@ -8,6 +8,7 @@
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:
Added: trunk/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/WWW/IDL2js.pm 2010-11-11 15:37:04 UTC (rev 18700)
@@ -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;
More information about the open-ils-commits
mailing list