Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 130:06a34c197b05
Added support for utf-8 and old versions of CGI module
author | wizard |
---|---|
date | Wed, 16 Jun 2010 01:50:56 +0400 |
parents | e4f15cbc3f1a |
children | 44977efed303 |
rev | line source |
---|---|
62 | 1 package IMPL::Web::QueryHandler::PageFormat; |
64 | 2 use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill); |
62 | 3 |
4 __PACKAGE__->PassThroughArgs; | |
5 | |
6 use IMPL::Class::Property; | |
77 | 7 use IMPL::Web::TT::Document; |
97 | 8 use IMPL::Security::Context; |
65 | 9 use File::Spec; |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
10 use Error qw(:try); |
62 | 11 |
64 | 12 BEGIN { |
65 | 13 public property templatesCharset => prop_all; |
14 public property templatesBase => prop_all; | |
97 | 15 public property defaultTarget => prop_all; |
116 | 16 public property pathinfoPrefix => prop_all; |
64 | 17 } |
18 | |
19 sub CTOR { | |
20 my ($this) = @_; | |
21 | |
65 | 22 $this->templatesCharset('utf-8') unless $this->templatesCharset; |
64 | 23 } |
24 | |
62 | 25 sub Process { |
26 my ($this,$action,$nextHandler) = @_; | |
27 | |
77 | 28 my $doc = new IMPL::Web::TT::Document(); |
62 | 29 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
30 try { |
97 | 31 |
32 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; | |
33 | |
34 my $pathInfo = $ENV{PATH_INFO}; | |
116 | 35 my $prefixRoot = ""; |
36 if (my $rx = $this->pathinfoPrefix) { | |
37 $pathInfo =~ s/($rx)//; | |
38 $prefixRoot = $1 if $1; | |
39 } | |
40 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; | |
97 | 41 |
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
|
42 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
|
43 |
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
|
44 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
|
45 pop @pathContainer; |
65 | 46 |
121 | 47 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase ); |
97 | 48 $doc->AddVar( result => $nextHandler->() ); |
129 | 49 $doc->AddVar( app => $action->application ); |
116 | 50 $doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } ); |
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
|
51 $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } ); |
97 | 52 { |
53 local $@; | |
116 | 54 $doc->AddVar( user => IMPL::Security::Context->current->principal ); |
55 $doc->AddVar( session => IMPL::Security::Context->current ); | |
97 | 56 warn $@ if $@; |
57 } | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
58 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
59 $action->response->contentType('text/html'); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
60 my $hOut = $action->response->streamBody; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
61 print $hOut $doc->Render(); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
62 } finally { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
63 $doc->Dispose; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
64 }; |
62 | 65 } |
66 | |
65 | 67 1; |
68 | |
69 __END__ | |
70 | |
71 =pod | |
72 | |
73 =head1 NAME | |
74 | |
75 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона. | |
76 | |
77 =head1 SYNOPSIS | |
78 | |
79 В файле конфигурации приложения | |
80 | |
81 =begin code xml | |
82 | |
83 <handlersQuery type="IMPL::Object::List"> | |
84 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
85 <charsetTemplates>utf-8</charsetTemplates> | |
86 </item> | |
87 </handlersQuery> | |
88 | |
89 =end code xml | |
90 | |
91 Программно | |
92 | |
93 =begin code | |
94 | |
95 my $app = new IMPL::Web::Application(); | |
96 $app->handlersQuery->Add( | |
97 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' ); | |
98 ); | |
99 | |
100 =end | |
101 | |
102 =head1 DESCRIPTION | |
103 | |
104 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется | |
105 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>. | |
106 | |
107 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала | |
108 обработчика запроса и переопределяет метод C<Process>. | |
109 | |
110 C<Serializable> | |
111 | |
112 =head1 MEMBERS | |
113 | |
114 =over | |
115 | |
116 =item C<CTOR(%props)> | |
117 | |
118 Создает новый экземпляр и заполняет свойства. | |
119 | |
120 =item C<[get,set] templatesCharset> | |
121 | |
122 Кодировка шаблонов. По умолчанию utf-8. | |
123 | |
124 =item C<[get,set] templatesBase> | |
125 | |
126 Каталог относительно которого ищется шаблон. | |
127 | |
128 =item C<[override] Process($action,$nextHandler)> | |
129 | |
130 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление | |
131 для выполнения действий. | |
132 | |
133 =back | |
134 | |
135 =cut |