[open-ils-commits] [GIT] Evergreen ILS branch rel_2_4 updated. 188c3589de72901b3f6e08d22aba49c3394b921d

Evergreen Git git at git.evergreen-ils.org
Fri Aug 2 16:09:57 EDT 2013


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, rel_2_4 has been updated
       via  188c3589de72901b3f6e08d22aba49c3394b921d (commit)
       via  8229e8f97bfc5f7ed4eb1ea486d2625a5d51e3fd (commit)
       via  716ecc96b8310688337bbe5dea8e85c20fd342af (commit)
      from  39143f79bc7f1f07e7971789a96d3cf07c555e6e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 188c3589de72901b3f6e08d22aba49c3394b921d
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri May 17 09:39:26 2013 -0400

    Upgrade notes for IDL2js locale support
    
    Minor Apache configuration change required.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/docs/RELEASE_NOTES_NEXT/Administration/idl2js-locale-support.txt b/docs/RELEASE_NOTES_NEXT/Administration/idl2js-locale-support.txt
new file mode 100644
index 0000000..21297e8
--- /dev/null
+++ b/docs/RELEASE_NOTES_NEXT/Administration/idl2js-locale-support.txt
@@ -0,0 +1,28 @@
+Upgrade Notes : IDL2js Locale Support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The following Apache configuration changes are required to support the 
+locale-aware IDL2js module.  
+
+// note: there's no Apache conf highlighting.  'bash' works well enough.
+[source, bash]
+-----------------------------------------------------------------
+# file: eg_vhost.conf
+
+# this is the new part
+# capture locale CGI param for /reports/fm_IDL.xml
+RewriteCond %{REQUEST_URI} ^/reports/fm_IDL.xml
+RewriteCond %{QUERY_STRING} locale=([^&;]*)
+RewriteRule . - [E=locale:%1]
+
+# it should be placed just above this existing config section
+<LocationMatch /reports/fm_IDL.xml>
+    IDLChunkStripPI "yes"
+    IDLChunkEscapeScript "no"
+    IDLChunkStripComments "yes"
+    IDLChunkStripDoctype "yes"
+    IDLChunkContentType "application/xml; charset=utf-8"
+    AddOutputFilter INCLUDES;IDLCHUNK .xml
+</LocationMatch>
+-----------------------------------------------------------------
+

commit 8229e8f97bfc5f7ed4eb1ea486d2625a5d51e3fd
Author: Bill Erickson <berick at esilibrary.com>
Date:   Mon May 6 09:59:22 2013 -0400

    LP1171875 Support locale CGI param for fm_IDL.xml
    
    Adds support for passing the locale string directly to
    /reports/fm_IDL.xml via locale= CGI parameter.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Pasi Kallinen <pasi.kallinen at pttk.fi>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/examples/apache/eg_vhost.conf.in b/Open-ILS/examples/apache/eg_vhost.conf.in
index 60605b3..bf58315 100644
--- a/Open-ILS/examples/apache/eg_vhost.conf.in
+++ b/Open-ILS/examples/apache/eg_vhost.conf.in
@@ -527,6 +527,11 @@ RewriteRule .? - [E=locale:%{HTTP:Accept-Language}]
     AddOutputFilter INCLUDES;XMLENT .xhtml
 </LocationMatch>
 
+# capture locale CGI param for /reports/fm_IDL.xml
+RewriteCond %{REQUEST_URI} ^/reports/fm_IDL.xml
+RewriteCond %{QUERY_STRING} locale=([^&;]*)
+RewriteRule . - [E=locale:%1]
+
 <LocationMatch /reports/fm_IDL.xml>
     IDLChunkStripPI "yes"
     IDLChunkEscapeScript "no"
diff --git a/Open-ILS/examples/apache_24/eg_vhost.conf.in b/Open-ILS/examples/apache_24/eg_vhost.conf.in
index b606c02..f8537d4 100644
--- a/Open-ILS/examples/apache_24/eg_vhost.conf.in
+++ b/Open-ILS/examples/apache_24/eg_vhost.conf.in
@@ -532,6 +532,11 @@ RewriteRule .? - [E=locale:%{HTTP:Accept-Language}]
     AddOutputFilter INCLUDES;XMLENT .xhtml
 </LocationMatch>
 
+# capture locale CGI param for /reports/fm_IDL.xml
+RewriteCond %{REQUEST_URI} ^/reports/fm_IDL.xml
+RewriteCond %{QUERY_STRING} locale=([^&;]*)
+RewriteRule . - [E=locale:%1]
+
 <LocationMatch /reports/fm_IDL.xml>
     IDLChunkStripPI "yes"
     IDLChunkEscapeScript "no"

