15 |
|
# newparse(parselabel) : Create a new parse type |
16 |
|
# addtag(parselabel,tagname,start,obj,text,obj,end,obj) |
17 |
|
# : Add tags to the parse given by label |
18 |
+ |
# checktag(tagname, hashref, param) : check for existence of param in |
19 |
+ |
# hashref from a tag call |
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 |
24 |
|
# getfile(url) : get a processedfile object given a url |
25 |
+ |
# activatedoc(url) : Return the object ref for a doc described by the given url |
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 |
32 |
|
# |
33 |
|
# -- error methods -- |
34 |
|
# error(string) : Report an general error to the user |
41 |
|
use ActiveDoc::Parse; |
42 |
|
use ActiveDoc::ActiveConfig; |
43 |
|
use ActiveDoc::PreProcessedFile; |
44 |
< |
use ObjectUtilities::ObjectBase; |
44 |
> |
use ObjectUtilities::StorableObject; |
45 |
|
use URL::URLhandler; |
46 |
|
|
47 |
< |
@ISA = qw(ObjectUtilities::ObjectBase); |
47 |
> |
@ISA = qw(ObjectUtilities::StorableObject); |
48 |
|
|
49 |
|
sub new { |
50 |
|
my $class=shift; |
55 |
|
# A URL handler per document |
56 |
|
$self->{urlhandler}=URL::URLhandler->new($self->config()->cache()); |
57 |
|
|
58 |
+ |
# A default UserInterface |
59 |
+ |
$self->{userinterface}=ActiveDoc::SimpleUserInterface->new(); |
60 |
|
$self->init(@_); |
61 |
|
return $self; |
62 |
|
} |
68 |
|
|
69 |
|
my $file=$self->file(); |
70 |
|
if ( $file ) { |
71 |
+ |
$self->{currentparsename}=$parselabel; |
72 |
|
$self->{currentparser}=$self->{parsers}{$parselabel}; |
73 |
|
$self->{parsers}{$parselabel}->parse($file,@_); |
74 |
|
delete $self->{currentparser}; |
75 |
+ |
$self->{currentparsename}=""; |
76 |
|
} |
77 |
|
else { |
78 |
|
print "Cannot parse - file not known\n"; |
79 |
|
} |
80 |
|
} |
81 |
|
|
82 |
+ |
sub currentparsename { |
83 |
+ |
my $self=shift; |
84 |
+ |
@_?$self->{currentparsename}=shift |
85 |
+ |
:$self->{currentparsename}; |
86 |
+ |
} |
87 |
+ |
|
88 |
|
sub newparse { |
89 |
|
my $self=shift; |
90 |
|
my $parselabel=shift; |
94 |
|
$self->{parsers}{$parselabel}->addgrouptags(); |
95 |
|
} |
96 |
|
|
97 |
+ |
sub cleartags { |
98 |
+ |
my $self=shift; |
99 |
+ |
my $parselabel=shift; |
100 |
+ |
|
101 |
+ |
$self->{parsers}{$parselabel}->cleartags(); |
102 |
+ |
} |
103 |
+ |
|
104 |
+ |
|
105 |
+ |
sub includeparse { |
106 |
+ |
my $self=shift; |
107 |
+ |
my $parselabel=shift; |
108 |
+ |
my $remoteparselabel=shift; |
109 |
+ |
my $activedoc=shift; |
110 |
+ |
|
111 |
+ |
# Some error trapping |
112 |
+ |
if ( ! exists $self->{parsers}{$parselabel} ) { |
113 |
+ |
$self->error("Unknown local parse name specified"); |
114 |
+ |
} |
115 |
+ |
if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) { |
116 |
+ |
$self->error("Unknown parse name specified in remote obj $activedoc"); |
117 |
+ |
} |
118 |
+ |
|
119 |
+ |
# |
120 |
+ |
my $rp=$activedoc->{parsers}{$remoteparselabel}; |
121 |
+ |
$self->{parsers}{$parselabel}->includeparse($rp); |
122 |
+ |
} |
123 |
+ |
|
124 |
|
sub addtag { |
125 |
|
my $self=shift; |
126 |
|
my $parselabel=shift; |
142 |
|
|
143 |
|
sub url { |
144 |
|
my $self=shift; |
145 |
< |
@_ ?$self->{File}=$self->getfile(shift) |
146 |
< |
: $self->{File}; |
145 |
> |
# get file & preprocess |
146 |
> |
if ( @_ ) {$self->{File}=$self->getfile(shift)} |
147 |
> |
$self->{File}->url(); |
148 |
|
} |
149 |
|
|
150 |
|
sub copydocconfig { |
170 |
|
|
171 |
|
sub basequery { |
172 |
|
my $self=shift; |
173 |
< |
@_ ? $self->{UserQuery}=shift |
174 |
< |
: $self->{UserQuery}; |
173 |
> |
@_ ? $self->{Query}=shift |
174 |
> |
: $self->{Query}; |
175 |
> |
} |
176 |
> |
|
177 |
> |
sub options { |
178 |
> |
my $self=shift; |
179 |
> |
my $param=shift; |
180 |
> |
$self->basequery()->getparam('option_'.$param); |
181 |
|
} |
182 |
|
|
183 |
|
sub getfile() { |
206 |
|
return $fileref; |
207 |
|
} |
208 |
|
|
209 |
+ |
sub activatedoc { |
210 |
+ |
my $self=shift; |
211 |
+ |
my $url=shift; |
212 |
+ |
|
213 |
+ |
# first get a preprocessed copy of the file |
214 |
+ |
my $fileob=$self->getfile($url); |
215 |
+ |
|
216 |
+ |
# now parse it for the <DocType> tag |
217 |
+ |
$self->{doctypefound}=0; |
218 |
+ |
$self->newparse("doctype"); |
219 |
+ |
$self->addtag("doctype","Doc", \&Doc_Start, $self, |
220 |
+ |
"", $self, "", $self); |
221 |
+ |
$self->parse("doctype"); |
222 |
+ |
|
223 |
+ |
if ( ! defined $self->{docobject} ) { |
224 |
+ |
print "No <Doc type=> Specified in ".$fileob->url()."\n"; |
225 |
+ |
exit 1; |
226 |
+ |
} |
227 |
+ |
# Set up a new object of the specified type |
228 |
+ |
my $newobj=$self->{docobject}->new($self->config()); |
229 |
+ |
$newobj->url($url); |
230 |
+ |
return $newobj; |
231 |
+ |
} |
232 |
+ |
|
233 |
|
# -------- Error Handling and Error services -------------- |
234 |
|
|
235 |
|
sub error { |
263 |
|
|
264 |
|
sub line { |
265 |
|
my $self=shift; |
266 |
+ |
|
267 |
|
my ($line, $fileobj)= |
268 |
< |
$self->{PPfile}->line($self->{currentparser}->line()); |
268 |
> |
$self->{File}->realline($self->{currentparser}->line()); |
269 |
|
return ($line, $fileobj); |
270 |
|
} |
271 |
|
|
272 |
|
sub tagstartline { |
273 |
|
my $self=shift; |
274 |
< |
my ($line, $fileobj)=$self->{PPfile}->line( |
274 |
> |
my ($line, $fileobj)=$self->{File}->line( |
275 |
|
$self->{currentparser}->tagstartline()); |
276 |
|
return ($line, $fileobj); |
277 |
|
} |
279 |
|
sub file { |
280 |
|
my $self=shift; |
281 |
|
|
282 |
< |
$self->{PPf}->file(); |
282 |
> |
$self->{File}->file(); |
283 |
|
} |
284 |
|
|
285 |
|
# --------------- Initialisation Methods --------------------------- |
286 |
|
|
210 |
– |
sub preprocess_init { |
211 |
– |
my $self=shift; |
212 |
– |
$self->{PPfile}=PreProcessedFile->new($self->config()); |
213 |
– |
} |
214 |
– |
|
287 |
|
sub init { |
288 |
|
# Dummy Routine - override for derived classes |
289 |
|
} |
322 |
|
$self->{urlhandler}->unsetbase($type); |
323 |
|
} |
324 |
|
} |
325 |
+ |
|
326 |
+ |
sub Doc_Start { |
327 |
+ |
my $self=shift; |
328 |
+ |
my $name=shift; |
329 |
+ |
my $hashref=shift; |
330 |
+ |
|
331 |
+ |
$self->checktag($name, $hashref, "type"); |
332 |
+ |
$self->{doctypefound}++; |
333 |
+ |
if ( $self->{doctypefound} == 1 ) { # only take first doctype |
334 |
+ |
$self->{docobject}=$$hashref{'type'}; |
335 |
+ |
} |
336 |
+ |
} |
337 |
+ |
|
338 |
+ |
sub userinterface { |
339 |
+ |
my $self=shift; |
340 |
+ |
@_?$self->{userinterface}=shift |
341 |
+ |
:$self->{userinterface} |
342 |
+ |
} |