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.7 by williamc, Tue Nov 23 17:20:40 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 > # newdoc(file)  : Return an new object of the appropriate type
19 > # getfile(url)  : get a processedfile object given a url
20 > # config([ActiveConfig]) : Set up/return Configuration for the document
21 > # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
22 > # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
23 > # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
24 > #
25 > # -- error methods --
26 > # error(string)       : Report an general error to the user
27 > # parseerror(string)  : Report an error during parsing a file
28 > # line()              : Return the current line number of the document
29 > #                       and the ProcessedFileObj it is in
30  
31   package ActiveDoc::ActiveDoc;
32 < require 5.001;
33 < use ActiveDoc::DOChandler;
34 < use ActiveDoc::TreeNode;
35 < use ActiveDoc::UserQuery;
36 < use ObjectStoreCont;
37 <
38 < @ISA = qw(BaseTags);
39 <
40 < # Initialise
41 < sub _init {
42 <        my $self=shift;
43 <        my $DOChandler=shift;
44 <        my $OC=shift;
45 <
46 <        $self->_addurl();
47 <        $self->{urlhandler}->setcache($DOChandler->defaultcache());
48 <        $self->{treenode}=ActiveDoc::TreeNode->new();
49 <        $self->{dochandler}=$DOChandler;
50 <        $self->{UserQuery}=$DOChandler->{UserQuery};
51 <        $self->{tags}->addtag("Use", \&Use_Start, "", "");
52 <        # Add the minimal functionality tag - feel free to override
53 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
54 <        $self->init();
32 > require 5.004;
33 > use ActiveDoc::Parse;
34 > use ActiveDoc::ActiveConfig;
35 > use ActiveDoc::PreProcessedFile;
36 > use ObjectUtilities::ObjectBase;
37 > use URL::URLhandler;
38 >
39 > @ISA = qw(ObjectUtilities::ObjectBase);
40 >
41 > sub new {
42 >        my $class=shift;
43 >        $self={};
44 >        bless $self, $class;
45 >        $self->config(shift);
46 >        
47 >        # A URL handler per document
48 >        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
49 >
50 >        $self->init(@_);
51 >        return $self;
52 > }
53 >
54 > # ----- parse related routines --------------
55 > sub parse {
56 >        my $self=shift;
57 >        $parselabel=shift;
58 >
59 >        my $file=$self->file();
60 >        if ( $file ) {
61 >          $self->{currentparser}=$self->{parsers}{$parselabel};
62 >          $self->{parsers}{$parselabel}->parse($file,@_);
63 >          delete $self->{currentparser};
64 >        }
65 >        else {
66 >          print "Cannot parse - file not known\n";
67 >        }
68   }
69  
70 < sub init {
71 <        # Dummy Routine - override for derrived classes
70 > sub newparse {
71 >        my $self=shift;
72 >        my $parselabel=shift;
73 >
74 >        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
75 >        $self->{parsers}{$parselabel}->addignoretags();
76 >        $self->{parsers}{$parselabel}->addgrouptags();
77   }
52 #
53 # use mechanism
54 #
55 sub include {
56        my $self=shift;
57        my $url=shift;
58        my $linkfile=shift;
59        my $filename;
60        my $obj;
61
62        $file=$self->{urlhandler}->get($url);
63        if ( $linkfile ne "" ) {
64          $filename=$file."/".$linkfile;
65        }
66        $obj=$self->{dochandler}->newdoc($filename);
78  
79 <        # Now Extend our tree
80 <        $self->{treenode}->grow($obj->treenode());
81 <        return $obj;
79 > sub addtag {
80 >        my $self=shift;
81 >        my $parselabel=shift;
82 >        if ( $#_ != 6 ) {
83 >                $self->error("Incorrect addtags specification\n".
84 >                                "called with :\n@_ \n");
85 >        }
86 >        $self->{parsers}{$parselabel}->addtag(@_);
87   }
88  
89 < sub userinterface {
89 > sub addurltags {
90          my $self=shift;
91 <        return $self->{dochandler}->{UserInterface};
91 >        my $parselabel=shift;
92 >        
93 >        $self->{parsers}{$parselabel}->
94 >                addtag("Base", \&Base_start, $self, "", $self,
95 >                        \&Base_end, $self);
96   }
97  
98 < sub treenode {
98 > sub url {
99          my $self=shift;
100 <        return $self->{treenode};
100 >        @_ ?$self->{File}=$self->getfile(shift)
101 >            : $self->{File};
102   }
103  
104 < sub getincludeObjectStore {
105 <        my $self=shift;
106 <        return $self->{includeOS};
104 > sub copydocconfig {
105 >        my $self=shift;
106 >        my $ActiveDoc=shift;
107 >        
108 >        $self->config($ActiveDoc->config());
109 >
110   }
111  
112 < sub find($) {
112 > sub copydocquery {
113          my $self=shift;
114 <        my $string=shift;
91 <        my $tn;
114 >        my $ActiveDoc=shift;
115  
116 <        $tn=$self->{treenode}->find($string);
94 <        if ( $tn eq "" ) {
95 <          $self->parseerror("Unable to find $string");
96 <        }
97 <        return $tn->associate();
116 >         $self->basequery($ActiveDoc->basequery());
117   }
118  
119 < sub line {
119 > sub config {
120          my $self=shift;
121 <        return $self->{switch}->line();
121 >        @_?$self->{ActiveConfig}=shift
122 >           : $self->{ActiveConfig};
123   }
124  
125 < sub error {
125 > sub basequery {
126          my $self=shift;
127 <        my $string=shift;
127 >        @_ ? $self->{UserQuery}=shift
128 >           : $self->{UserQuery};
129 > }
130  
131 <        die $string."\n";
131 > sub getfile() {
132 >        my $self=shift;
133 >        my $origurl=shift;
134  
135 +        my $fileref;
136 +        my ($url, $file)=$self->{urlhandler}->get($origurl);
137 +        # do we already have an appropriate object?
138 +        ($fileref)=$self->config()->find($url);
139 +        #undef $fileref;
140 +        if (  defined $fileref ) {
141 +         print "found $url in database ----\n";
142 +         $fileref->update();
143 +        }
144 +        else {
145 +         if ( $file eq "" ) {
146 +           $self->parseerror("Unable to get $origurl");
147 +         }
148 +         #-- set up a new preprocess file
149 +         print "Making a new file $url----\n";
150 +         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
151 +         $fileref->url($url);
152 +         $fileref->update();
153 +        }
154 +        return $fileref;
155   }
156 +
157 + # -------- Error Handling and Error services --------------
158 +
159 + sub error {
160 +        my $self=shift;
161 +        my $string=shift;
162 +
163 +        die $string."\n";
164 + }
165 +
166   sub parseerror {
167 <        my $self=shift;
168 <        my $string=shift;
167 >        my $self=shift;
168 >        my $string=shift;
169  
170 <        print "Parse Error in $self->{url}, line ".
171 <                                        $self->line()."\n";
172 <        print $string."\n";
173 <        die;
170 >        ($line, $file)=$self->line();
171 >        print "Parse Error in ".$file->url().", line ".
172 >                                        $line."\n";
173 >        print $string."\n";
174 >        die;
175   }
176  
177   sub checktag {
178 <        my $self=shift;
179 <        my $hashref=shift;
180 <        my $param=shift;
181 <        my $tagname=shift;
178 >        my $self=shift;
179 >        my $tagname=shift;
180 >        my $hashref=shift;
181 >        my $param=shift;
182  
183 <        if ( ! exists $$hashref{$param} ) {
184 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");  
185 <        }
183 >        if ( ! exists $$hashref{$param} ) {
184 >          $self->parseerror("Incomplete Tag <$tagname> : $param required");
185 >        }
186   }
187  
188 < # ------------------------ Tag Routines ------------------------------
189 < #
190 < # The Include tag
191 < #
188 > sub line {
189 >        my $self=shift;
190 >        my ($line, $fileobj)=
191 >                $self->{PPfile}->line($self->{currentparser}->line());
192 >        return ($line, $fileobj);
193 > }
194  
195 < sub Include_Start {
195 > sub tagstartline {
196          my $self=shift;
197 <        my $name=shift;
198 <        my $hashref=shift;
197 >        my ($line, $fileobj)=$self->{PPfile}->line(
198 >                $self->{currentparser}->tagstartline());
199 >        return ($line, $fileobj);
200 > }
201  
202 <        $self->{switch}->checkparam( $name, "ref");
203 <        print "<Include> tag not yet implemented\n";
204 < #        $self->include($$hashref{'ref'},$$hashref{'linkdoc'});
202 > sub file {
203 >        my $self=shift;
204 >
205 >        $self->{PPf}->file();
206   }
207  
208 < sub Use_Start {
208 > # --------------- Initialisation Methods ---------------------------
209 >
210 > sub preprocess_init {
211          my $self=shift;
212 +        $self->{PPfile}=PreProcessedFile->new($self->config());
213 + }
214 +
215 + sub init {
216 +        # Dummy Routine - override for derived classes
217 + }
218 +
219 + # ------------------- Tag Routines -----------------------------------
220 + #
221 + # Base - for setting url bases
222 + #
223 + sub Base_start {
224 +        my $self=shift;
225          my $name=shift;
226          my $hashref=shift;
227  
228 <        print "<Use> tag not yet implemented\n";
228 >        $self->checktag($name, $hashref, 'type' );
229 >        $self->checktag($name, $hashref, 'base' );
230 >      
231 >        # Keep track of base tags
232 >        push @{$self->{basestack}}, $$hashref{"type"};
233 >        # Set the base
234 >        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
235 >
236 > }
237 >
238 > sub Base_end {
239 >        my $self=shift;
240 >        my $name=shift;
241 >        my $type;
242 >
243 >        if ( $#{$self->{basestack}} == -1 ) {
244 >                print "Parse Error : unmatched </".$name."> on line ".
245 >                        $self->line()."\n";
246 >                die;
247 >        }
248 >        else {
249 >          $type = pop @{$self->{basestack}};
250 >          $self->{urlhandler}->unsetbase($type);
251 >        }
252   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines