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.6 by williamc, Fri Nov 19 15:27:46 1999 UTC vs.
Revision 1.12 by williamc, Fri Jan 14 18:01:03 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   # 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
# Line 33 | Line 41 | require 5.004;
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;
# Line 47 | Line 55 | sub new {
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   }
# Line 57 | Line 67 | sub parse {
67          $parselabel=shift;
68  
69          my $file=$self->file();
60        print "Parse called on file $file\n";
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;
# Line 75 | Line 94 | sub newparse {
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;
# Line 96 | Line 134 | sub addurltags {
134  
135   sub url {
136          my $self=shift;
137 <        @_ ?$self->{File}=$self->getfile(shift)
138 <            : $self->{File};
137 >        # get file & preprocess
138 >        if ( @_  ) {$self->{File}=$self->getfile(shift)}
139 >        $self->{File}->url();
140   }
141  
142   sub copydocconfig {
# Line 123 | Line 162 | sub config {
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() {
# Line 132 | Line 177 | sub getfile() {
177          my $origurl=shift;
178  
179          my $fileref;
135        print "GETFILE called\n";
180          my ($url, $file)=$self->{urlhandler}->get($origurl);
181          # do we already have an appropriate object?
182 <        #my ($fileref)=$self->config()->find("__preprocessed",$url);
183 <        undef $fileref;
182 >        ($fileref)=$self->config()->find($url);
183 >        #undef $fileref;
184          if (  defined $fileref ) {
185           print "found $url in database ----\n";
186           $fileref->update();
# Line 150 | Line 194 | sub getfile() {
194           $fileref=ActiveDoc::PreProcessedFile->new($self->config());
195           $fileref->url($url);
196           $fileref->update();
153         $self->config()->store($fileref,"__preprocessed",$url);
197          }
155        print "---------- returning".$fileref."\n";
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 {
# Line 188 | Line 254 | sub checktag {
254   }
255  
256   sub line {
257 <        $self=shift;
257 >        my $self=shift;
258 >
259          my ($line, $fileobj)=
260 <                $self->{Processedfile}->line($self->{switch}->line());
260 >                $self->{File}->realline($self->{currentparser}->line());
261          return ($line, $fileobj);
262   }
263  
264 + sub tagstartline {
265 +        my $self=shift;
266 +        my ($line, $fileobj)=$self->{File}->line(
267 +                $self->{currentparser}->tagstartline());
268 +        return ($line, $fileobj);
269 + }
270 +
271   sub file {
272          my $self=shift;
273  
274 <        $self->{PPf}->file();
274 >        $self->{File}->file();
275   }
276  
277   # --------------- Initialisation Methods ---------------------------
278  
205 sub preprocess_init {
206        my $self=shift;
207        $self->{PPfile}=PreProcessedFile->new($self->config());
208 }
209
279   sub init {
280          # Dummy Routine - override for derived classes
281   }
# Line 245 | Line 314 | sub Base_end {
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 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines