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.3 by williamc, Thu Sep 23 10:35:41 1999 UTC vs.
Revision 1.9 by williamc, Mon Nov 29 17:32:14 1999 UTC

# Line 1 | Line 1
1   #
2 < # The base functionality for the ActiveDocument - inherits from Basetags
2 > # ActiveDoc.pm
3 > #
4 > # Originally Written by Christopher Williams
5 > #
6 > # Description
7   #
4 # Inherits from BaseTags
5 # --------
8   # Interface
9   # ---------
10 < # new(filename, DOChandler): create a new object based on a file and
11 < #                                 associate with a base DOChandler
12 < # parse()                       : parse the input file
13 < # include(url) : Activate include file mechanism, returns the object ref if OK
14 < # treenode()   : return the associated TreeNode object reference
15 < # getincludeObjectStore : Return a pointer to the ObectStore that contains all
16 < #                         included objects
17 < # find(string)  : find the object reference related to string in the associated
18 < #                 tree. Mechanism for getting object references
19 < # _addgroup()   : Add group functionality to document
20 < # parseerror(String) : Report an error to the user
21 < # userinterface()       : return the default User Interface object
22 < # checktag($hashref, param , tagname) : Check a hash returned from switcher
23 < #                                       for a given parameter
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.001;
36 < use ActiveDoc::DOChandler;
37 < use ActiveDoc::TreeNode;
38 < use ActiveDoc::UserQuery;
39 < use ObjectStoreCont;
40 <
41 < @ISA = qw(BaseTags);
42 <
43 < # Initialise
44 < sub _init {
45 <        my $self=shift;
46 <        my $DOChandler=shift;
47 <        my $OC=shift;
48 <
49 <        $self->_addurl();
50 <        $self->{urlhandler}->setcache($DOChandler->defaultcache());
51 <        $self->{treenode}=ActiveDoc::TreeNode->new();
52 <        $self->{dochandler}=$DOChandler;
53 <        $self->{UserQuery}=$DOChandler->{UserQuery};
54 <        $self->{tags}->addtag("Use", \&Use_Start, "", "");
44 <        # Add the minimal functionality tag - feel free to override
45 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
46 <        $self->init();
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 < sub init {
58 <        # Dummy Routine - override for derrived classes
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 < # use mechanism
74 < #
75 < sub include {
76 <        my $self=shift;
77 <        my $url=shift;
78 <        my $linkfile=shift;
79 <        my $filename;
80 <        my $obj;
81 <
82 <        $file=$self->{urlhandler}->get($url);
83 <        if ( $linkfile ne "" ) {
84 <          $filename=$file."/".$linkfile;
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 <        $obj=$self->{dochandler}->newdoc($filename);
89 >        $self->{parsers}{$parselabel}->addtag(@_);
90 > }
91  
92 <        # Now Extend our tree
93 <        $self->{treenode}->grow($obj->treenode());
94 <        return $obj;
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 userinterface {
101 > sub url {
102          my $self=shift;
103 <        return $self->{dochandler}->{UserInterface};
103 >        # get file & preprocess
104 >        if ( @_  ) {$self->{File}=$self->getfile(shift)}
105 >        $self->{File}->url();
106   }
107  
108 < sub treenode {
108 > sub copydocconfig {
109          my $self=shift;
110 <        return $self->{treenode};
110 >        my $ActiveDoc=shift;
111 >        
112 >        $self->config($ActiveDoc->config());
113 >
114   }
115  
116 < sub getincludeObjectStore {
117 <        my $self=shift;
118 <        return $self->{includeOS};
116 > sub copydocquery {
117 >        my $self=shift;
118 >        my $ActiveDoc=shift;
119 >
120 >         $self->basequery($ActiveDoc->basequery());
121   }
122  
123 < sub find($) {
123 > sub config {
124          my $self=shift;
125 <        my $string=shift;
126 <        my $tn;
125 >        @_?$self->{ActiveConfig}=shift
126 >           : $self->{ActiveConfig};
127 > }
128  
129 <        $tn=$self->{treenode}->find($string);
130 <        if ( $tn eq "" ) {
131 <          $self->parseerror("Unable to find $string");
132 <        }
97 <        return $tn->associate();
129 > sub basequery {
130 >        my $self=shift;
131 >        @_ ? $self->{UserQuery}=shift
132 >           : $self->{UserQuery};
133   }
134  
135 < sub line {
135 > sub getfile() {
136          my $self=shift;
137 <        return $self->{switch}->line();
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 error {
161 > sub activatedoc {
162          my $self=shift;
163 <        my $string=shift;
163 >        my $url=shift;
164  
165 <        die $string."\n";
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;
193 >        my $self=shift;
194 >        my $string=shift;
195  
196 <        print "Parse Error in $self->{url}, line ".
197 <                                        $self->line()."\n";
198 <        print $string."\n";
199 <        die;
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;
124        my $hashref=shift;
125        my $param=shift;
126        my $tagname=shift;
218  
219 <        if ( ! exists $$hashref{$param} ) {
220 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");  
221 <        }
219 >        my ($line, $fileobj)=
220 >                $self->{File}->realline($self->{currentparser}->line());
221 >        return ($line, $fileobj);
222   }
223  
224 < # ------------------------ Tag Routines ------------------------------
225 < #
226 < # The Include tag
227 < #
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 Include_Start {
231 > sub file {
232          my $self=shift;
140        my $name=shift;
141        my $hashref=shift;
233  
234 <        $self->{switch}->checkparam( $name, "ref");
144 <        print "<Include> tag not yet implemented\n";
145 < #        $self->include($$hashref{'ref'},$$hashref{'linkdoc'});
234 >        $self->{File}->file();
235   }
236  
237 < sub Use_Start {
238 <        my $self=shift;
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 <        print "<Use> tag not yet implemented\n";
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines