9 |
|
# |
10 |
|
# Interface |
11 |
|
# --------- |
12 |
< |
# new() : A new PreProcessedFile object |
12 |
> |
# new(cache,dbstore) : A new PreProcessedFile object |
13 |
|
# url([url]) : return the full url. With an argument will take the given |
14 |
|
# url and expand it in the context of the current url base. |
15 |
|
# file() : return the filename corresponding to url of the document |
16 |
|
# ProcessedFile() : return the filename corresponding to processed url |
17 |
|
# of the document |
18 |
|
# realline(number): Return the line and fileobj corresponding to number in |
19 |
< |
# processed file |
20 |
< |
# update() : update the preprocessed file as required. |
21 |
< |
# store(filename) : |
19 |
> |
# processed file |
20 |
> |
# update() : update the preprocessed file as required. |
21 |
> |
# store(filename) : |
22 |
|
# restore(filename) : |
23 |
|
|
24 |
|
package ActiveDoc::PreProcessedFile; |
25 |
|
use ActiveDoc::ActiveDoc; |
26 |
+ |
use ActiveDoc::IncFile; |
27 |
+ |
use Utilities::Verbose; |
28 |
+ |
use ObjectUtilities::StorableObject; |
29 |
|
require 5.004; |
30 |
< |
@ISA=qw(ActiveDoc::ActiveDoc); |
30 |
> |
@ISA=qw(ObjectUtilities::StorableObject Utilities::Verbose); |
31 |
> |
|
32 |
> |
|
33 |
> |
sub new { |
34 |
> |
my $class=shift; |
35 |
> |
my $self={}; |
36 |
> |
bless $self, $class; |
37 |
> |
$self->{dbstore}=shift; |
38 |
> |
$self->cache($self->{dbstore}->cache()); |
39 |
> |
bless $self, $class; |
40 |
> |
return $self; |
41 |
> |
} |
42 |
> |
|
43 |
> |
sub cache { |
44 |
> |
my $self=shift; |
45 |
> |
if ( @_ ) { |
46 |
> |
$self->{cache}=shift; |
47 |
> |
$self->init(); |
48 |
> |
} |
49 |
> |
return $self->{cache}; |
50 |
> |
} |
51 |
|
|
52 |
|
sub init { |
53 |
|
my $self=shift; |
54 |
|
$self->{lastsequence}=-1; |
55 |
< |
# Specific Tags |
56 |
< |
$self->newparse("include"); |
57 |
< |
$self->addurltags("include"); |
58 |
< |
$self->addtag("include","Include", \&Include_Start, $self, |
55 |
> |
$self->{switch}=ActiveDoc::ActiveDoc->new($self->{dbstore}); |
56 |
> |
|
57 |
> |
# -- Specific Tags |
58 |
> |
$self->{switch}->newparse("include"); |
59 |
> |
$self->{switch}->addbasetags("include"); |
60 |
> |
$self->{switch}->addtag("include","include", \&Include_Start, $self, |
61 |
|
"", $self, "", $self); |
62 |
|
} |
63 |
|
|
87 |
|
|
88 |
|
sub line { |
89 |
|
my $self=shift; |
90 |
< |
my $line=$self->{currentparser}->line(); |
90 |
> |
my $line=$self->{switch}->currentparser()->line(); |
91 |
|
return $line, $self; |
92 |
|
} |
93 |
|
|
95 |
|
my $self=shift; |
96 |
|
|
97 |
|
if ( @_ ) { |
98 |
< |
my $url=shift; |
99 |
< |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
100 |
< |
} |
101 |
< |
else { |
77 |
< |
$self->{url}; |
98 |
> |
my $url=shift; |
99 |
> |
($self->{url}, $file)=$self->{switch}->urlget($url); |
100 |
> |
$self->{switch}->filetoparse($file); |
101 |
> |
$self->{switch}->filenameref($self->{url}." ($file)"); |
102 |
|
} |
103 |
+ |
return $self->{url}; |
104 |
|
} |
105 |
|
|
106 |
|
sub ProcessedFile { |
107 |
|
my $self=shift; |
108 |
< |
$self->config()->cache()->file("_preprocess_".$self->url()); |
108 |
> |
$self->{cache}->file("_preprocess_".$self->url()); |
109 |
|
} |
110 |
|
|
111 |
|
sub file { |
112 |
|
my $self=shift; |
113 |
|
|
114 |
< |
my ($url, $file)=$self->{urlhandler}->get($self->url()); |
114 |
> |
my ($url, $file)=$self->{switch}->urlget($self->url()); |
115 |
|
$self->verbose("Getting file ".$self->url()." = $file"); |
116 |
|
return $file; |
117 |
|
} |
131 |
|
@{$self->{updatedfiles}}=(); |
132 |
|
|
133 |
|
# -- check the input file snd output sequence numbers are in sync |
134 |
< |
my $basefilenumber=$self->config()->cache()->updatenumber($self->url()); |
134 |
> |
my $basefilenumber=$self->{cache}->updatenumber($self->url()); |
135 |
|
if ( $basefilenumber != $self->{lastsequence} ) { |
136 |
|
$rv=1; |
137 |
|
} |
142 |
|
$rv=$rv+$fileobj->update(); # make sure it up to date |
143 |
|
|
144 |
|
# -- has it changed since last time we built this object |
145 |
< |
$sn=$self->config()->sequence($fileobj->url()); |
145 |
> |
$sn=$self->{dbstore}->sequence($fileobj->url()); |
146 |
|
if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) { |
147 |
|
$rv++; |
148 |
|
push @{$self->{updatedfiles}},$fileobj->url(); # record for test |
153 |
|
if ( $rv != 0 ) { |
154 |
|
$self->verbose(" Need to Update ".$self->url()); |
155 |
|
# ---- sort out the preprocessed file in the cache |
156 |
< |
my $newfile=$self->config()->cache()->filename($outfile); |
132 |
< |
$self->config()->cache()->store($outfile,$newfile); |
156 |
> |
my $newfile=$self->{cache}->filename($outfile); |
157 |
|
|
158 |
< |
$self->process($self->config()->cache()->file($self->url()),$newfile); |
158 |
> |
$self->process($self->{cache}->file($self->url()),$newfile); |
159 |
> |
$self->{cache}->store($outfile,$newfile); |
160 |
|
$self->{lastsequence}=$basefilenumber; |
161 |
< |
# store self in the objectstore by url |
162 |
< |
$self->config->store($self,$self->url()); |
161 |
> |
# -- store self in the objectstore by url |
162 |
> |
$self->{dbstore}->store($self,$self->url()); |
163 |
|
} |
164 |
|
else { |
165 |
|
$self->verbose("No Need to Update ".$self->url()); |
177 |
|
my $filein=shift; |
178 |
|
my $fileout=shift; |
179 |
|
|
180 |
< |
#-- create a new file in the url cache |
180 |
> |
# -- create a new file in the url cache |
181 |
|
$self->_cleanup(); |
182 |
|
$self->{fileout}=FileHandle->new(); |
183 |
|
$self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n" |
184 |
|
."$!\n"; |
185 |
|
|
186 |
< |
# turn on the switch streamer |
187 |
< |
$self->parse("include", $self->{fileout}, "include_starttag"); |
186 |
> |
# -- turn on the switch streamer |
187 |
> |
$self->{switch}->parse("include", $self->{fileout}, "include_starttag"); |
188 |
|
|
189 |
|
$self->{fileout}->close(); |
190 |
|
$self->verbose("$fileout Created"); |
196 |
|
|
197 |
|
my $fh=$self->openfile(">".$location); |
198 |
|
|
199 |
< |
# get all include objects to store themselves |
199 |
> |
# -- get all include objects to store themselves |
200 |
|
print $fh $self->{lastsequence}."\n"; |
201 |
+ |
print $fh ref($self->cache()).":::".$self->cache()->location()."\n"; |
202 |
|
print $fh ($self->url()?$self->url():""); |
203 |
|
print $fh "\n"; |
204 |
|
foreach $inc ( @{$self->{includesdesc}} ) { |
216 |
|
|
217 |
|
$self->{lastsequence}=<$fh>; |
218 |
|
chomp $self->{lastsequence}; |
219 |
< |
$self->{url}=<$fh>; |
220 |
< |
chomp $self->{url}; |
219 |
> |
# -- recreate the cache |
220 |
> |
my $cacheinfo=<$fh>; |
221 |
> |
chomp $cacheinfo; |
222 |
> |
my ($type,$cachelocation)=split /:::/, $cacheinfo; |
223 |
> |
my $cache=$type->new($cachelocation); |
224 |
> |
$self->cache($cache); |
225 |
> |
|
226 |
> |
my $url=<$fh>; |
227 |
> |
chomp $url; |
228 |
> |
$self->url($url); |
229 |
|
while ( <$fh> ) { |
230 |
|
if ( $_ eq ">\n") { |
231 |
< |
$inc=IncFile->new(); |
231 |
> |
$inc=ActiveDoc::IncFile->new($self->{dbstore}); |
232 |
|
$inc->restore($fh); |
233 |
|
push @{$self->{includesdesc}}, $inc; |
234 |
|
# resurrect the appropriate object ID |
235 |
< |
push @{$self->{includes}}, $self->getfile($inc->file()); |
235 |
> |
push @{$self->{includes}}, $self->{switch}->getfile($inc->file()); |
236 |
|
} |
237 |
|
} |
238 |
|
$fh->close(); |
248 |
|
} |
249 |
|
|
250 |
|
sub _includefile { |
217 |
– |
use ActiveDoc::IncFile; |
251 |
|
my $self=shift; |
252 |
|
my $fileobj=shift; |
253 |
|
my $startline=shift; |
254 |
|
my $endline=shift; |
255 |
|
my $lines=shift; |
256 |
|
|
257 |
< |
my $obj=IncFile->new(); |
257 |
> |
my $obj=ActiveDoc::IncFile->new(); |
258 |
|
my $url=$fileobj->url(); |
259 |
< |
my $sn=$self->config()->sequence($url); |
259 |
> |
my $sn=$self->{dbstore}->sequence($url); |
260 |
|
$obj->init($url,$startline,$endline,$lines, $sn); |
261 |
|
push @{$self->{includes}}, $fileobj; |
262 |
|
push @{$self->{includesdesc}}, $obj; |
272 |
|
my $name=shift; |
273 |
|
my $hashref=shift; |
274 |
|
|
275 |
< |
$self->checktag( $name,$hashref, "url"); |
276 |
< |
print "Including ".$$hashref{'url'}."\n"; |
277 |
< |
my $fileObj=$self->getfile($$hashref{'url'}); |
275 |
> |
$self->{switch}->checktag( $name,$hashref, "url"); |
276 |
> |
$self->verbose("Including ".$$hashref{'url'}); |
277 |
> |
my $fileObj=$self->{switch}->getfile($$hashref{'url'}); |
278 |
|
if ( defined $fileObj ) { |
279 |
|
# dump out to our file in construction |
280 |
|
my $fh=FileHandle->new(); |
288 |
|
} |
289 |
|
print {$self->{fileout}} "\n";# always end include with new line |
290 |
|
undef $fh; |
291 |
< |
$self->_includefile($fileObj, $self->{currentparser}->tagstartline(), |
292 |
< |
$self->{currentparser}->line(), $linecount); |
291 |
> |
$self->_includefile($fileObj, |
292 |
> |
$self->{switch}->currentparser()->tagstartline(), |
293 |
> |
$self->{switch}->currentparser()->line(), $linecount); |
294 |
|
} |
295 |
|
} |
296 |
|
|