7 |
|
# |
8 |
|
# Interface |
9 |
|
# --------- |
10 |
< |
# new(ActiveConfig[,options]) : A new ActiveDoc object |
10 |
> |
# new() : A new ActiveDoc object |
11 |
> |
# config([ActiveConfig]) : Set up/return Configuration for the document |
12 |
|
# url() : Return/set the docs url - essential |
13 |
|
# file() : Return the local filename of document |
14 |
+ |
# ProcessFile() : Return the filename of PreProcessed document |
15 |
|
# |
16 |
< |
# parse(parselabel): Parse the document file for the given parse level |
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 |
16 |
> |
# parent() : return the object ref of the calling parent |
17 |
|
# getfile(url) : get a processedfile object given a url |
18 |
|
# activatedoc(url) : Return the object ref for a doc described by the given url |
19 |
|
# -- 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 |
20 |
|
# userinterface() : Return the defaullt userinterface |
21 |
|
# option(var) : return the value of the option var ( or undef ) |
32 |
– |
# requestoption("message") : Ask the user to supply a value for an option |
33 |
– |
# if it dosnt already exist |
34 |
– |
# askuser(Query) : send a query object to the userinterface |
35 |
– |
# verbose(string) : Print string in verbosity mode |
22 |
|
# |
23 |
+ |
# addurltags(parse) : add the <base> tags to manage urls to parse |
24 |
|
# -- error methods -- |
25 |
|
# error(string) : Report an general error to the user |
26 |
|
# parseerror(string) : Report an error during parsing a file |
27 |
|
# line() : Return the current line number of the document |
28 |
|
# and the ProcessedFileObj it is in |
29 |
+ |
# |
30 |
|
|
31 |
|
package ActiveDoc::ActiveDoc; |
32 |
|
require 5.004; |
33 |
< |
use ActiveDoc::Parse; |
46 |
< |
use ActiveDoc::ActiveConfig; |
47 |
< |
use ActiveDoc::PreProcessedFile; |
48 |
< |
use ObjectUtilities::StorableObject; |
33 |
> |
use ActiveDoc::SimpleDoc; |
34 |
|
use URL::URLhandler; |
35 |
|
|
36 |
< |
@ISA = qw(ObjectUtilities::StorableObject); |
52 |
< |
|
53 |
< |
sub new { |
54 |
< |
my $class=shift; |
55 |
< |
$self={}; |
56 |
< |
bless $self, $class; |
57 |
< |
$self->config(shift); |
58 |
< |
|
59 |
< |
# have some override options been passed |
60 |
< |
if ( @_ ) { |
61 |
< |
$self->basequery(shift); |
62 |
< |
} |
63 |
< |
else { |
64 |
< |
# --- is there a starter document? |
65 |
< |
my $basedoc=$self->config()->basedoc(); |
66 |
< |
if ( defined $basedoc ) { |
67 |
< |
$self->verbose("Initialising from $basedoc"); |
68 |
< |
$self->copydocquery($basedoc); |
69 |
< |
} |
70 |
< |
else { |
71 |
< |
$self->error("ActiveDoc Error : No base doc found"); |
72 |
< |
} |
73 |
< |
} |
74 |
< |
$self->_init2(); |
75 |
< |
} |
76 |
< |
|
77 |
< |
sub _init2 { |
78 |
< |
|
79 |
< |
my $self=shift; |
80 |
< |
# A URL handler per document |
81 |
< |
$self->{urlhandler}=URL::URLhandler->new($self->config()->cache()); |
82 |
< |
|
83 |
< |
# A default UserInterface |
84 |
< |
$self->{userinterface}=ActiveDoc::SimpleUserInterface->new(); |
85 |
< |
$self->init(@_); |
86 |
< |
return $self; |
87 |
< |
|
88 |
< |
} |
89 |
< |
|
90 |
< |
sub verbose { |
91 |
< |
my $self=shift; |
92 |
< |
my $string=shift; |
93 |
< |
|
94 |
< |
if ( $self->option('verbose_all') || |
95 |
< |
$self->option('verbose_'.ref($self)) ) { |
96 |
< |
print ">".ref($self)." : ".$string."\n"; |
97 |
< |
} |
98 |
< |
} |
99 |
< |
|
100 |
< |
# ----- parse related routines -------------- |
101 |
< |
sub parse { |
102 |
< |
my $self=shift; |
103 |
< |
$parselabel=shift; |
104 |
< |
|
105 |
< |
my $file=$self->file(); |
106 |
< |
if ( $file ) { |
107 |
< |
if ( exists $self->{parsers}{$parselabel} ) { |
108 |
< |
$self->{currentparsename}=$parselabel; |
109 |
< |
$self->{currentparser}=$self->{parsers}{$parselabel}; |
110 |
< |
$self->{parsers}{$parselabel}->parse($file,@_); |
111 |
< |
delete $self->{currentparser}; |
112 |
< |
$self->{currentparsename}=""; |
113 |
< |
} |
114 |
< |
} |
115 |
< |
else { |
116 |
< |
print "Cannot parse - file not known\n"; |
117 |
< |
} |
118 |
< |
} |
119 |
< |
|
120 |
< |
sub currentparsename { |
121 |
< |
my $self=shift; |
122 |
< |
@_?$self->{currentparsename}=shift |
123 |
< |
:$self->{currentparsename}; |
124 |
< |
} |
125 |
< |
|
126 |
< |
sub newparse { |
127 |
< |
my $self=shift; |
128 |
< |
my $parselabel=shift; |
129 |
< |
|
130 |
< |
$self->{parsers}{$parselabel}=ActiveDoc::Parse->new(); |
131 |
< |
$self->{parsers}{$parselabel}->addignoretags(); |
132 |
< |
$self->{parsers}{$parselabel}->addgrouptags(); |
133 |
< |
} |
134 |
< |
|
135 |
< |
sub cleartags { |
136 |
< |
my $self=shift; |
137 |
< |
my $parselabel=shift; |
138 |
< |
|
139 |
< |
$self->{parsers}{$parselabel}->cleartags(); |
140 |
< |
} |
141 |
< |
|
142 |
< |
|
143 |
< |
sub includeparse { |
144 |
< |
my $self=shift; |
145 |
< |
my $parselabel=shift; |
146 |
< |
my $remoteparselabel=shift; |
147 |
< |
my $activedoc=shift; |
148 |
< |
|
149 |
< |
# Some error trapping |
150 |
< |
if ( ! exists $self->{parsers}{$parselabel} ) { |
151 |
< |
$self->error("Unknown local parse name specified"); |
152 |
< |
} |
153 |
< |
if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) { |
154 |
< |
$self->error("Unknown parse name specified in remote obj $activedoc"); |
155 |
< |
} |
156 |
< |
|
157 |
< |
# |
158 |
< |
my $rp=$activedoc->{parsers}{$remoteparselabel}; |
159 |
< |
$self->{parsers}{$parselabel}->includeparse($rp); |
160 |
< |
} |
161 |
< |
|
162 |
< |
sub addtag { |
163 |
< |
my $self=shift; |
164 |
< |
my $parselabel=shift; |
165 |
< |
if ( $#_ != 6 ) { |
166 |
< |
$self->error("Incorrect addtags specification\n". |
167 |
< |
"called with :\n@_ \n"); |
168 |
< |
} |
169 |
< |
$self->{parsers}{$parselabel}->addtag(@_); |
170 |
< |
} |
36 |
> |
@ISA = qw(ActiveDoc::SimpleDoc); |
37 |
|
|
38 |
|
sub addurltags { |
39 |
|
my $self=shift; |
47 |
|
sub url { |
48 |
|
my $self=shift; |
49 |
|
# get file & preprocess |
50 |
< |
if ( @_ ) {$self->{File}=$self->getfile(shift)} |
51 |
< |
$self->{File}->url(); |
52 |
< |
} |
53 |
< |
|
54 |
< |
sub copydocconfig { |
55 |
< |
my $self=shift; |
190 |
< |
my $ActiveDoc=shift; |
191 |
< |
|
192 |
< |
$self->config($ActiveDoc->config()); |
193 |
< |
|
194 |
< |
} |
195 |
< |
|
196 |
< |
sub copydocquery { |
197 |
< |
my $self=shift; |
198 |
< |
my $ActiveDoc=shift; |
199 |
< |
|
200 |
< |
if ( defined $ActiveDoc->basequery() ) { |
201 |
< |
$self->basequery($ActiveDoc->basequery()); |
202 |
< |
} |
203 |
< |
else { |
204 |
< |
$self->error("Cannot copy basequery - undefined"); |
50 |
> |
if ( @_ ) { |
51 |
> |
$self->{File}=$self->getfile(shift); |
52 |
> |
$self->verbose("url downloaded to $self->{File}"); |
53 |
> |
} |
54 |
> |
if ( defined $self->{File} ) { |
55 |
> |
return $self->{File}->url(); |
56 |
|
} |
57 |
+ |
else { return "undefined"; } |
58 |
|
} |
59 |
|
|
60 |
|
sub config { |
63 |
|
: $self->{ActiveConfig}; |
64 |
|
} |
65 |
|
|
66 |
< |
sub basequery { |
215 |
< |
my $self=shift; |
216 |
< |
@_ ? $self->{Query}=shift |
217 |
< |
: $self->{Query}; |
218 |
< |
return $self->{Query}; |
219 |
< |
} |
220 |
< |
|
221 |
< |
sub option { |
222 |
< |
my $self=shift; |
223 |
< |
my $param=shift; |
224 |
< |
if ( defined $self->basequery()) { |
225 |
< |
return $self->basequery()->getparam($param); |
226 |
< |
} |
227 |
< |
else { |
228 |
< |
return $undef; |
229 |
< |
} |
230 |
< |
} |
231 |
< |
|
232 |
< |
sub requestoption { |
233 |
< |
my $self=shift; |
234 |
< |
my $param=shift; |
235 |
< |
my $string=shift; |
236 |
< |
|
237 |
< |
my $par=undef; |
238 |
< |
if ( defined $self->basequery()) { |
239 |
< |
$par=$self->basequery()->getparam($param); |
240 |
< |
while ( ! defined $par ) { |
241 |
< |
$self->basequery()->querytype( $param, "basic"); |
242 |
< |
$self->basequery()->querymessage( $param, $string); |
243 |
< |
$self->userinterface()->askuser($self->basequery()); |
244 |
< |
$par=$self->basequery()->getparam($param); |
245 |
< |
} |
246 |
< |
} |
247 |
< |
return $par; |
248 |
< |
} |
249 |
< |
|
250 |
< |
sub askuser { |
251 |
< |
my $self=shift; |
252 |
< |
return $self->userinterface()->askuser(@_); |
253 |
< |
} |
254 |
< |
|
255 |
< |
sub getfile() { |
66 |
> |
sub getfile { |
67 |
|
my $self=shift; |
68 |
|
my $origurl=shift; |
69 |
|
|
70 |
|
my $fileref; |
71 |
|
my ($url, $file); |
72 |
< |
if ( defined $self->option('url_update') ) { |
73 |
< |
$self->verbose("Forced download of $origurl"); |
74 |
< |
($url, $file)=$self->{urlhandler}->download($origurl); |
72 |
> |
if ( (defined ($it=$self->option('url_update'))) && |
73 |
> |
( $it eq "1" || $origurl=~/^$it/ )) { |
74 |
> |
$self->verbose("Forced download of $origurl"); |
75 |
> |
($url, $file)=$self->{urlhandler}->download($origurl); |
76 |
|
} |
77 |
|
else { |
78 |
+ |
$self->verbose("Attempting to get $origurl"); |
79 |
|
($url, $file)=$self->{urlhandler}->get($origurl); |
80 |
|
} |
81 |
|
# do we already have an appropriate object? |
90 |
|
$self->parseerror("Unable to get $origurl"); |
91 |
|
} |
92 |
|
#-- set up a new preprocess file |
93 |
< |
print "Making a new file $url----\n"; |
93 |
> |
$self->verbose("Making a new preprocessed file $url"); |
94 |
|
$fileref=ActiveDoc::PreProcessedFile->new($self->config()); |
95 |
|
$fileref->url($url); |
96 |
|
$fileref->update(); |
126 |
|
my $newobj=$tempdoc->{docobject}->new($self->config()); |
127 |
|
undef $tempdoc; |
128 |
|
$newobj->url($url); |
129 |
< |
$newobj->_initparse(); |
129 |
> |
$newobj->parent($self); |
130 |
|
return $newobj; |
131 |
|
} |
132 |
|
|
133 |
< |
sub _initparse { |
133 |
> |
sub parent { |
134 |
|
my $self=shift; |
135 |
|
|
136 |
< |
$self->parse("init"); |
136 |
> |
@_?$self->{parent}=shift |
137 |
> |
:$self->{parent}; |
138 |
|
} |
139 |
+ |
|
140 |
|
# -------- Error Handling and Error services -------------- |
141 |
|
|
142 |
|
sub error { |
162 |
|
} |
163 |
|
} |
164 |
|
|
350 |
– |
sub checktag { |
351 |
– |
my $self=shift; |
352 |
– |
my $tagname=shift; |
353 |
– |
my $hashref=shift; |
354 |
– |
my $param=shift; |
355 |
– |
|
356 |
– |
if ( ! exists $$hashref{$param} ) { |
357 |
– |
$self->parseerror("Incomplete Tag <$tagname> : $param required"); |
358 |
– |
} |
359 |
– |
} |
360 |
– |
|
165 |
|
sub line { |
166 |
|
my $self=shift; |
167 |
|
|
183 |
|
$self->{File}->file(); |
184 |
|
} |
185 |
|
|
186 |
+ |
sub ProcessFile { |
187 |
+ |
my $self=shift; |
188 |
+ |
|
189 |
+ |
return $self->{File}->ProcessedFile(); |
190 |
+ |
} |
191 |
+ |
|
192 |
|
# --------------- Initialisation Methods --------------------------- |
193 |
|
|
194 |
|
sub init { |
238 |
|
$self->{docobject}=$$hashref{'type'}; |
239 |
|
} |
240 |
|
} |
431 |
– |
|
432 |
– |
sub userinterface { |
433 |
– |
my $self=shift; |
434 |
– |
@_?$self->{userinterface}=shift |
435 |
– |
:$self->{userinterface} |
436 |
– |
} |