Bugzilla – Attachment 65534 Details for
Bug 17807
Use XSLT_Handler in oai.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17807: Add format parameter to XSLT_Handler->transform
Bug-17807-Add-format-parameter-to-XSLTHandler-tran.patch (text/plain), 4.93 KB, created by
Nick Clemens (kidclamp)
on 2017-08-07 12:27:59 UTC
(
hide
)
Description:
Bug 17807: Add format parameter to XSLT_Handler->transform
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-08-07 12:27:59 UTC
Size:
4.93 KB
patch
obsolete
>From 8157b30a4855acc29716031b98b0144a06090c08 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 21 Dec 2016 15:50:31 +0100 >Subject: [PATCH] Bug 17807: Add format parameter to XSLT_Handler->transform > >Format may be chars (default), bytes or xmldoc. >Note: xmldoc is a XML::LibXML document object. >Since the default is chars, this does not affect current use. > >Note: The format parameter (xmldoc) will be used later in one of the OAI >modules to prevent duplicated xml parsing. > >Test plan: >Run t/db_dependent/XSLT_Handler.t > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > Koha/XSLT_Handler.pm | 29 ++++++++++++++++++----------- > t/db_dependent/XSLT_Handler.t | 7 ++++++- > 2 files changed, 24 insertions(+), 12 deletions(-) > >diff --git a/Koha/XSLT_Handler.pm b/Koha/XSLT_Handler.pm >index f4e9411..7541afa 100644 >--- a/Koha/XSLT_Handler.pm >+++ b/Koha/XSLT_Handler.pm >@@ -130,10 +130,10 @@ __PACKAGE__->mk_accessors(qw( do_not_return_source print_warns )); > > =head2 transform > >- my $output= $xslt_engine->transform( $xml, $xsltfilename ); >+ my $output= $xslt_engine->transform( $xml, $xsltfilename, [$format] ); > #Alternatively: >- #$output = $xslt_engine->transform({ xml => $xml, file => $file, [parameters => $parameters] }); >- #$output = $xslt_engine->transform({ xml => $xml, code => $code, [parameters => $parameters] }); >+ #$output = $xslt_engine->transform({ xml => $xml, file => $file, [parameters => $parameters], [format => ['chars'|'bytes'|'xmldoc']] }); >+ #$output = $xslt_engine->transform({ xml => $xml, code => $code, [parameters => $parameters], [format => ['chars'|'bytes'|'xmldoc']] }); > if( $xslt_engine->err ) { > #decide what to do on failure.. > } >@@ -143,7 +143,8 @@ __PACKAGE__->mk_accessors(qw( do_not_return_source print_warns )); > Instead of a filename, you may also pass a URL. > You may also pass the contents of a xsl file as a string like $code above. > If you do not pass a filename, the last file used is assumed. >- Returns the transformed string. >+ Normally returns the transformed string; if you pass format => 'xmldoc' in >+ the hash format, it returns a xml document object. > Check the error number in err to know if something went wrong. > In that case do_not_return_source did determine the return value. > >@@ -153,17 +154,19 @@ sub transform { > my $self = shift; > > #check parameters >- # old style: $xml, $filename >+ # old style: $xml, $filename, $format > # new style: $hashref >- my ( $xml, $filename, $xsltcode ); >+ my ( $xml, $filename, $xsltcode, $format ); > my $parameters = {}; > if( ref $_[0] eq 'HASH' ) { > $xml = $_[0]->{xml}; > $xsltcode = $_[0]->{code}; > $filename = $_[0]->{file} if !$xsltcode; #xsltcode gets priority > $parameters = $_[0]->{parameters} if ref $_[0]->{parameters} eq 'HASH'; >+ $format = $_[0]->{format} || 'chars'; > } else { >- ( $xml, $filename ) = @_; >+ ( $xml, $filename, $format ) = @_; >+ $format ||= 'chars'; > } > > #Initialized yet? >@@ -193,7 +196,7 @@ sub transform { > $self->_set_error( 5, $@ ); > return $retval; > } >- my $str = eval { >+ my $result = eval { > #$parameters is an optional hashref that contains > #key-value pairs to be sent to the XSLT. > #Numbers may be bare but strings must be double quoted >@@ -202,15 +205,19 @@ sub transform { > > #NOTE: Parameters are not cached. They are provided for > #each different transform. >- my $result = $stsh->transform($source, %$parameters); >- $stsh->output_as_chars($result); >+ my $transformed = $stsh->transform($source, %$parameters); >+ $format eq 'bytes' >+ ? $stsh->output_as_bytes( $transformed ) >+ : $format eq 'xmldoc' >+ ? $transformed >+ : $stsh->output_as_chars( $transformed ); # default: chars > }; > if ($@) { > $self->_set_error( 6, $@ ); > return $retval; > } > $self->{last_xsltfile} = $key; >- return $str; >+ return $result; > } > > =head2 refresh >diff --git a/t/db_dependent/XSLT_Handler.t b/t/db_dependent/XSLT_Handler.t >index 40274b0..8d6bc5c 100644 >--- a/t/db_dependent/XSLT_Handler.t >+++ b/t/db_dependent/XSLT_Handler.t >@@ -21,7 +21,7 @@ use Modern::Perl; > > use FindBin; > use File::Slurp; >-use Test::More tests => 40; >+use Test::More tests => 41; > use Test::Warn; > > use Koha::XSLT_Handler; >@@ -134,6 +134,11 @@ is( $output, $output2, 'Try hash parameter code'); > #Check rerun on last code > $output2 = $engine->transform( $xml_2 ); > is( $output, $output2, 'Rerun on previous passed code'); >+#Check format xmldoc >+is( ref $engine->transform({ >+ file => $xsltfile_1, xml => $xml_2, format => 'xmldoc', >+}), 'XML::LibXML::Document', >+'Format parameter returns a xml document object' ); > > #The second test xsl contains bad code > my $xsltfile_2 = 'test02.xsl'; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17807
:
58348
|
58349
|
63463
|
63464
|
63935
|
64045
|
64046
|
64047
|
64048
|
65534
|
65535
|
65536
|
66635
|
66636
|
66637