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.14 by williamc, Tue Jan 18 18:30:10 2000 UTC

# 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 + # 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 + #                    -- any parse called "init" will also be run
27   # config([ActiveConfig]) : Set up/return Configuration for the document
28   # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
29   # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
30   # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
31 + # userinterface()       : Return the defaullt userinterface
32 + # option(var)           : return the value of the option var
33 + # requestoption("message") : Ask the user to supply a value for an option
34 + #                            if it dosnt already exist
35   #
36   # -- error methods --
37   # error(string)       : Report an general error to the user
# Line 33 | Line 44 | require 5.004;
44   use ActiveDoc::Parse;
45   use ActiveDoc::ActiveConfig;
46   use ActiveDoc::PreProcessedFile;
47 < use ObjectUtilities::ObjectBase;
47 > use ObjectUtilities::StorableObject;
48   use URL::URLhandler;
49  
50 < @ISA = qw(ObjectUtilities::ObjectBase);
50 > @ISA = qw(ObjectUtilities::StorableObject);
51  
52   sub new {
53          my $class=shift;
54          $self={};
55          bless $self, $class;
56          $self->config(shift);
57 <        
57 >
58 >        # --- is there a starter document?
59 >        my $basedoc=$self->config()->basedoc();
60 >        if ( defined $basedoc ) {
61 >          $self->copydocquery($basedoc);
62 >        }
63 >        else {
64 >          $self->error("Error : No base doc found");
65 >        }
66 >        $self->_init2();
67 > }
68 >
69 > sub _init2 {
70 >
71 >        my $self=shift;
72          # A URL handler per document
73          $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
74  
75 +        # A default UserInterface
76 +        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
77          $self->init(@_);
78          return $self;
79 +
80   }
81  
82   # ----- parse related routines --------------
# Line 58 | Line 86 | sub parse {
86  
87          my $file=$self->file();
88          if ( $file ) {
89 <          $self->{currentparser}=$self->{parsers}{$parselabel};
90 <          $self->{parsers}{$parselabel}->parse($file,@_);
91 <          delete $self->{currentparser};
89 >          if ( exists $self->{parsers}{$parselabel} ) {
90 >            $self->{currentparsename}=$parselabel;
91 >            $self->{currentparser}=$self->{parsers}{$parselabel};
92 >            $self->{parsers}{$parselabel}->parse($file,@_);
93 >            delete $self->{currentparser};
94 >            $self->{currentparsename}="";
95 >          }
96          }
97          else {
98            print "Cannot parse - file not known\n";
99          }
100   }
101  
102 + sub currentparsename {
103 +        my $self=shift;
104 +        @_?$self->{currentparsename}=shift
105 +          :$self->{currentparsename};
106 + }
107 +
108   sub newparse {
109          my $self=shift;
110          my $parselabel=shift;
# Line 76 | Line 114 | sub newparse {
114          $self->{parsers}{$parselabel}->addgrouptags();
115   }
116  
117 + sub cleartags {
118 +        my $self=shift;
119 +        my $parselabel=shift;
120 +
121 +        $self->{parsers}{$parselabel}->cleartags();
122 + }
123 +
124 +
125 + sub includeparse {
126 +        my $self=shift;
127 +        my $parselabel=shift;
128 +        my $remoteparselabel=shift;
129 +        my $activedoc=shift;
130 +
131 +        # Some error trapping
132 +        if ( ! exists $self->{parsers}{$parselabel} ) {
133 +          $self->error("Unknown local parse name specified");
134 +        }
135 +        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
136 +          $self->error("Unknown parse name specified in remote obj $activedoc");
137 +        }
138 +
139 +        #
140 +        my $rp=$activedoc->{parsers}{$remoteparselabel};
141 +        $self->{parsers}{$parselabel}->includeparse($rp);
142 + }
143 +
144   sub addtag {
145          my $self=shift;
146          my $parselabel=shift;
# Line 97 | Line 162 | sub addurltags {
162  
163   sub url {
164          my $self=shift;
165 <        @_ ?$self->{File}=$self->getfile(shift)
166 <            : $self->{File};
165 >        # get file & preprocess
166 >        if ( @_  ) {$self->{File}=$self->getfile(shift)}
167 >        $self->{File}->url();
168   }
169  
170   sub copydocconfig {
# Line 113 | Line 179 | sub copydocquery {
179          my $self=shift;
180          my $ActiveDoc=shift;
181  
182 <         $self->basequery($ActiveDoc->basequery());
182 >        $self->basequery($ActiveDoc->basequery());
183   }
184  
185   sub config {
# Line 124 | Line 190 | sub config {
190  
191   sub basequery {
192          my $self=shift;
193 <        @_ ? $self->{UserQuery}=shift
194 <           : $self->{UserQuery};
193 >        @_ ? $self->{Query}=shift
194 >           : $self->{Query};
195 > }
196 >
197 > sub option {
198 >        my $self=shift;
199 >        my $param=shift;
200 >        $self->basequery()->getparam($param);
201 > }
202 >
203 > sub requestoption {
204 >        my $self=shift;
205 >        my $param=shift;
206 >        my $string=shift;
207 >
208 >        my $par=$self->basequery()->getparam($param);
209 >        while ( ! defined $par ) {
210 >          $self->basequery()->querytype( $param, "basic");
211 >          $self->basequery()->querymessage( $param, $string);
212 >          $self->userinterface()->askuser($self->basequery());
213 >          $par=$self->basequery()->getparam('ActiveConfigdir');
214 >        }
215 >        return $par;
216   }
217  
218   sub getfile() {
# Line 154 | Line 241 | sub getfile() {
241          return $fileref;
242   }
243  
244 + sub activatedoc {
245 +        my $self=shift;
246 +        my $url=shift;
247 +
248 +        # first get a preprocessed copy of the file
249 + #       my $fileob=$self->getfile($url);
250 +
251 +        # now parse it for the <DocType> tag
252 +        my $tempdoc=ActiveDoc::ActiveDoc->new($self->config());
253 +        $tempdoc->url($url);
254 +        $tempdoc->{doctypefound}=0;
255 +        $tempdoc->newparse("doctype");
256 +        $tempdoc->addtag("doctype","Doc", \&Doc_Start, $tempdoc,
257 +                                          "", $tempdoc, "", $tempdoc);
258 +        $tempdoc->parse("doctype");
259 +
260 +        if ( ! defined $tempdoc->{docobject} ) {
261 +          print "No <Doc type=> Specified in ".$url."\n";
262 +          exit 1;
263 +        }
264 +        # Set up a new object of the specified type
265 +        eval "require $tempdoc->{docobject}";
266 +        die $@ if $@;
267 +        my $newobj=$tempdoc->{docobject}->new($self->config());
268 +        undef $tempdoc;
269 +        $newobj->url($url);
270 +        $newobj->_initparse();
271 +        return $newobj;
272 + }
273 +
274 + sub _initparse {
275 +        my $self=shift;
276 +
277 +        $self->parse("init");
278 + }
279   # -------- Error Handling and Error services --------------
280  
281   sub error {
# Line 187 | Line 309 | sub checktag {
309  
310   sub line {
311          my $self=shift;
312 +
313          my ($line, $fileobj)=
314 <                $self->{PPfile}->line($self->{currentparser}->line());
314 >                $self->{File}->realline($self->{currentparser}->line());
315          return ($line, $fileobj);
316   }
317  
318   sub tagstartline {
319          my $self=shift;
320 <        my ($line, $fileobj)=$self->{PPfile}->line(
320 >        my ($line, $fileobj)=$self->{File}->line(
321                  $self->{currentparser}->tagstartline());
322          return ($line, $fileobj);
323   }
# Line 202 | Line 325 | sub tagstartline {
325   sub file {
326          my $self=shift;
327  
328 <        $self->{PPf}->file();
328 >        $self->{File}->file();
329   }
330  
331   # --------------- Initialisation Methods ---------------------------
332  
210 sub preprocess_init {
211        my $self=shift;
212        $self->{PPfile}=PreProcessedFile->new($self->config());
213 }
214
333   sub init {
334          # Dummy Routine - override for derived classes
335   }
# Line 250 | Line 368 | sub Base_end {
368            $self->{urlhandler}->unsetbase($type);
369          }
370   }
371 +
372 + sub Doc_Start {
373 +        my $self=shift;
374 +        my $name=shift;
375 +        my $hashref=shift;
376 +        
377 +        $self->checktag($name, $hashref, "type");
378 +        $self->{doctypefound}++;
379 +        if ( $self->{doctypefound} == 1 ) { # only take first doctype
380 +           $self->{docobject}=$$hashref{'type'};
381 +        }
382 + }
383 +
384 + sub userinterface {
385 +        my $self=shift;
386 +        @_?$self->{userinterface}=shift
387 +          :$self->{userinterface}
388 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines