Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 127:0dce0470a3d8
In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
added a relativeUrl function for a usage from a templates
IMPL::Web::TT::Form now fully functional
author | wizard |
---|---|
date | Fri, 11 Jun 2010 20:21:07 +0400 |
parents | 92c850d0bdb9 |
children | e4f15cbc3f1a |
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->() ); |
116 | 49 $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
|
50 $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } ); |
97 | 51 { |
52 local $@; | |
116 | 53 $doc->AddVar( user => IMPL::Security::Context->current->principal ); |
54 $doc->AddVar( session => IMPL::Security::Context->current ); | |
97 | 55 warn $@ if $@; |
56 } | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
57 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
58 $action->response->contentType('text/html'); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
59 my $hOut = $action->response->streamBody; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
60 print $hOut $doc->Render(); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
61 } finally { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
62 $doc->Dispose; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
63 }; |
62 | 64 } |
65 | |
65 | 66 1; |
67 | |
68 __END__ | |
69 | |
70 =pod | |
71 | |
72 =head1 NAME | |
73 | |
74 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона. | |
75 | |
76 =head1 SYNOPSIS | |
77 | |
78 В файле конфигурации приложения | |
79 | |
80 =begin code xml | |
81 | |
82 <handlersQuery type="IMPL::Object::List"> | |
83 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
84 <charsetTemplates>utf-8</charsetTemplates> | |
85 </item> | |
86 </handlersQuery> | |
87 | |
88 =end code xml | |
89 | |
90 Программно | |
91 | |
92 =begin code | |
93 | |
94 my $app = new IMPL::Web::Application(); | |
95 $app->handlersQuery->Add( | |
96 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' ); | |
97 ); | |
98 | |
99 =end | |
100 | |
101 =head1 DESCRIPTION | |
102 | |
103 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется | |
104 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>. | |
105 | |
106 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала | |
107 обработчика запроса и переопределяет метод C<Process>. | |
108 | |
109 C<Serializable> | |
110 | |
111 =head1 MEMBERS | |
112 | |
113 =over | |
114 | |
115 =item C<CTOR(%props)> | |
116 | |
117 Создает новый экземпляр и заполняет свойства. | |
118 | |
119 =item C<[get,set] templatesCharset> | |
120 | |
121 Кодировка шаблонов. По умолчанию utf-8. | |
122 | |
123 =item C<[get,set] templatesBase> | |
124 | |
125 Каталог относительно которого ищется шаблон. | |
126 | |
127 =item C<[override] Process($action,$nextHandler)> | |
128 | |
129 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление | |
130 для выполнения действий. | |
131 | |
132 =back | |
133 | |
134 =cut |