-# $Id: Utils.pm,v 1.24 2007-03-01 13:59:45 mike Exp $
+# $Id: Utils.pm,v 1.26 2007-03-19 18:51:03 mike Exp $
package ZOOM::IRSpy::Utils;
cql_target
irspy_xpath_context
modify_xml_document
- bib1_access_point);
+ bib1_access_point
+ render_record);
use XML::LibXML;
use XML::LibXML::XPathContext;
}
-# Makes a CQL query that finds a specified target
+# 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) = @_;
- return "rec.id=" . cql_quote("$host:$port/$db");
+ $host .= ":$port/$db" if defined $port;
+ return "rec.id=" . cql_quote($host);
}
sub irspy_xpath_context {
my($record) = @_;
- my $xml = ref $record ? $record->render() : $record;
- my $parser = new XML::LibXML();
- my $doc = $parser->parse_string($xml);
- my $root = $doc->getDocumentElement();
+ if (ref $record && $record->isa("ZOOM::Record")) {
+ $record = $record->render();
+ }
+
+ my $root;
+ if (ref $record) {
+ $root = $record;
+ } else {
+ my $parser = new XML::LibXML();
+ my $doc = $parser->parse_string($record);
+ $root = $doc->getDocumentElement();
+ }
+
my $xc = XML::LibXML::XPathContext->new($root);
foreach my $prefix (keys %_namespaces) {
$xc->registerNs($prefix, $_namespaces{$prefix});
}
+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;