-# $Id: Record.pm,v 1.10 2006-07-25 16:53:28 mike Exp $
+# $Id: Record.pm,v 1.17 2006-10-23 12:22:52 sondberg Exp $
package ZOOM::IRSpy::Record;
sub new {
my $class = shift();
- my($target, $zeerex) = @_;
+ my($irspy, $target, $zeerex) = @_;
if (!defined $zeerex) {
$zeerex = _empty_zeerex_record($target);
my $parser = new XML::LibXML();
return bless {
+ irspy => $irspy,
target => $target,
parser => $parser,
zeerex => $parser->parse_string($zeerex)->documentElement(),
### Doesn't recognise SRU/SRW URLs
my($host, $port, $db) = ZOOM::IRSpy::_parse_target_string($target);
+ my $xhost = ZOOM::IRSpy::xml_encode($host);
+ my $xport = ZOOM::IRSpy::xml_encode($port);
+ my $xdb = ZOOM::IRSpy::xml_encode($db);
return <<__EOT__;
<explain xmlns="http://explain.z3950.org/dtd/2.0/">
<serverInfo protocol="Z39.50" version="1995">
- <host>$host</host>
- <port>$port</port>
- <database>$db</database>
+ <host>$xhost</host>
+ <port>$xport</port>
+ <database>$xdb</database>
</serverInfo>
</explain>
__EOT__
my $root = $this->{zeerex}; # XML::LibXML::Element ISA XML::LibXML::Node
my $xc = XML::LibXML::XPathContext->new($root);
$xc->registerNs(zeerex => "http://explain.z3950.org/dtd/2.0/");
- $xc->registerNs(irspy => "http://indexdata.com/irspy/1.0");
+ $xc->registerNs(irspy => $ZOOM::IRSpy::irspy_ns);
my @nodes = $xc->findnodes($xpath);
if (@nodes == 0) {
if @nodes == 0;
}
- ZOOM::Log::log("irspy",
- scalar(@nodes), " matches for '$xpath': using first")
+ $this->{irspy}->log("warn",
+ scalar(@nodes), " matches for '$xpath': using first")
if @nodes > 1;
$this->_half_decent_appendWellBalancedChunk($nodes[0], $frag);
}
+sub store_result {
+ my ($this, $type, %info) = @_;
+ my $xml = "<irspy:$type";
+
+ foreach my $key (keys %info) {
+ $xml .= " $key=\"" . $this->_string2cdata($info{$key}) . "\"";
+ }
+
+ $xml .= ">" . $this->_isodate(time()) . "</irspy:$type>\n";
+
+ $this->append_entry('irspy:status', $xml);
+}
+
# *sigh*
#
# namespace mapping for that node -- but that only affects pre-parsed
# trees, and is no use for parsing. Hence the following pair of lines
# DOES NOT WORK:
-# $node->setNamespace("http://indexdata.com/irspy/1.0", "irspy", 0);
+# $node->setNamespace($ZOOM::IRSpy::irspy_ns, "irspy", 0);
# $node->appendWellBalancedChunk($frag);
#
# Instead I have to go the long way round, hence this method. I have
my($node, $frag) = @_;
if (1) {
- $frag =~ s,>, xmlns:irspy="http://indexdata.com/irspy/1.0">,;
+ $frag =~ s,>, xmlns:irspy="$ZOOM::IRSpy::irspy_ns">,;
$node->appendWellBalancedChunk($frag);
return;
}
}
+# Yes, I know that this is already implemented in IRSpy.pm. I suggest that we
+# introduce a toolkit package with such subroutines...
+#
+sub _string2cdata {
+ my ($this, $buffer) = @_;
+ $buffer =~ s/&/&/gs;
+ $buffer =~ s/</</gs;
+ $buffer =~ s/>/>/gs;
+ $buffer =~ s/"/"/gs;
+ $buffer =~ s/'/'/gs;
+
+ return $buffer;
+}
+
+
+sub _isodate {
+ my ($this, $time) = @_;
+ return ZOOM::IRSpy::Test::isodate($time);
+}
+
+
=head1 SEE ALSO
ZOOM::IRSpy