From: erickson Date: Fri, 14 Nov 2008 18:26:24 +0000 (+0000) Subject: added a force_valid_xml option which causes an error when the resulting HTML is not... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1c7acf80f793cfa97adb882ff1fe9573d6d96aa2;p=Evergreen.git 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 git-svn-id: svn://svn.open-ils.org/ILS/trunk@11185 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/examples/oils_web.xml.example b/Open-ILS/examples/oils_web.xml.example index a5ac6b3f9c..afebd8e881 100644 --- a/Open-ILS/examples/oils_web.xml.example +++ b/Open-ILS/examples/oils_web.xml.example @@ -6,6 +6,11 @@ E.g. http://static.example.com/media --> + + false + diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm b/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm index 14146b9b3b..382db605f2 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm @@ -38,7 +38,7 @@ sub handler { $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 @@ sub handler { 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 @@ sub parse_config { $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;