annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 144:b56ebc31bf18

Empty nodes no more created while transforming a post request to the DOM document minor speed improvements to the object CTOR caching Added support for a secure processing (and 'laundering' ) a CGI parameters Many minor fixes
author wizard
date Tue, 13 Jul 2010 02:05:38 +0400
parents fb896377389f
children 60fd224f3e3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
1 package IMPL::Web::QueryHandler::PageFormat;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
2 use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill);
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
3 use strict;
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
4
c64bd1bf727d Web application
wizard
parents:
diff changeset
5 __PACKAGE__->PassThroughArgs;
c64bd1bf727d Web application
wizard
parents:
diff changeset
6
140
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
7 use JSON;
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
8 use IMPL::Class::Property;
77
9d24db321029 Refactoring Web::TT
wizard
parents: 65
diff changeset
9 use IMPL::Web::TT::Document;
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
10 use Template::Plugin::URL;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
11 use IMPL::Security::Context;
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
12 use File::Spec;
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
13 use Error qw(:try);
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
14
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
15 $Template::Plugin::URL::JOINT = '&';
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
16
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
17 BEGIN {
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
18 public property templatesCharset => prop_all;
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
19 public property templatesBase => prop_all;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
20 public property defaultTarget => prop_all;
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
21 public property pathinfoPrefix => prop_all;
134
44977efed303 Significant performance optimizations
wizard
parents: 129
diff changeset
22 public property cache => prop_all;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
23 }
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
24
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
25 sub CTOR {
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
26 my ($this) = @_;
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
27
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
28 $this->templatesCharset('utf-8') unless $this->templatesCharset;
134
44977efed303 Significant performance optimizations
wizard
parents: 129
diff changeset
29 $this->cache(File::Spec->rel2abs($this->cache)) if $this->cache;
44977efed303 Significant performance optimizations
wizard
parents: 129
diff changeset
30 $this->templatesBase(File::Spec->rel2abs($this->templatesBase)) if $this->templatesBase;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
31 }
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
32
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
33 sub Process {
c64bd1bf727d Web application
wizard
parents:
diff changeset
34 my ($this,$action,$nextHandler) = @_;
c64bd1bf727d Web application
wizard
parents:
diff changeset
35
134
44977efed303 Significant performance optimizations
wizard
parents: 129
diff changeset
36 my $doc = new IMPL::Web::TT::Document(cache => $this->cache);
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
37
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
38 try {
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
39
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
40 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
41
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
42 my ($requestUri) = split /\?/, $ENV{REQUEST_URI};
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
43
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
44 my $pathInfo;
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
45
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
46 if ( $requestUri eq $ENV{SCRIPT_NAME}.$ENV{PATH_INFO} ) {
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
47 # CGI with path info
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
48 $pathInfo = $ENV{PATH_INFO};
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
49 } else {
137
6975cd4973d1 minor fix
wizard
parents: 136
diff changeset
50 die "REQUEST_URI: $requestUri\nPATH_INFO: $ENV{PATH_INFO}" unless $requestUri eq $ENV{PATH_INFO};
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
51 }
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
52
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
53 my @root = ('');
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
54 my @base;
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
55
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
56 if (my $rx = $this->pathinfoPrefix) {
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
57 $requestUri =~ s/^($rx)//;
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
58 push @root, grep $_, split /\//, $1 if $1;
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
59 }
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
60
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
61 $pathInfo = $requestUri unless defined $pathInfo;
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
62
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
63 @base = grep $_, split /\//, ($pathInfo ? substr $requestUri,0, -length($pathInfo) : $requestUri);
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
64
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
65 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
66
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
67 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
68
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
69 my @pathContainer = @path;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
70 pop @pathContainer;
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
71
121
92c850d0bdb9 Minor changes
wizard
parents: 116
diff changeset
72 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase );
140
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
73
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
74 $doc->AddVar( result => $nextHandler->() );
144
b56ebc31bf18 Empty nodes no more created while transforming a post request to the DOM document
wizard
parents: 140
diff changeset
75 $doc->AddVar( action => $action );
129
e4f15cbc3f1a Fixed utf-8 problem
wizard
parents: 127
diff changeset
76 $doc->AddVar( app => $action->application );
140
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
77
136
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
78 $doc->AddVar( absoluteUrl => sub { join '/', @root, $_[0] } );
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
79 $doc->AddVar( baseUrl => sub { join '/', @root, @base, $_[0] } );
f6af119ac741 url routines for templates
wizard
parents: 134
diff changeset
80 $doc->AddVar( relativeUrl => sub { join '/', @root, @base, @pathContainer,$_[0] } );
140
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
81
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
82 $doc->AddVar( user => IMPL::Security::Context->current->principal );
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
83 $doc->AddVar( session => IMPL::Security::Context->current );
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
84
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
85 $doc->AddVar( to_json => \&to_json );
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
86 $doc->AddVar( escape_string => sub { $_[0] =~ s/"/"/g; $_[0] } );
fb896377389f to_json and escape_string functions for the templates
wizard
parents: 137
diff changeset
87
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
88
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
89 $action->response->contentType('text/html');
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
90 my $hOut = $action->response->streamBody;
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
91 print $hOut $doc->Render();
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
92 } finally {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
93 $doc->Dispose;
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
94 };
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
95 }
c64bd1bf727d Web application
wizard
parents:
diff changeset
96
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
97 1;
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
98
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
99 __END__
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
100
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
101 =pod
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
102
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
103 =head1 NAME
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
104
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
105 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
106
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
107 =head1 SYNOPSIS
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
108
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
109 В файле конфигурации приложения
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
110
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
111 =begin code xml
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
112
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
113 <handlersQuery type="IMPL::Object::List">
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
114 <item type="IMPL::Web::QueryHandler::PageFormat">
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
115 <charsetTemplates>utf-8</charsetTemplates>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
116 </item>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
117 </handlersQuery>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
118
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
119 =end code xml
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
120
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
121 Программно
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
122
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
123 =begin code
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
124
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
125 my $app = new IMPL::Web::Application();
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
126 $app->handlersQuery->Add(
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
127 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' );
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
128 );
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
129
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
130 =end
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
131
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
132 =head1 DESCRIPTION
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
133
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
134 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
135 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
136
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
137 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
138 обработчика запроса и переопределяет метод C<Process>.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
139
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
140 C<Serializable>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
141
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
142 =head1 MEMBERS
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
143
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
144 =over
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
145
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
146 =item C<CTOR(%props)>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
147
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
148 Создает новый экземпляр и заполняет свойства.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
149
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
150 =item C<[get,set] templatesCharset>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
151
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
152 Кодировка шаблонов. По умолчанию utf-8.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
153
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
154 =item C<[get,set] templatesBase>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
155
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
156 Каталог относительно которого ищется шаблон.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
157
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
158 =item C<[override] Process($action,$nextHandler)>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
159
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
160 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
161 для выполнения действий.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
162
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
163 =back
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
164
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
165 =cut