-# $Id: Utils.pm,v 1.16 2006-11-29 17:22:00 mike Exp $
+# $Id: Utils.pm,v 1.20 2006-12-11 13:58:17 sondberg Exp $
package ZOOM::IRSpy::Utils;
use warnings;
use Exporter 'import';
-our @EXPORT_OK = qw(xml_encode
+our @EXPORT_OK = qw(isodate
+ xml_encode
cql_quote
cql_target
irspy_xpath_context
# Utility functions follow, exported for use of web UI
+sub isodate {
+ my($time) = @_;
+
+ my($sec, $min, $hour, $mday, $mon, $year) = localtime($time);
+ return sprintf("%04d-%02d-%02dT%02d:%02d:%02d",
+ $year+1900, $mon+1, $mday, $hour, $min, $sec);
+}
+
# 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
# Template::Plugin both roll their own. So I will do likewise. D'oh!
#
sub xml_encode {
- my($text, $fallback) = @_;
+ my($text, $fallback, $opts) = @_;
+ if (!defined $opts && ref $fallback) {
+ # The second and third arguments are both optional
+ $opts = $fallback;
+ $fallback = undef;
+ }
+ $opts = {} if !defined $opts;
$text = $fallback if !defined $text;
use Carp;
$text =~ s/&/&/g;
$text =~ s/</</g;
$text =~ s/>/>/g;
- $text =~ s/['']/'/g;
+ # Internet Explorer can't display ' (!) so don't create it
+ #$text =~ s/['']/'/g;
$text =~ s/[""]/"/g;
+ $text =~ s/ / /g if $opts->{nbsp};
+
return $text;
}
}
-#print "Loaded ZOOM::IRSpy::Utils.pm";
+# This function is made available in xslt using the register_function call
+sub xslt_strcmp {
+ my ($arg1, $arg2) = @_;
+ return ($arg1->to_literal()) cmp ($arg2->to_literal());
+}
1;