ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm
(Generate patch)

Comparing COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm (file contents):
Revision 1.7 by williamc, Tue Nov 23 17:20:40 1999 UTC vs.
Revision 1.19 by williamc, Thu Jan 27 17:50:38 2000 UTC

# Line 7 | Line 7
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   #
# Line 15 | Line 15
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 < # newdoc(file)  : Return an new object of the appropriate type
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   # 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 + # 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
# Line 33 | Line 43 | require 5.004;
43   use ActiveDoc::Parse;
44   use ActiveDoc::ActiveConfig;
45   use ActiveDoc::PreProcessedFile;
46 < use ObjectUtilities::ObjectBase;
46 > use ObjectUtilities::StorableObject;
47   use URL::URLhandler;
48  
49 < @ISA = qw(ObjectUtilities::ObjectBase);
49 > @ISA = qw(ObjectUtilities::StorableObject);
50  
51   sub new {
52          my $class=shift;
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  
80 +        # A default UserInterface
81 +        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
82          $self->init(@_);
83          return $self;
84 +
85   }
86  
87   # ----- parse related routines --------------
# Line 58 | Line 91 | sub parse {
91  
92          my $file=$self->file();
93          if ( $file ) {
94 <          $self->{currentparser}=$self->{parsers}{$parselabel};
95 <          $self->{parsers}{$parselabel}->parse($file,@_);
96 <          delete $self->{currentparser};
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";
104          }
105   }
106  
107 + sub currentparsename {
108 +        my $self=shift;
109 +        @_?$self->{currentparsename}=shift
110 +          :$self->{currentparsename};
111 + }
112 +
113   sub newparse {
114          my $self=shift;
115          my $parselabel=shift;
# Line 76 | Line 119 | sub newparse {
119          $self->{parsers}{$parselabel}->addgrouptags();
120   }
121  
122 + sub cleartags {
123 +        my $self=shift;
124 +        my $parselabel=shift;
125 +
126 +        $self->{parsers}{$parselabel}->cleartags();
127 + }
128 +
129 +
130 + sub includeparse {
131 +        my $self=shift;
132 +        my $parselabel=shift;
133 +        my $remoteparselabel=shift;
134 +        my $activedoc=shift;
135 +
136 +        # Some error trapping
137 +        if ( ! exists $self->{parsers}{$parselabel} ) {
138 +          $self->error("Unknown local parse name specified");
139 +        }
140 +        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
141 +          $self->error("Unknown parse name specified in remote obj $activedoc");
142 +        }
143 +
144 +        #
145 +        my $rp=$activedoc->{parsers}{$remoteparselabel};
146 +        $self->{parsers}{$parselabel}->includeparse($rp);
147 + }
148 +
149   sub addtag {
150          my $self=shift;
151          my $parselabel=shift;
# Line 97 | Line 167 | sub addurltags {
167  
168   sub url {
169          my $self=shift;
170 <        @_ ?$self->{File}=$self->getfile(shift)
171 <            : $self->{File};
170 >        # get file & preprocess
171 >        if ( @_  ) {$self->{File}=$self->getfile(shift)}
172 >        $self->{File}->url();
173   }
174  
175   sub copydocconfig {
# Line 113 | Line 184 | sub copydocquery {
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 {
# Line 124 | Line 200 | sub config {
200  
201   sub basequery {
202          my $self=shift;
203 <        @_ ? $self->{UserQuery}=shift
204 <           : $self->{UserQuery};
203 >        @_ ? $self->{Query}=shift
204 >           : $self->{Query};
205 >        return $self->{Query};
206 > }
207 >
208 > sub option {
209 >        my $self=shift;
210 >        my $param=shift;
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() {
# Line 154 | Line 260 | sub getfile() {
260          return $fileref;
261   }
262  
263 + sub activatedoc {
264 +        my $self=shift;
265 +        my $url=shift;
266 +
267 +        # first get a preprocessed copy of the file
268 + #       my $fileob=$self->getfile($url);
269 +
270 +        # now parse it for the <DocType> tag
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 $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 +        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 {
# Line 167 | Line 310 | sub parseerror {
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 {
# Line 187 | Line 335 | sub checktag {
335  
336   sub line {
337          my $self=shift;
338 +
339          my ($line, $fileobj)=
340 <                $self->{PPfile}->line($self->{currentparser}->line());
340 >                $self->{File}->realline($self->{currentparser}->line());
341          return ($line, $fileobj);
342   }
343  
344   sub tagstartline {
345          my $self=shift;
346 <        my ($line, $fileobj)=$self->{PPfile}->line(
346 >        my ($line, $fileobj)=$self->{File}->line(
347                  $self->{currentparser}->tagstartline());
348          return ($line, $fileobj);
349   }
# Line 202 | Line 351 | sub tagstartline {
351   sub file {
352          my $self=shift;
353  
354 <        $self->{PPf}->file();
354 >        $self->{File}->file();
355   }
356  
357   # --------------- Initialisation Methods ---------------------------
358  
210 sub preprocess_init {
211        my $self=shift;
212        $self->{PPfile}=PreProcessedFile->new($self->config());
213 }
214
359   sub init {
360          # Dummy Routine - override for derived classes
361   }
# Line 232 | Line 376 | sub Base_start {
376          push @{$self->{basestack}}, $$hashref{"type"};
377          # Set the base
378          $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
235
379   }
380  
381   sub Base_end {
# Line 241 | Line 384 | sub Base_end {
384          my $type;
385  
386          if ( $#{$self->{basestack}} == -1 ) {
387 <                print "Parse Error : unmatched </".$name."> on line ".
245 <                        $self->line()."\n";
246 <                die;
387 >                $self->parseerror("Parse Error : unmatched </$name>");
388          }
389          else {
390            $type = pop @{$self->{basestack}};
391            $self->{urlhandler}->unsetbase($type);
392          }
393   }
394 +
395 + sub Doc_Start {
396 +        my $self=shift;
397 +        my $name=shift;
398 +        my $hashref=shift;
399 +        
400 +        $self->checktag($name, $hashref, "type");
401 +        $self->{doctypefound}++;
402 +        if ( $self->{doctypefound} == 1 ) { # only take first doctype
403 +           $self->{docobject}=$$hashref{'type'};
404 +        }
405 + }
406 +
407 + sub userinterface {
408 +        my $self=shift;
409 +        @_?$self->{userinterface}=shift
410 +          :$self->{userinterface}
411 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines