[open-ils-commits] r13108 - in trunk/Open-ILS: examples src/perlmods/OpenILS/WWW (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri May 8 16:41:05 EDT 2009
Author: erickson
Date: 2009-05-08 16:41:01 -0400 (Fri, 08 May 2009)
New Revision: 13108
Modified:
trunk/Open-ILS/examples/oils_web.xml.example
trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm
Log:
changed the optional XML parsing to support DTD replacement via xml::libxml. added some other useful context variables
Modified: trunk/Open-ILS/examples/oils_web.xml.example
===================================================================
--- trunk/Open-ILS/examples/oils_web.xml.example 2009-05-08 20:30:11 UTC (rev 13107)
+++ trunk/Open-ILS/examples/oils_web.xml.example 2009-05-08 20:41:01 UTC (rev 13108)
@@ -1,8 +1,10 @@
<oils_web>
<!-- This should match the Apache Directory/Location[Match] configuration path -->
- <base_uri>/eg</base_uri>
+ <base_path>/eg</base_path>
+ <web_dir>/openils/var/web</web_dir>
+
<!-- when locating files that don't have explicit handlers defined, assume the
files have the following filename extension -->
<default_template_extension>tt2</default_template_extension>
@@ -35,5 +37,6 @@
<handler path='acq/currency_type/view' template='acq/financial/view_currency_type.tt2'/>
<handler path='acq/provider/list' template='acq/financial/list_providers.tt2'/>
<handler path='acq/provider/view' template='acq/financial/view_provider.tt2'/>
+ <handler path='vandelay/vandelay' template='vandelay/vandelay.tt2' as_xml='true'/>
</handlers>
</oils_web>
Modified: trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm 2009-05-08 20:30:11 UTC (rev 13107)
+++ trunk/Open-ILS/src/perlmods/OpenILS/WWW/EGWeb.pm 2009-05-08 20:41:01 UTC (rev 13108)
@@ -2,6 +2,7 @@
use strict; use warnings;
use Template;
use XML::Simple;
+use XML::LibXML;
use File::stat;
use Apache2::Const -compile => qw(OK DECLINED HTTP_INTERNAL_SERVER_ERROR);
use Apache2::Log;
@@ -29,8 +30,8 @@
my $r = shift;
check_web_config($r); # option to disable this
my $ctx = load_context($r);
- my $base = $ctx->{base_uri};
- my($template, $page_args) = find_template($r, $base, $ctx);
+ my $base = $ctx->{base_path};
+ my($template, $page_args, $as_xml) = find_template($r, $base, $ctx);
return Apache2::Const::DECLINED unless $template;
$template = $ctx->{skin} . "/$template";
@@ -38,7 +39,7 @@
$r->content_type('text/html; encoding=utf8');
my $tt = Template->new({
- OUTPUT => ($ctx->{force_valid_xml}) ? sub { validate_as_xml($r, @_); } : $r,
+ OUTPUT => ($as_xml) ? sub { parse_as_xml($r, $ctx, @_); } : $r,
INCLUDE_PATH => $ctx->{template_paths},
});
@@ -50,10 +51,17 @@
return Apache2::Const::OK;
}
-sub validate_as_xml {
+sub parse_as_xml {
my $r = shift;
+ my $ctx = shift;
my $data = shift;
- eval { XML::Simple->new->XMLin($data); };
+
+ eval {
+ my $doc = XML::LibXML->new->parse_string($data);
+ $data = $doc->documentElement->toStringC14N;
+ $data = $ctx->{final_dtd} . "\n" . $data;
+ };
+
if($@) {
my $err = "Invalid XML: $@";
$r->log->error($err);
@@ -69,6 +77,8 @@
my $r = shift;
my $cgi = CGI->new;
my $ctx = $web_config->{ctx};
+ $ctx->{hostname} = $r->hostname;
+ $ctx->{base_url} = $cgi->url(-base => 1);
$ctx->{skin} = $cgi->cookie(OILS_HTTP_COOKIE_SKIN) || 'default';
$ctx->{theme} = $cgi->cookie(OILS_HTTP_COOKIE_THEME) || 'default';
$ctx->{locale} =
@@ -104,17 +114,20 @@
my @parts = split('/', $path);
my $template = '';
my $page_args = [];
+ my $as_xml = $ctx->{force_valid_xml};
my $handler = $web_config->{handlers};
+
while(@parts) {
my $part = shift @parts;
next unless $part;
my $t = $handler->{$part};
- if(ref $t) {
- $handler = $t;
- } else {
- $template = $t;
+ if(ref($t) eq 'PathConfig') {
+ $template = $t->{template};
+ $as_xml = ($t->{as_xml} and $t->{as_xml} =~ /true/io) || $as_xml;
$page_args = [@parts];
last;
+ } else {
+ $handler = $t;
}
}
@@ -151,7 +164,7 @@
}
$r->log->debug("template = $template : page args = @$page_args");
- return ($template, $page_args);
+ return ($template, $page_args, $as_xml);
}
# if the web configuration file has never been loaded or has
@@ -173,10 +186,11 @@
my $handlers = {};
$ctx->{media_prefix} = (ref $data->{media_prefix}) ? '' : $data->{media_prefix};
- $ctx->{base_uri} = (ref $data->{base_uri}) ? '' : $data->{base_uri};
+ $ctx->{base_path} = (ref $data->{base_path}) ? '' : $data->{base_path};
$ctx->{template_paths} = [];
$ctx->{force_valid_xml} = ($data->{force_valid_xml} =~ /true/io) ? 1 : 0;
$ctx->{default_template_extension} = $data->{default_template_extension} || 'tt2';
+ $ctx->{web_dir} = $data->{web_dir};
my $tpaths = $data->{template_paths}->{path};
$tpaths = [$tpaths] unless ref $tpaths;
@@ -190,7 +204,7 @@
my $p = $parts[$i];
unless(defined $h->{$p}) {
if($i == $pcount - 1) {
- $h->{$p} = $handler->{template};
+ $h->{$p} = PathConfig->new(%$handler);
last;
} else {
$h->{$p} = {};
@@ -203,5 +217,11 @@
return {ctx => $ctx, handlers => $handlers};
}
+package PathConfig;
+sub new {
+ my($class, %args) = @_;
+ return bless(\%args, $class);
+}
+
1;
More information about the open-ils-commits
mailing list