1 package OpenILS::WWW::IDL2js;
2 use strict; use warnings;
5 use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
8 use OpenSRF::Utils::SettingsClient;
15 # load and parse the stylesheet
21 # parse the IDL, loaded from the network
26 OpenSRF::System->bootstrap_client(config_file => $bs_config);
27 my $sclient = OpenSRF::Utils::SettingsClient->new();
29 my $xsl_file = $sclient->config_value('IDL2js');
32 warn "XSL2js XSL file required for IDL2js Apache module\n";
36 $xsl_file = $sclient->config_value(dirs => 'xsl')."/$xsl_file";
37 my $idl_file = $sclient->config_value("IDL");
39 my $xslt = XML::LibXSLT->new();
43 my $style_doc = XML::LibXML->load_xml(location => $xsl_file, no_cdata=>1);
44 $stylesheet = $xslt->parse_stylesheet($style_doc);
48 warn "Invalid XSL File: $xsl_file: $e\n";
51 $idl_doc = XML::LibXML->load_xml(location => $idl_file);
57 my $args = $r->args || '';
58 child_init() unless $__initted;
60 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $stylesheet and $idl_doc;
61 return Apache2::Const::DECLINED if $args and $args !~ /^[a-zA-Z,]*$/;
65 my $results = $stylesheet->transform($idl_doc, class_list => "'$args'");
66 $output = $stylesheet->output_as_bytes($results);
69 $r->log->error("IDL XSL Error: $e");
72 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $output;
74 $r->content_type('application/x-javascript; encoding=utf8');
76 return Apache2::Const::OK;