commit 716ecc96b8310688337bbe5dea8e85c20fd342af
Author: Bill Erickson <berick at esilibrary.com>
Date:   Fri Apr 26 13:20:24 2013 -0400

    LP1171875 Add locale support to IDL2js
    
    /IDL2js now reads locale information from either locale= CGI parameter
    or Accept-Language HTTP headers.  The locale-aware IDL is loaded from
    /reports/fm_IDL.xml via Apache subrequest.  Each full copy of the IDL is
    cached within the Apache processes to avoid the need to re-parse the IDL ad
    infinitum for full IDL retrieval.  Partial IDL retrieval is also supported
    (but not cached).
    
    No attempt is made to cleanse the locale -- invalid locale strings are
    discarded -- so it's the callers responsibility to pass a valid locale.
    
    Signed-off-by: Bill Erickson <berick at esilibrary.com>
    Signed-off-by: Pasi Kallinen <pasi.kallinen at pttk.fi>
    Signed-off-by: Mike Rylander <mrylander at gmail.com>

diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm
index c55f137..497b0db 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm
@@ -3,14 +3,18 @@ use strict; use warnings;
 use XML::LibXML;
 use XML::LibXSLT;
 use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
+use Apache2::RequestRec;
+use Apache2::SubRequest;
+use Apache2::Filter;
+use APR::Brigade;
+use APR::Bucket;
 use Error qw/:try/;
 use OpenSRF::System;
 use OpenSRF::Utils::SettingsClient;
+use CGI;
 
 my $bs_config;
 my $stylesheet;
-my $idl_doc;
-
 
 # load and parse the stylesheet
 sub import {
@@ -48,21 +52,82 @@ sub child_init {
         warn "Invalid XSL File: $xsl_file: $e\n";
     };
 
-    $idl_doc = XML::LibXML->load_xml(location => $idl_file);
     return Apache2::Const::OK;
 }
 
 
+my %idl_cache;
 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,]*$/;
+    return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $stylesheet;
+
+    # pull the locale from the query string if present
+    (my $locale = $args) =~ s/.*locale=([a-z]{2}-[A-Z]{2}).*/$1/g;
+
+    # remove the locale argument from the query 
+    # string, regardless of whether it was valid
+    $args =~ s/([&;]?locale=[^&;]*)[&;]?//g; 
+
+    # if no valid locale is present in the query 
+    # string, pull it from the headers
+    $locale = $r->headers_in->get('Accept-Language') unless $locale;
+
+    if (!$locale or $locale !~ /^[a-z]{2}-[A-Z]{2}$/) {
+        $r->log->debug("Invalid IDL2js locale '$locale'; using en-US");
+        $locale = 'en-US';
+    }
+
+    $r->log->debug("IDL2js using locale '$locale'");
+
+    my $output = '';
+    my $stat = load_IDL($r, $locale, $args, \$output);
+    return $stat unless $stat == Apache2::Const::OK;
+
+    $r->content_type('application/x-javascript; encoding=utf8');
+    $r->print($output);
+    return Apache2::Const::OK;
+}
+
+# loads the IDL for the provided locale.
+# when possible, use a cached version of the IDL.
+sub load_IDL {
+    my ($r, $locale, $args, $output_ref) = @_;
+
+    # do we already have a cached copy of the IDL for this locale?
+    if (!$args and $idl_cache{$locale}) {
+        $$output_ref = $idl_cache{$locale};
+        return Apache2::Const::OK;
+    }
+
+    # Fetch the locale-aware fm_IDL.xml via Apache subrequest.
+    my $subr = $r->lookup_uri("/reports/fm_IDL.xml?locale=$locale");
+
+    # filter allows us to capture the output of the subrequest locally
+    # http://www.gossamer-threads.com/lists/modperl/modperl/97649#97649
+    my $xml = ''; 
+    $subr->add_output_filter(sub {
+        my ($f, $bb) = @_; 
+        while (my $e = $bb->first) { 
+            $e->read(my $buf); 
+            $xml .= $buf; 
+            $e->delete; 
+        } 
+        return Apache2::Const::OK; 
+    }); 
+
+    $subr->run;
+
+    if (!$xml) {
+        $r->log->error("No IDL XML found");
+        return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
+    }
 
     my $output;
     try {
+        my $idl_doc = XML::LibXML->load_xml(string => $xml);
         my $results = $stylesheet->transform($idl_doc, class_list => "'$args'");
         $output = $stylesheet->output_as_bytes($results);
     } catch Error with {
@@ -72,9 +137,13 @@ sub handler {
 
     return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR unless $output;
 
-    $r->content_type('application/x-javascript; encoding=utf8');
-    $r->print($output);
-    return Apache2::Const::OK;
+    # only cache full versions of the IDL
+    $idl_cache{$locale} = $output unless $args;
+
+    # pass output back to the caller
+    $$output_ref = $output;
+
+    return Apache2::Const::OK; 
 }
 
 1;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/apache/eg_vhost.conf.in          |    5 +
 Open-ILS/examples/apache_24/eg_vhost.conf.in       |    5 +
 Open-ILS/src/perlmods/lib/OpenILS/WWW/IDL2js.pm    |   85 ++++++++++++++++++--
 .../Administration/idl2js-locale-support.txt       |   28 +++++++
 4 files changed, 115 insertions(+), 8 deletions(-)
 create mode 100644 docs/RELEASE_NOTES_NEXT/Administration/idl2js-locale-support.txt


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list