7 |
|
# |
8 |
|
# Interface |
9 |
|
# --------- |
10 |
< |
# new() : A new ActiveDoc object |
10 |
> |
# new(ActiveConfig[,options]) : A new ActiveDoc object |
11 |
|
# url() : Return/set the docs url - essential |
12 |
|
# file() : Return the local filename of document |
13 |
|
# |
20 |
|
# includeparse(local_parsename, objparsename, activedoc) : copy the parse from |
21 |
|
# one object to another |
22 |
|
# currentparsename([name]) : get/set current parse name |
23 |
– |
# newdoc(file) : Return an new object of the appropriate type |
23 |
|
# getfile(url) : get a processedfile object given a url |
24 |
|
# activatedoc(url) : Return the object ref for a doc described by the given url |
25 |
+ |
# -- any parse called "init" will also be run |
26 |
|
# config([ActiveConfig]) : Set up/return Configuration for the document |
27 |
|
# basequery([ActiveConfig]) : Set up/return UserQuery for the doc |
28 |
|
# copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc |
29 |
|
# copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc |
30 |
|
# userinterface() : Return the defaullt userinterface |
31 |
< |
# options(var) : return the value of the option var |
31 |
> |
# option(var) : return the value of the option var |
32 |
> |
# requestoption("message") : Ask the user to supply a value for an option |
33 |
> |
# if it dosnt already exist |
34 |
|
# |
35 |
|
# -- error methods -- |
36 |
|
# error(string) : Report an general error to the user |
53 |
|
$self={}; |
54 |
|
bless $self, $class; |
55 |
|
$self->config(shift); |
56 |
< |
|
56 |
> |
|
57 |
> |
# have some override options been passed |
58 |
> |
if ( @_ ) { |
59 |
> |
$self->basequery(shift); |
60 |
> |
} |
61 |
> |
else { |
62 |
> |
# --- is there a starter document? |
63 |
> |
my $basedoc=$self->config()->basedoc(); |
64 |
> |
if ( defined $basedoc ) { |
65 |
> |
$self->copydocquery($basedoc); |
66 |
> |
} |
67 |
> |
else { |
68 |
> |
$self->error("ActiveDoc Error : No base doc found"); |
69 |
> |
} |
70 |
> |
} |
71 |
> |
$self->_init2(); |
72 |
> |
} |
73 |
> |
|
74 |
> |
sub _init2 { |
75 |
> |
|
76 |
> |
my $self=shift; |
77 |
|
# A URL handler per document |
78 |
|
$self->{urlhandler}=URL::URLhandler->new($self->config()->cache()); |
79 |
|
|
81 |
|
$self->{userinterface}=ActiveDoc::SimpleUserInterface->new(); |
82 |
|
$self->init(@_); |
83 |
|
return $self; |
84 |
+ |
|
85 |
|
} |
86 |
|
|
87 |
|
# ----- parse related routines -------------- |
91 |
|
|
92 |
|
my $file=$self->file(); |
93 |
|
if ( $file ) { |
94 |
< |
$self->{currentparsename}=$parselabel; |
95 |
< |
$self->{currentparser}=$self->{parsers}{$parselabel}; |
96 |
< |
$self->{parsers}{$parselabel}->parse($file,@_); |
97 |
< |
delete $self->{currentparser}; |
98 |
< |
$self->{currentparsename}=""; |
94 |
> |
if ( exists $self->{parsers}{$parselabel} ) { |
95 |
> |
$self->{currentparsename}=$parselabel; |
96 |
> |
$self->{currentparser}=$self->{parsers}{$parselabel}; |
97 |
> |
$self->{parsers}{$parselabel}->parse($file,@_); |
98 |
> |
delete $self->{currentparser}; |
99 |
> |
$self->{currentparsename}=""; |
100 |
> |
} |
101 |
|
} |
102 |
|
else { |
103 |
|
print "Cannot parse - file not known\n"; |
184 |
|
my $self=shift; |
185 |
|
my $ActiveDoc=shift; |
186 |
|
|
187 |
< |
$self->basequery($ActiveDoc->basequery()); |
187 |
> |
if ( defined $ActiveDoc->basequery() ) { |
188 |
> |
$self->basequery($ActiveDoc->basequery()); |
189 |
> |
} |
190 |
> |
else { |
191 |
> |
$self->error("Cannot copy basequery - undefined"); |
192 |
> |
} |
193 |
|
} |
194 |
|
|
195 |
|
sub config { |
202 |
|
my $self=shift; |
203 |
|
@_ ? $self->{Query}=shift |
204 |
|
: $self->{Query}; |
205 |
+ |
return $self->{Query}; |
206 |
|
} |
207 |
|
|
208 |
< |
sub options { |
208 |
> |
sub option { |
209 |
|
my $self=shift; |
210 |
|
my $param=shift; |
211 |
< |
$self->basequery()->getparam('option_'.$param); |
211 |
> |
if ( defined $self->basequery()) { |
212 |
> |
return $self->basequery()->getparam($param); |
213 |
> |
} |
214 |
> |
else { |
215 |
> |
return $undef; |
216 |
> |
} |
217 |
> |
} |
218 |
> |
|
219 |
> |
sub requestoption { |
220 |
> |
my $self=shift; |
221 |
> |
my $param=shift; |
222 |
> |
my $string=shift; |
223 |
> |
|
224 |
> |
my $par=undef; |
225 |
> |
if ( defined $self->basequery()) { |
226 |
> |
$par=$self->basequery()->getparam($param); |
227 |
> |
while ( ! defined $par ) { |
228 |
> |
$self->basequery()->querytype( $param, "basic"); |
229 |
> |
$self->basequery()->querymessage( $param, $string); |
230 |
> |
$self->userinterface()->askuser($self->basequery()); |
231 |
> |
$par=$self->basequery()->getparam($param); |
232 |
> |
} |
233 |
> |
} |
234 |
> |
return $par; |
235 |
|
} |
236 |
|
|
237 |
|
sub getfile() { |
265 |
|
my $url=shift; |
266 |
|
|
267 |
|
# first get a preprocessed copy of the file |
268 |
< |
my $fileob=$self->getfile($url); |
268 |
> |
# my $fileob=$self->getfile($url); |
269 |
|
|
270 |
|
# now parse it for the <DocType> tag |
271 |
< |
$self->{doctypefound}=0; |
272 |
< |
$self->newparse("doctype"); |
273 |
< |
$self->addtag("doctype","Doc", \&Doc_Start, $self, |
274 |
< |
"", $self, "", $self); |
275 |
< |
$self->parse("doctype"); |
271 |
> |
my $tempdoc=ActiveDoc::ActiveDoc->new($self->config()); |
272 |
> |
$tempdoc->{urlhandler}=$self->{urlhandler}; |
273 |
> |
my $fullurl=$tempdoc->url($url); |
274 |
> |
$url=$fullurl; |
275 |
> |
$tempdoc->{doctypefound}=0; |
276 |
> |
$tempdoc->newparse("doctype"); |
277 |
> |
$tempdoc->addtag("doctype","Doc", \&Doc_Start, $tempdoc, |
278 |
> |
"", $tempdoc, "", $tempdoc); |
279 |
> |
$tempdoc->parse("doctype"); |
280 |
|
|
281 |
< |
if ( ! defined $self->{docobject} ) { |
282 |
< |
print "No <Doc type=> Specified in ".$fileob->url()."\n"; |
281 |
> |
if ( ! defined $tempdoc->{docobject} ) { |
282 |
> |
print "No <Doc type=> Specified in ".$url."\n"; |
283 |
|
exit 1; |
284 |
|
} |
285 |
|
# Set up a new object of the specified type |
286 |
< |
my $newobj=$self->{docobject}->new($self->config()); |
286 |
> |
eval "require $tempdoc->{docobject}"; |
287 |
> |
die $@ if $@; |
288 |
> |
my $newobj=$tempdoc->{docobject}->new($self->config()); |
289 |
> |
undef $tempdoc; |
290 |
|
$newobj->url($url); |
291 |
+ |
$newobj->_initparse(); |
292 |
|
return $newobj; |
293 |
|
} |
294 |
|
|
295 |
+ |
sub _initparse { |
296 |
+ |
my $self=shift; |
297 |
+ |
|
298 |
+ |
$self->parse("init"); |
299 |
+ |
} |
300 |
|
# -------- Error Handling and Error services -------------- |
301 |
|
|
302 |
|
sub error { |
310 |
|
my $self=shift; |
311 |
|
my $string=shift; |
312 |
|
|
313 |
< |
($line, $file)=$self->line(); |
314 |
< |
print "Parse Error in ".$file->url().", line ". |
313 |
> |
if ( ! defined $self->{currentparse} ) { |
314 |
> |
$self->error($string); |
315 |
> |
} |
316 |
> |
else { |
317 |
> |
($line, $file)=$self->line(); |
318 |
> |
print "Parse Error in ".$file->url().", line ". |
319 |
|
$line."\n"; |
320 |
< |
print $string."\n"; |
321 |
< |
die; |
320 |
> |
print $string."\n"; |
321 |
> |
die; |
322 |
> |
} |
323 |
|
} |
324 |
|
|
325 |
|
sub checktag { |
376 |
|
push @{$self->{basestack}}, $$hashref{"type"}; |
377 |
|
# Set the base |
378 |
|
$self->{urlhandler}->setbase($$hashref{"type"},$hashref); |
307 |
– |
|
379 |
|
} |
380 |
|
|
381 |
|
sub Base_end { |
384 |
|
my $type; |
385 |
|
|
386 |
|
if ( $#{$self->{basestack}} == -1 ) { |
387 |
< |
print "Parse Error : unmatched </".$name."> on line ". |
317 |
< |
$self->line()."\n"; |
318 |
< |
die; |
387 |
> |
$self->parseerror("Parse Error : unmatched </$name>"); |
388 |
|
} |
389 |
|
else { |
390 |
|
$type = pop @{$self->{basestack}}; |