[open-ils-commits] r11185 - in trunk/Open-ILS: examples src/perlmods/OpenILS/WWW
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Nov 14 13:26:27 EST 2008
Author: erickson
Date: 2008-11-14 13:26:24 -0500 (Fri, 14 Nov 2008)
New Revision: 11185
Modified:
trunk/Open-ILS/examples/oils_web.xml.example
trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm
Log:
added a force_valid_xml option which causes an error when the resulting HTML is not valid XML. this is good for debugging, when html thinkos lead to broken pages
Modified: trunk/Open-ILS/examples/oils_web.xml.example
===================================================================
--- trunk/Open-ILS/examples/oils_web.xml.example 2008-11-14 15:53:19 UTC (rev 11184)
+++ trunk/Open-ILS/examples/oils_web.xml.example 2008-11-14 18:26:24 UTC (rev 11185)
@@ -6,6 +6,11 @@
E.g. <media_prefix>http://static.example.com/media</media_prefix> -->
<media_prefix/>
+ <!-- If set to true, all output will be parsed as XML before delivery to the client.
+ If XML parsing fails, the error message, with HTML included, will be output as text/plain.
+ XML parsing adds overhead, so this should only be used for debugging -->
+ <force_valid_xml>false</force_valid_xml>
+
<!-- Where templates can be found. Paths will be checked in the order entered here.
It's possible to override individual or sets of templates by putting them into
a path in front of the default template path -->
Modified: trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm 2008-11-14 15:53:19 UTC (rev 11184)
+++ trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm 2008-11-14 18:26:24 UTC (rev 11185)
@@ -38,7 +38,7 @@
$r->content_type('text/html; encoding=utf8');
my $tt = Template->new({
- OUTPUT => $r,
+ OUTPUT => ($ctx->{force_valid_xml}) ? sub { validate_as_xml($r, @_); } : $r,
INCLUDE_PATH => $ctx->{template_paths},
});
@@ -50,6 +50,21 @@
return Apache2::Const::OK;
}
+sub validate_as_xml {
+ my $r = shift;
+ my $data = shift;
+ eval { XML::Simple->new->XMLin($data); };
+ if($@) {
+ my $err = "Invalid XML: $@";
+ $r->log->error($err);
+ $r->content_type('text/plain; encoding=utf8');
+ $r->print("\n$err\n\n$data");
+ } else {
+ $r->print($data);
+ }
+}
+
+
sub load_context {
my $r = shift;
my $cgi = CGI->new;
@@ -120,6 +135,7 @@
$ctx->{media_prefix} = (ref $data->{media_prefix}) ? '' : $data->{media_prefix};
$ctx->{base_uri} = (ref $data->{base_uri}) ? '' : $data->{base_uri};
$ctx->{template_paths} = [];
+ $ctx->{force_valid_xml} = ($data->{force_valid_xml} =~ /true/io) ? 1 : 0;
my $tpaths = $data->{template_paths}->{path};
$tpaths = [$tpaths] unless ref $tpaths;
More information about the open-ils-commits
mailing list