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 includeparse { |
98 |
+ |
my $self=shift; |
99 |
+ |
my $parselabel=shift; |
100 |
+ |
my $remoteparselabel=shift; |
101 |
+ |
my $activedoc=shift; |
102 |
+ |
|
103 |
+ |
# Some error trapping |
104 |
+ |
if ( ! exists $self->{parsers}{$parselabel} ) { |
105 |
+ |
$self->error("Unknown local parse name specified"); |
106 |
+ |
} |
107 |
+ |
if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) { |
108 |
+ |
$self->error("Unknown parse name specified in remote obj $activedoc"); |
109 |
+ |
} |
110 |
+ |
|
111 |
+ |
# |
112 |
+ |
my $rp=$activedoc->{parsers}{$remoteparselabel}; |
113 |
+ |
$self->{parsers}{$parselabel}->includeparse($rp); |
114 |
+ |
} |
115 |
+ |
|
116 |
|
sub addtag { |
117 |
|
my $self=shift; |
118 |
|
my $parselabel=shift; |
162 |
|
|
163 |
|
sub basequery { |
164 |
|
my $self=shift; |
165 |
< |
@_ ? $self->{UserQuery}=shift |
166 |
< |
: $self->{UserQuery}; |
165 |
> |
@_ ? $self->{Query}=shift |
166 |
> |
: $self->{Query}; |
167 |
> |
} |
168 |
> |
|
169 |
> |
sub options { |
170 |
> |
my $self=shift; |
171 |
> |
my $param=shift; |
172 |
> |
$self->basequery()->getparam('option_'.$param); |
173 |
|
} |
174 |
|
|
175 |
|
sub getfile() { |
198 |
|
return $fileref; |
199 |
|
} |
200 |
|
|
201 |
+ |
sub activatedoc { |
202 |
+ |
my $self=shift; |
203 |
+ |
my $url=shift; |
204 |
+ |
|
205 |
+ |
# first get a preprocessed copy of the file |
206 |
+ |
my $fileob=$self->getfile($url); |
207 |
+ |
|
208 |
+ |
# now parse it for the <DocType> tag |
209 |
+ |
$self->{doctypefound}=0; |
210 |
+ |
$self->newparse("doctype"); |
211 |
+ |
$self->addtag("doctype","Doc", \&Doc_Start, $self, |
212 |
+ |
"", $self, "", $self); |
213 |
+ |
$self->parse("doctype"); |
214 |
+ |
|
215 |
+ |
if ( ! defined $self->{docobject} ) { |
216 |
+ |
print "No <Doc type=> Specified in ".$fileob->url()."\n"; |
217 |
+ |
exit 1; |
218 |
+ |
} |
219 |
+ |
# Set up a new object of the specified type |
220 |
+ |
my $newobj=$self->{docobject}->new($self->config()); |
221 |
+ |
$newobj->url($url); |
222 |
+ |
return $newobj; |
223 |
+ |
} |
224 |
+ |
|
225 |
|
# -------- Error Handling and Error services -------------- |
226 |
|
|
227 |
|
sub error { |
255 |
|
|
256 |
|
sub line { |
257 |
|
my $self=shift; |
258 |
+ |
|
259 |
|
my ($line, $fileobj)= |
260 |
< |
$self->{File}->line($self->{currentparser}->line()); |
260 |
> |
$self->{File}->realline($self->{currentparser}->line()); |
261 |
|
return ($line, $fileobj); |
262 |
|
} |
263 |
|
|
314 |
|
$self->{urlhandler}->unsetbase($type); |
315 |
|
} |
316 |
|
} |
317 |
+ |
|
318 |
+ |
sub Doc_Start { |
319 |
+ |
my $self=shift; |
320 |
+ |
my $name=shift; |
321 |
+ |
my $hashref=shift; |
322 |
+ |
|
323 |
+ |
$self->checktag($name, $hashref, "type"); |
324 |
+ |
$self->{doctypefound}++; |
325 |
+ |
if ( $self->{doctypefound} == 1 ) { # only take first doctype |
326 |
+ |
$self->{docobject}=$$hashref{'type'}; |
327 |
+ |
} |
328 |
+ |
} |
329 |
+ |
|
330 |
+ |
sub userinterface { |
331 |
+ |
my $self=shift; |
332 |
+ |
@_?$self->{userinterface}=shift |
333 |
+ |
:$self->{userinterface} |
334 |
+ |
} |