X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FRecord.pm;h=1ab5033308245ee4b9c1aa0dfe5da7c3ca4a1b1c;hb=8db258f86776ee4d7049c59e81c319f05cd292fc;hp=165f62e525c6ed7304515a7b596c57c32e6ec253;hpb=4172edcd817f7b978a772fe2b8365e4f1ee8f3bb;p=irspy-moved-to-github.git diff --git a/lib/ZOOM/IRSpy/Record.pm b/lib/ZOOM/IRSpy/Record.pm index 165f62e..1ab5033 100644 --- a/lib/ZOOM/IRSpy/Record.pm +++ b/lib/ZOOM/IRSpy/Record.pm @@ -1,4 +1,4 @@ -# $Id: Record.pm,v 1.10 2006-07-25 16:53:28 mike Exp $ +# $Id: Record.pm,v 1.13 2006-09-26 09:08:09 mike Exp $ package ZOOM::IRSpy::Record; @@ -6,6 +6,9 @@ use 5.008; use strict; use warnings; +use Exporter 'import'; +our @EXPORT_OK = qw(xml_encode); + use XML::LibXML; use XML::LibXML::XPathContext; @@ -26,7 +29,7 @@ I<## To follow> sub new { my $class = shift(); - my($target, $zeerex) = @_; + my($irspy, $target, $zeerex) = @_; if (!defined $zeerex) { $zeerex = _empty_zeerex_record($target); @@ -34,6 +37,7 @@ sub new { my $parser = new XML::LibXML(); return bless { + irspy => $irspy, target => $target, parser => $parser, zeerex => $parser->parse_string($zeerex)->documentElement(), @@ -47,18 +51,37 @@ sub _empty_zeerex_record { ### Doesn't recognise SRU/SRW URLs my($host, $port, $db) = ZOOM::IRSpy::_parse_target_string($target); + my $xhost = xml_encode($host); + my $xport = xml_encode($port); + my $xdb = xml_encode($db); return <<__EOT__; - $host - $port - $db + $xhost + $xport + $xdb __EOT__ } +# I can't -- just can't, can't, can't -- believe that this function +# isn't provided by one of the core XML modules. But the evidence all +# says that it's not: among other things, XML::Generator and +# Template::Plugin both roll their own. So I will do likewise. D'oh! +# +sub xml_encode { + my ($text) = @_; + $text =~ s/&/&/g; + $text =~ s//>/g; + $text =~ s/['']/'/g; + $text =~ s/[""]/"/g; + return $text; +} + + sub append_entry { my $this = shift(); my($xpath, $frag) = @_; @@ -82,8 +105,8 @@ sub append_entry { if @nodes == 0; } - ZOOM::Log::log("irspy", - scalar(@nodes), " matches for '$xpath': using first") + $this->{irspy}->log("irspy", + scalar(@nodes), " matches for '$xpath': using first") if @nodes > 1; $this->_half_decent_appendWellBalancedChunk($nodes[0], $frag);