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->{cache}=shift; |
38 |
> |
$self->{dbstore}=shift; |
39 |
> |
$self->{switch}=ActiveDoc::ActiveDoc-> |
40 |
> |
new($self->{cache},$self->{dbstore}); |
41 |
> |
$self->init(); |
42 |
> |
bless $self, $class; |
43 |
> |
return $self; |
44 |
> |
} |
45 |
|
|
46 |
|
sub init { |
47 |
|
my $self=shift; |
48 |
|
$self->{lastsequence}=-1; |
49 |
< |
# Specific Tags |
50 |
< |
$self->newparse("include"); |
51 |
< |
$self->addurltags("include"); |
52 |
< |
$self->addtag("include","Include", \&Include_Start, $self, |
49 |
> |
# -- Specific Tags |
50 |
> |
$self->{switch}->newparse("include"); |
51 |
> |
$self->{switch}->addbasetags("include"); |
52 |
> |
$self->{switch}->addtag("include","include", \&Include_Start, $self, |
53 |
|
"", $self, "", $self); |
54 |
|
} |
55 |
|
|
79 |
|
|
80 |
|
sub line { |
81 |
|
my $self=shift; |
82 |
< |
my $line=$self->{currentparser}->line(); |
82 |
> |
my $line=$self->{switch}->currentparser()->line(); |
83 |
|
return $line, $self; |
84 |
|
} |
85 |
|
|
87 |
|
my $self=shift; |
88 |
|
|
89 |
|
if ( @_ ) { |
90 |
< |
my $url=shift; |
91 |
< |
($self->{url}, $file)=$self->{urlhandler}->get($url); |
92 |
< |
} |
93 |
< |
else { |
77 |
< |
$self->{url}; |
90 |
> |
my $url=shift; |
91 |
> |
($self->{url}, $file)=$self->{switch}->urlget($url); |
92 |
> |
$self->{switch}->filetoparse($file); |
93 |
> |
$self->{switch}->filenameref($self->{url}." ($file)"); |
94 |
|
} |
95 |
+ |
return $self->{url}; |
96 |
|
} |
97 |
|
|
98 |
|
sub ProcessedFile { |
99 |
|
my $self=shift; |
100 |
< |
$self->config()->cache()->file("_preprocess_".$self->url()); |
100 |
> |
$self->{cache}->file("_preprocess_".$self->url()); |
101 |
|
} |
102 |
|
|
103 |
|
sub file { |
104 |
|
my $self=shift; |
105 |
|
|
106 |
< |
my ($url, $file)=$self->{urlhandler}->get($self->url()); |
106 |
> |
my ($url, $file)=$self->{switch}->urlget($self->url()); |
107 |
|
$self->verbose("Getting file ".$self->url()." = $file"); |
108 |
|
return $file; |
109 |
|
} |
123 |
|
@{$self->{updatedfiles}}=(); |
124 |
|
|
125 |
|
# -- check the input file snd output sequence numbers are in sync |
126 |
< |
my $basefilenumber=$self->config()->cache()->updatenumber($self->url()); |
126 |
> |
my $basefilenumber=$self->{cache}->updatenumber($self->url()); |
127 |
|
if ( $basefilenumber != $self->{lastsequence} ) { |
128 |
|
$rv=1; |
129 |
|
} |
134 |
|
$rv=$rv+$fileobj->update(); # make sure it up to date |
135 |
|
|
136 |
|
# -- has it changed since last time we built this object |
137 |
< |
$sn=$self->config()->sequence($fileobj->url()); |
137 |
> |
$sn=$self->{dbstore}->sequence($fileobj->url()); |
138 |
|
if ( $self->{includesdesc}[$i]->lastsequence() != $sn ) { |
139 |
|
$rv++; |
140 |
|
push @{$self->{updatedfiles}},$fileobj->url(); # record for test |
145 |
|
if ( $rv != 0 ) { |
146 |
|
$self->verbose(" Need to Update ".$self->url()); |
147 |
|
# ---- sort out the preprocessed file in the cache |
148 |
< |
my $newfile=$self->config()->cache()->filename($outfile); |
132 |
< |
$self->config()->cache()->store($outfile,$newfile); |
148 |
> |
my $newfile=$self->{cache}->filename($outfile); |
149 |
|
|
150 |
< |
$self->process($self->config()->cache()->file($self->url()),$newfile); |
150 |
> |
$self->process($self->{cache}->file($self->url()),$newfile); |
151 |
> |
$self->{cache}->store($outfile,$newfile); |
152 |
|
$self->{lastsequence}=$basefilenumber; |
153 |
< |
# store self in the objectstore by url |
154 |
< |
$self->config->store($self,$self->url()); |
153 |
> |
# -- store self in the objectstore by url |
154 |
> |
$self->{dbstore}->store($self,$self->url()); |
155 |
|
} |
156 |
|
else { |
157 |
|
$self->verbose("No Need to Update ".$self->url()); |
169 |
|
my $filein=shift; |
170 |
|
my $fileout=shift; |
171 |
|
|
172 |
< |
#-- create a new file in the url cache |
172 |
> |
# -- create a new file in the url cache |
173 |
|
$self->_cleanup(); |
174 |
|
$self->{fileout}=FileHandle->new(); |
175 |
|
$self->{fileout}->open(">".$fileout) or die "Unable to open $newfile\n" |
176 |
|
."$!\n"; |
177 |
|
|
178 |
< |
# turn on the switch streamer |
179 |
< |
$self->parse("include", $self->{fileout}, "include_starttag"); |
178 |
> |
# -- turn on the switch streamer |
179 |
> |
$self->{switch}->parse("include", $self->{fileout}, "include_starttag"); |
180 |
|
|
181 |
|
$self->{fileout}->close(); |
182 |
|
$self->verbose("$fileout Created"); |
188 |
|
|
189 |
|
my $fh=$self->openfile(">".$location); |
190 |
|
|
191 |
< |
# get all include objects to store themselves |
191 |
> |
# -- get all include objects to store themselves |
192 |
|
print $fh $self->{lastsequence}."\n"; |
193 |
|
print $fh ($self->url()?$self->url():""); |
194 |
|
print $fh "\n"; |
207 |
|
|
208 |
|
$self->{lastsequence}=<$fh>; |
209 |
|
chomp $self->{lastsequence}; |
210 |
< |
$self->{url}=<$fh>; |
211 |
< |
chomp $self->{url}; |
210 |
> |
my $url=<$fh>; |
211 |
> |
chomp $url; |
212 |
> |
$self->url($url); |
213 |
|
while ( <$fh> ) { |
214 |
|
if ( $_ eq ">\n") { |
215 |
< |
$inc=IncFile->new(); |
215 |
> |
$inc=ActiveDoc::IncFile->new($self->{dbstore}); |
216 |
|
$inc->restore($fh); |
217 |
|
push @{$self->{includesdesc}}, $inc; |
218 |
|
# resurrect the appropriate object ID |
219 |
< |
push @{$self->{includes}}, $self->getfile($inc->file()); |
219 |
> |
push @{$self->{includes}}, $self->{switch}->getfile($inc->file()); |
220 |
|
} |
221 |
|
} |
222 |
|
$fh->close(); |
232 |
|
} |
233 |
|
|
234 |
|
sub _includefile { |
217 |
– |
use ActiveDoc::IncFile; |
235 |
|
my $self=shift; |
236 |
|
my $fileobj=shift; |
237 |
|
my $startline=shift; |
238 |
|
my $endline=shift; |
239 |
|
my $lines=shift; |
240 |
|
|
241 |
< |
my $obj=IncFile->new(); |
241 |
> |
my $obj=ActiveDoc::IncFile->new(); |
242 |
|
my $url=$fileobj->url(); |
243 |
< |
my $sn=$self->config()->sequence($url); |
243 |
> |
my $sn=$self->{dbstore}->sequence($url); |
244 |
|
$obj->init($url,$startline,$endline,$lines, $sn); |
245 |
|
push @{$self->{includes}}, $fileobj; |
246 |
|
push @{$self->{includesdesc}}, $obj; |
256 |
|
my $name=shift; |
257 |
|
my $hashref=shift; |
258 |
|
|
259 |
< |
$self->checktag( $name,$hashref, "url"); |
259 |
> |
$self->{switch}->checktag( $name,$hashref, "url"); |
260 |
|
print "Including ".$$hashref{'url'}."\n"; |
261 |
< |
my $fileObj=$self->getfile($$hashref{'url'}); |
261 |
> |
my $fileObj=$self->{switch}->getfile($$hashref{'url'}); |
262 |
|
if ( defined $fileObj ) { |
263 |
|
# dump out to our file in construction |
264 |
|
my $fh=FileHandle->new(); |
272 |
|
} |
273 |
|
print {$self->{fileout}} "\n";# always end include with new line |
274 |
|
undef $fh; |
275 |
< |
$self->_includefile($fileObj, $self->{currentparser}->tagstartline(), |
276 |
< |
$self->{currentparser}->line(), $linecount); |
275 |
> |
$self->_includefile($fileObj, |
276 |
> |
$self->{switch}->currentparser()->tagstartline(), |
277 |
> |
$self->{switch}->currentparser()->line(), $linecount); |
278 |
|
} |
279 |
|
} |
280 |
|
|