ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm
Revision: 1.9
Committed: Mon Nov 29 17:32:14 1999 UTC (25 years, 5 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.8: +38 -1 lines
Log Message:
activatdoc tested basic-level

File Contents

# Content
1 #
2 # ActiveDoc.pm
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 #
8 # Interface
9 # ---------
10 # new() : A new ActiveDoc object
11 # url() : Return/set the docs url - essential
12 # file() : Return the local filename of document
13 #
14 # 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 # newdoc(file) : Return an new object of the appropriate type
21 # getfile(url) : get a processedfile object given a url
22 # activatedoc(url) : Return the object ref for a doc described by the given url
23 # config([ActiveConfig]) : Set up/return Configuration for the document
24 # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
25 # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
26 # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
27 #
28 # -- error methods --
29 # error(string) : Report an general error to the user
30 # parseerror(string) : Report an error during parsing a file
31 # line() : Return the current line number of the document
32 # and the ProcessedFileObj it is in
33
34 package ActiveDoc::ActiveDoc;
35 require 5.004;
36 use ActiveDoc::Parse;
37 use ActiveDoc::ActiveConfig;
38 use ActiveDoc::PreProcessedFile;
39 use ObjectUtilities::ObjectBase;
40 use URL::URLhandler;
41
42 @ISA = qw(ObjectUtilities::ObjectBase);
43
44 sub new {
45 my $class=shift;
46 $self={};
47 bless $self, $class;
48 $self->config(shift);
49
50 # A URL handler per document
51 $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
52
53 $self->init(@_);
54 return $self;
55 }
56
57 # ----- parse related routines --------------
58 sub parse {
59 my $self=shift;
60 $parselabel=shift;
61
62 my $file=$self->file();
63 if ( $file ) {
64 $self->{currentparser}=$self->{parsers}{$parselabel};
65 $self->{parsers}{$parselabel}->parse($file,@_);
66 delete $self->{currentparser};
67 }
68 else {
69 print "Cannot parse - file not known\n";
70 }
71 }
72
73 sub newparse {
74 my $self=shift;
75 my $parselabel=shift;
76
77 $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
78 $self->{parsers}{$parselabel}->addignoretags();
79 $self->{parsers}{$parselabel}->addgrouptags();
80 }
81
82 sub addtag {
83 my $self=shift;
84 my $parselabel=shift;
85 if ( $#_ != 6 ) {
86 $self->error("Incorrect addtags specification\n".
87 "called with :\n@_ \n");
88 }
89 $self->{parsers}{$parselabel}->addtag(@_);
90 }
91
92 sub addurltags {
93 my $self=shift;
94 my $parselabel=shift;
95
96 $self->{parsers}{$parselabel}->
97 addtag("Base", \&Base_start, $self, "", $self,
98 \&Base_end, $self);
99 }
100
101 sub url {
102 my $self=shift;
103 # get file & preprocess
104 if ( @_ ) {$self->{File}=$self->getfile(shift)}
105 $self->{File}->url();
106 }
107
108 sub copydocconfig {
109 my $self=shift;
110 my $ActiveDoc=shift;
111
112 $self->config($ActiveDoc->config());
113
114 }
115
116 sub copydocquery {
117 my $self=shift;
118 my $ActiveDoc=shift;
119
120 $self->basequery($ActiveDoc->basequery());
121 }
122
123 sub config {
124 my $self=shift;
125 @_?$self->{ActiveConfig}=shift
126 : $self->{ActiveConfig};
127 }
128
129 sub basequery {
130 my $self=shift;
131 @_ ? $self->{UserQuery}=shift
132 : $self->{UserQuery};
133 }
134
135 sub getfile() {
136 my $self=shift;
137 my $origurl=shift;
138
139 my $fileref;
140 my ($url, $file)=$self->{urlhandler}->get($origurl);
141 # do we already have an appropriate object?
142 ($fileref)=$self->config()->find($url);
143 #undef $fileref;
144 if ( defined $fileref ) {
145 print "found $url in database ----\n";
146 $fileref->update();
147 }
148 else {
149 if ( $file eq "" ) {
150 $self->parseerror("Unable to get $origurl");
151 }
152 #-- set up a new preprocess file
153 print "Making a new file $url----\n";
154 $fileref=ActiveDoc::PreProcessedFile->new($self->config());
155 $fileref->url($url);
156 $fileref->update();
157 }
158 return $fileref;
159 }
160
161 sub activatedoc {
162 my $self=shift;
163 my $url=shift;
164
165 # first get a preprocessed copy of the file
166 my $fileob=$self->getfile($url);
167
168 # now parse it for the <DocType> tag
169 $self->newparse("doctype");
170 $self->addtag("doctype","Doc", \&Doc_Start, $self,
171 "", $self, "", $self);
172 $self->parse("doctype");
173
174 if ( ! defined $self->{docobject} ) {
175 print "No <Doc type=> Specified in ".$fileob->url()."\n";
176 exit 1;
177 }
178 # Set up a new object of the specified type
179 my $newobj=$self->{docobject}->new($self->config());
180 return $newobj;
181 }
182
183 # -------- Error Handling and Error services --------------
184
185 sub error {
186 my $self=shift;
187 my $string=shift;
188
189 die $string."\n";
190 }
191
192 sub parseerror {
193 my $self=shift;
194 my $string=shift;
195
196 ($line, $file)=$self->line();
197 print "Parse Error in ".$file->url().", line ".
198 $line."\n";
199 print $string."\n";
200 die;
201 }
202
203 sub checktag {
204 my $self=shift;
205 my $tagname=shift;
206 my $hashref=shift;
207 my $param=shift;
208
209 print keys %$hashref;
210 print "-----------------------------------\n";
211 if ( ! exists $$hashref{$param} ) {
212 $self->parseerror("Incomplete Tag <$tagname> : $param required");
213 }
214 }
215
216 sub line {
217 my $self=shift;
218
219 my ($line, $fileobj)=
220 $self->{File}->realline($self->{currentparser}->line());
221 return ($line, $fileobj);
222 }
223
224 sub tagstartline {
225 my $self=shift;
226 my ($line, $fileobj)=$self->{File}->line(
227 $self->{currentparser}->tagstartline());
228 return ($line, $fileobj);
229 }
230
231 sub file {
232 my $self=shift;
233
234 $self->{File}->file();
235 }
236
237 # --------------- Initialisation Methods ---------------------------
238
239 sub init {
240 # Dummy Routine - override for derived classes
241 }
242
243 # ------------------- Tag Routines -----------------------------------
244 #
245 # Base - for setting url bases
246 #
247 sub Base_start {
248 my $self=shift;
249 my $name=shift;
250 my $hashref=shift;
251
252 $self->checktag($name, $hashref, 'type' );
253 $self->checktag($name, $hashref, 'base' );
254
255 # Keep track of base tags
256 push @{$self->{basestack}}, $$hashref{"type"};
257 # Set the base
258 $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
259
260 }
261
262 sub Base_end {
263 my $self=shift;
264 my $name=shift;
265 my $type;
266
267 if ( $#{$self->{basestack}} == -1 ) {
268 print "Parse Error : unmatched </".$name."> on line ".
269 $self->line()."\n";
270 die;
271 }
272 else {
273 $type = pop @{$self->{basestack}};
274 $self->{urlhandler}->unsetbase($type);
275 }
276 }
277
278 sub Doc_Start {
279 my $self=shift;
280 my $name=shift;
281 my $hashref=shift;
282
283 $self->checktag($name, $hashref, "type");
284 $self->{docobject}=$$hashref{'type'};
285 }