modify_xml_document()'s code for no-opping when no change has been
[irspy-moved-to-github.git] / lib / ZOOM / IRSpy / Utils.pm
index e24fd6c..6049e93 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Utils.pm,v 1.27 2007-04-27 14:04:40 mike Exp $
+# $Id: Utils.pm,v 1.30 2007-05-02 13:52:54 mike Exp $
 
 package ZOOM::IRSpy::Utils;
 
@@ -181,11 +181,24 @@ sub irspy_record2identifier {
 # a null transform; now we have to be a bit cleverer.
 #
 sub irspy_identifier2target {
+    my $res = _irspy_identifier2target(@_);
+    #carp "converted ID '@_' to target '$res'";
+    return $res;
+}
+
+sub _irspy_identifier2target {
     my($id) = @_;
 
     my($protocol, $target) = ($id =~ /(.*?):(.*)/);
-    print STDERR "protocol='$protocol', target='$target'\n";
-    ### This assumes everything is Z39.50
+    if (uc($protocol) eq "Z39.50") {
+       return "tcp:$target";
+    } elsif (uc($protocol) eq "SRU") {
+       return "sru=get,http:$target";
+    } elsif (uc($protocol) eq "SRW") {
+       return "sru=srw,http:$target";
+    }
+
+    warn "unrecognised protocol '$protocol' in ID $id";
     return $target;
 }
 
@@ -219,21 +232,21 @@ sub modify_xml_document {
                # we'll check whether the element is already
                # canonical, to determine whether our change is a
                # no-op.
-               my $old = "???";
+               my $old = "";
                my @children = $node->childNodes();
                if (@children == 1) {
                    my $child = $node->firstChild();
                    if (ref $child && ref $child eq "XML::LibXML::Text") {
                        $old = $child->getData();
-                       next if $value eq $old;
                    }
                }
+               next if $value eq $old;
 
                $node->removeChildNodes();
                my $child = new XML::LibXML::Text($value);
                $node->appendChild($child);
                push @changes, $ref;
-               #print "Elem $key: '$old' -> '$value' ($xpath)<br/>\n";
+               print STDERR "Elem $key: '$old' -> '$value' ($xpath)<br/>\n";
            } else {
                warn "unexpected node type $node";
            }