Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 99:6dd659f6f66c
Minor changes, DOM schema is in development (in the aspect of a forms)
author | wizard |
---|---|
date | Wed, 05 May 2010 17:33:55 +0400 |
parents | 964587c5183c |
children | 0e72ad99eef7 |
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; |
64 | 16 } |
17 | |
18 sub CTOR { | |
19 my ($this) = @_; | |
20 | |
65 | 21 $this->templatesCharset('utf-8') unless $this->templatesCharset; |
64 | 22 } |
23 | |
62 | 24 sub Process { |
25 my ($this,$action,$nextHandler) = @_; | |
26 | |
77 | 27 my $doc = new IMPL::Web::TT::Document(); |
62 | 28 |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
29 try { |
97 | 30 |
31 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase; | |
32 | |
33 my $pathInfo = $ENV{PATH_INFO}; | |
34 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget; | |
35 | |
36 my @path = split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" ); | |
65 | 37 |
77 | 38 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset ); |
97 | 39 $doc->AddVar( result => $nextHandler->() ); |
40 { | |
41 local $@; | |
42 $doc->AddVar( user => eval { IMPL::Security::Context->current->principal; } ); | |
43 $doc->AddVar( session => eval { IMPL::Security::Context->current; } ); | |
44 warn $@ if $@; | |
45 } | |
63
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
46 |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
47 $action->response->contentType('text/html'); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
48 my $hOut = $action->response->streamBody; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
49 print $hOut $doc->Render(); |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
50 } finally { |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
51 $doc->Dispose; |
76b878ad6596
Added serialization support for the IMPL::Object::List
wizard
parents:
62
diff
changeset
|
52 }; |
62 | 53 } |
54 | |
65 | 55 1; |
56 | |
57 __END__ | |
58 | |
59 =pod | |
60 | |
61 =head1 NAME | |
62 | |
63 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона. | |
64 | |
65 =head1 SYNOPSIS | |
66 | |
67 В файле конфигурации приложения | |
68 | |
69 =begin code xml | |
70 | |
71 <handlersQuery type="IMPL::Object::List"> | |
72 <item type="IMPL::Web::QueryHandler::PageFormat"> | |
73 <charsetTemplates>utf-8</charsetTemplates> | |
74 </item> | |
75 </handlersQuery> | |
76 | |
77 =end code xml | |
78 | |
79 Программно | |
80 | |
81 =begin code | |
82 | |
83 my $app = new IMPL::Web::Application(); | |
84 $app->handlersQuery->Add( | |
85 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' ); | |
86 ); | |
87 | |
88 =end | |
89 | |
90 =head1 DESCRIPTION | |
91 | |
92 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется | |
93 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>. | |
94 | |
95 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала | |
96 обработчика запроса и переопределяет метод C<Process>. | |
97 | |
98 C<Serializable> | |
99 | |
100 =head1 MEMBERS | |
101 | |
102 =over | |
103 | |
104 =item C<CTOR(%props)> | |
105 | |
106 Создает новый экземпляр и заполняет свойства. | |
107 | |
108 =item C<[get,set] templatesCharset> | |
109 | |
110 Кодировка шаблонов. По умолчанию utf-8. | |
111 | |
112 =item C<[get,set] templatesBase> | |
113 | |
114 Каталог относительно которого ищется шаблон. | |
115 | |
116 =item C<[override] Process($action,$nextHandler)> | |
117 | |
118 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление | |
119 для выполнения действий. | |
120 | |
121 =back | |
122 | |
123 =cut |