]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/extras/opensearch.pm
fixin...
[Evergreen.git] / Open-ILS / src / extras / opensearch.pm
1 package opensearch;
2 use strict; use warnings;
3
4 use Apache2 ();
5 use Apache::Log;
6 use Apache::Const -compile => qw(OK REDIRECT :log);
7 use APR::Const    -compile => qw(:error SUCCESS);
8 use Apache::RequestRec ();
9 use Apache::RequestIO ();
10 use Apache::RequestUtil;
11
12 use CGI ();
13 use Template qw(:template);
14
15 use OpenSRF::EX qw(:try);
16 use OpenSRF::System;
17
18 my $child_init_ttk = "opensearch.ttk";
19
20 my $includes = [ '/pines/cvs/ILS/Open-ILS/src/extras' ];
21
22 my $plugin_base = 'OpenILS::Template::Plugin';
23
24 sub handler {
25
26         my $apache = shift;
27         print "Content-type: text/xml; charset=utf-8\n\n";
28
29         _process_template(
30                         apache          => $apache,
31                         template                => 'opensearch.ttk',
32                         );
33
34         return Apache::OK;
35 }
36
37 sub child_init_handler {
38         _process_template(  template => $child_init_ttk );
39 }
40
41 sub _process_template {
42
43         my %params = @_;
44         my $ttk                         = $params{template}             || return undef;
45         my $apache                      = $params{apache}                       || undef;
46         my $pre_process = $params{pre_process}  || undef;
47         my $param_hash          = $params{params}                       || {};
48
49         my $template;
50
51         $template = Template->new( { 
52                 OUTPUT                  => $apache, 
53                 ABSOLUTE                        => 1, 
54                 RELATIVE                        => 1,
55                 PLUGIN_BASE             => $plugin_base,
56                 PRE_PROCESS             => $pre_process,
57                 INCLUDE_PATH    => $includes, 
58                 PRE_CHOMP               => 1,
59                 POST_CHOMP              => 1,
60                 } 
61         );
62
63         try {
64
65                 if( ! $template->process( $ttk, $param_hash ) ) { 
66                         warn  "Error Occured: " . $template->error();
67                         my $err = $template->error();
68                         $err =~ s/\n/\<br\/\>/g;
69                         warn "Error processing template $ttk\n";        
70                         print "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
71                 }
72
73         } catch Error with {
74                 my $e = shift;
75                 warn "Error processing template $ttk:  $e - $@ \n";     
76                 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
77                 return;
78         };
79
80 }
81
82
83 1;