LP#1442276: Upgrade script for Encoding UTF8 output
authorKathy Lussier <klussier@masslnc.org>
Sat, 11 Mar 2017 03:53:18 +0000 (22:53 -0500)
committerDan Scott <dscott@laurentian.ca>
Sun, 12 Mar 2017 04:13:36 +0000 (23:13 -0500)
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
Open-ILS/src/sql/Pg/upgrade/xxxx.function.oils_xslt_process_utf8_fix [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.function.oils_xslt_process_utf8_fix b/Open-ILS/src/sql/Pg/upgrade/xxxx.function.oils_xslt_process_utf8_fix
new file mode 100644 (file)
index 0000000..9557c4f
--- /dev/null
@@ -0,0 +1,43 @@
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('xxxx', :eg_version);
+
+CREATE OR REPLACE FUNCTION evergreen.oils_xslt_process(TEXT, TEXT) RETURNS TEXT AS $func$
+  use strict;
+
+  use XML::LibXSLT;
+  use XML::LibXML;
+
+  my $doc = shift;
+  my $xslt = shift;
+
+  # The following approach uses the older XML::LibXML 1.69 / XML::LibXSLT 1.68
+  # methods of parsing XML documents and stylesheets, in the hopes of broader
+  # compatibility with distributions
+  my $parser = $_SHARED{'_xslt_process'}{parsers}{xml} || XML::LibXML->new();
+
+  # Cache the XML parser, if we do not already have one
+  $_SHARED{'_xslt_process'}{parsers}{xml} = $parser
+    unless ($_SHARED{'_xslt_process'}{parsers}{xml});
+
+  my $xslt_parser = $_SHARED{'_xslt_process'}{parsers}{xslt} || XML::LibXSLT->new();
+
+  # Cache the XSLT processor, if we do not already have one
+  $_SHARED{'_xslt_process'}{parsers}{xslt} = $xslt_parser
+    unless ($_SHARED{'_xslt_process'}{parsers}{xslt});
+
+  my $stylesheet = $_SHARED{'_xslt_process'}{stylesheets}{$xslt} ||
+    $xslt_parser->parse_stylesheet( $parser->parse_string($xslt) );
+
+  $_SHARED{'_xslt_process'}{stylesheets}{$xslt} = $stylesheet
+    unless ($_SHARED{'_xslt_process'}{stylesheets}{$xslt});
+
+  return $stylesheet->output_as_chars(
+    $stylesheet->transform(
+      $parser->parse_string($doc)
+    )
+  );
+
+$func$ LANGUAGE 'plperlu' STRICT IMMUTABLE;
+
+COMMIT;