Mercurial > pub > Impl
annotate Lib/IMPL/Web/DOM/FileNode.pm @ 400:ef37ec102dab
redirection support while fetching child resources
author | cin |
---|---|
date | Wed, 14 May 2014 17:27:32 +0400 |
parents | 4d0e1962161c |
children |
rev | line source |
---|---|
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
1 package IMPL::Web::DOM::FileNode; |
167 | 2 use parent qw(IMPL::DOM::Node); |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
3 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
4 __PACKAGE__->PassThroughArgs; |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
5 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
6 use IMPL::Class::Property; |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
7 use File::Temp qw(tempfile); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
8 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
9 BEGIN { |
194 | 10 public property parameterName => { |
11 get => sub { | |
12 my ($this) = @_; | |
13 $this->_parameterName() or | |
14 $this->_parameterName( | |
15 join '/', ( map { | |
16 (defined $_->nodeProperty('instanceId')) ? | |
17 $_->nodeName . '['.$_->nodeProperty('instanceId').']': | |
18 $_->nodeName | |
19 } $this->_selectParents, $this ) | |
20 ); | |
21 } | |
22 }; | |
23 private property _parameterName => prop_all; | |
24 public property fileName => { | |
25 get => sub { | |
26 my ($this) = @_; | |
27 return $this->document->query->param($this->parameterName); | |
28 } | |
29 }; | |
30 public property fileHandle => { | |
31 get => sub { | |
32 my ($this) = @_; | |
33 return $this->document->query->upload($this->parameterName); | |
34 } | |
35 }; | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
36 } |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
37 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
38 sub invokeTempFile { |
194 | 39 my ($this,$sub,$target) = @_; |
40 | |
41 die new IMPL::InvalidArgumentException("A reference to a function should be specified") unless $sub && ref $sub eq 'CODE'; | |
42 | |
43 $target ||= $this; | |
44 | |
45 my $query = $this->document->nodeProperty('query') or die new IMPL::InvalidOperationException("Failed to get a CGI query from the document"); | |
46 my $hFile = $query->upload($this->parameterName) or die new IMPL::IOException("Failed to open the uploaded file",$query->cgi_error,$this->parameterName,$this->nodeProperty('instanceId')); | |
47 | |
48 my ($hTemp,$tempFileName) = tempfile(); | |
49 binmode($hTemp); | |
50 | |
51 print $hTemp $_ while <$hFile>; | |
52 | |
53 $hTemp->flush(); | |
54 seek $hTemp, 0,0; | |
55 { | |
56 local $_ = $tempFileName; | |
57 $sub->($this,$tempFileName,$hTemp); | |
58 } | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
59 } |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
60 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
61 sub _selectParents { |
194 | 62 my ($node) = @_; |
63 | |
64 my @result; | |
65 | |
66 unshift @result, $node while $node = $node->parentNode; | |
67 | |
68 return @result; | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
69 } |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
70 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
71 1; |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
72 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
73 __END__ |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
74 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
75 =pod |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
76 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
77 =head1 NAME |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
78 |
180 | 79 C<IMPL::Web::DOM::FileNode> - узел, использующийся для представления параметра запроса в котором передан файл. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
80 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
81 =head1 SINOPSYS |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
82 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
83 =begin code xml |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
84 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
85 <!-- input.schema.xml --> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
86 <schema> |
194 | 87 <SimpleType type="file" nativeType="IMPL::Web::DOM::FileNode"/> |
88 <ComplexNode name="user"> | |
89 <Node type="file" name="avatar"/> | |
90 </ComplexNode> | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
91 </schema> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
92 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
93 =end code xml |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
94 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
95 =begin code |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
96 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
97 # handle.pl |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
98 use IMPL::DOM::Transform::PostToDOM (); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
99 use IMPL::DOM::Schema; |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
100 use CGI; |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
101 use File::Copy qw(copy); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
102 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
103 my $t = new IMPL::DOM::Transform::PostToDOM( |
194 | 104 undef, |
105 IMPL::DOM::Schema->LoadSchema('input.schema.xml'), | |
106 'user' | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
107 ); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
108 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
109 my $doc = $t->Transform(CGI->new()); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
110 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
111 if ($t->Errors->Count) { |
194 | 112 # handle errors |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
113 } |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
114 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
115 $doc->selectSingleNode('avatar')->invokeTempFile( |
194 | 116 sub { |
117 my($node,$fname,$fhandle) = @_; | |
118 | |
119 # do smth with file | |
120 copy($_,'avatar.jpg'); | |
121 | |
122 # same thing | |
123 # copy($fname,'avatar.jpg'); | |
124 } | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
125 ); |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
126 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
127 =end code |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
128 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
129 =head1 DESCRIPTION |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
130 |
180 | 131 Данный класс используется для представлении параметров C<CGI> запросов при преобзаовании |
132 запроса в ДОМ документ преобразованием C<IMPL::DOM::Transform::PostToDOM>. | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
133 |
180 | 134 Узлы данного типа расширяют стандатрный C<IMPL::DOM::Node> несколькими свойствами и |
135 методами для доступа к файлу, переданному в виде параметра запроса. | |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
136 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
137 =head1 MEMBERS |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
138 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
139 =head2 PROPERTIES |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
140 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
141 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
142 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
143 =item C<[get] parameterName> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
144 |
180 | 145 Имя параметра C<CGI> запроса соответствующего данному узлу. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
146 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
147 =item C<[get] fileName> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
148 |
180 | 149 Имя файла из параметра запроса |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
150 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
151 =item C<[get] fileHandle> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
152 |
180 | 153 Указатель на файл из параметра запроса |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
154 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
155 =back |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
156 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
157 =head2 METHODS |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
158 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
159 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
160 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
161 =item C<invokeTempFile($callback,$target)> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
162 |
180 | 163 Сохраняет файл, переданный в запросе во временный, вызывает C<$callback> для обработки временного файла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
164 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
165 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
166 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
167 =item C<$callback> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
168 |
180 | 169 Ссылка на функцию которая будет вызвана для обработки временного файла. C<callback($target,$fname,$fhandle)> |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
170 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
171 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
172 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
173 =item C<$fname> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
174 |
180 | 175 Имя временного файла |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
176 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
177 =item C<$fhandle> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
178 |
180 | 179 Указатель на временный файл |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
180 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
181 =back |
194 | 182 |
180 | 183 Также пременная C<$_> содержит имя временного файла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
184 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
185 =item C<$target> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
186 |
180 | 187 Значение этого параметра будет передано первым параметром функции C<$callback>. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
188 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
189 =back |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
190 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
191 =back |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
diff
changeset
|
192 |
180 | 193 =cut |