-# $Id: Utils.pm,v 1.22 2007-03-01 13:51:18 mike Exp $
+# $Id: Utils.pm,v 1.25 2007-03-05 19:41:57 mike Exp $
package ZOOM::IRSpy::Utils;
our @EXPORT_OK = qw(isodate
xml_encode
cql_quote
+ cql_target
irspy_xpath_context
modify_xml_document
- bib1_access_point);
+ bib1_access_point
+ render_record);
use XML::LibXML;
use XML::LibXML::XPathContext;
my($term) = @_;
$term =~ s/([""\\])/\\$1/g;
- $term = qq["$term"] if $term =~ /\s/;
+ $term = qq["$term"] if $term =~ /[\s""\/]/;
return $term;
}
+# Makes a CQL query that finds a specified target. Arguments may be
+# either an ID alone, or a (host, port, db) triple.
+sub cql_target {
+ my($host, $port, $db) = @_;
+
+ $host .= ":$port/$db" if defined $port;
+ return "rec.id=" . cql_quote($host);
+}
+
+
# PRIVATE to irspy_namespace() and irspy_xpath_context()
my %_namespaces = (
e => 'http://explain.z3950.org/dtd/2.0/',
}
+sub render_record {
+ my($rs, $which, $elementSetName) = @_;
+
+ # There is a slight race condition here on the element-set name,
+ # but it shouldn't be a problem as this is (currently) only called
+ # from parts of the program that run single-threaded.
+ my $old = $rs->option(elementSetName => $elementSetName);
+ my $rec = $rs->record($which);
+ $rs->option(elementSetName => $old);
+
+ return $rec->render();
+}
+
+
1;