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.4 by williamc, Mon Sep 27 14:05:22 1999 UTC vs.
Revision 1.8 by williamc, Tue Nov 23 17:31:10 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();
55 < }
56 <
57 < sub init {
58 <        # Dummy Routine - override for derrived classes
59 < }
60 < #
61 < # use mechanism
62 < #
63 < 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 ( ( defined $linkfile) && ( $linkfile ne "" ) ) {
64 <          $filename=$file."/".$linkfile;
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 <          $filename=$file;
66 >          print "Cannot parse - file not known\n";
67          }
68 <        $obj=$self->{dochandler}->newdoc($filename);
68 > }
69 >
70 > sub newparse {
71 >        my $self=shift;
72 >        my $parselabel=shift;
73  
74 <        # Now Extend our tree
75 <        $self->{treenode}->grow($obj->treenode());
76 <        return $obj;
74 >        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
75 >        $self->{parsers}{$parselabel}->addignoretags();
76 >        $self->{parsers}{$parselabel}->addgrouptags();
77   }
78  
79 < sub userinterface {
79 > sub addtag {
80          my $self=shift;
81 <        return $self->{dochandler}->{UserInterface};
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 treenode {
89 > sub addurltags {
90          my $self=shift;
91 <        return $self->{treenode};
91 >        my $parselabel=shift;
92 >        
93 >        $self->{parsers}{$parselabel}->
94 >                addtag("Base", \&Base_start, $self, "", $self,
95 >                        \&Base_end, $self);
96   }
97  
98 < sub getincludeObjectStore {
99 <        my $self=shift;
100 <        return $self->{includeOS};
98 > sub url {
99 >        my $self=shift;
100 >        # get file & preprocess
101 >        if ( @_  ) {$self->{File}=$self->getfile(shift)}
102 >        $self->{File}->url();
103   }
104  
105 < sub find($) {
105 > sub copydocconfig {
106          my $self=shift;
107 <        my $string=shift;
108 <        my $tn;
107 >        my $ActiveDoc=shift;
108 >        
109 >        $self->config($ActiveDoc->config());
110  
96        $tn=$self->{treenode}->find($string);
97        if ( $tn eq "" ) {
98          $self->parseerror("Unable to find $string");
99        }
100        return $tn->associate();
111   }
112  
113 < sub line {
113 > sub copydocquery {
114          my $self=shift;
115 <        return $self->{switch}->line();
115 >        my $ActiveDoc=shift;
116 >
117 >         $self->basequery($ActiveDoc->basequery());
118   }
119  
120 < sub error {
120 > sub config {
121          my $self=shift;
122 <        my $string=shift;
122 >        @_?$self->{ActiveConfig}=shift
123 >           : $self->{ActiveConfig};
124 > }
125 >
126 > sub basequery {
127 >        my $self=shift;
128 >        @_ ? $self->{UserQuery}=shift
129 >           : $self->{UserQuery};
130 > }
131 >
132 > sub getfile() {
133 >        my $self=shift;
134 >        my $origurl=shift;
135 >
136 >        my $fileref;
137 >        my ($url, $file)=$self->{urlhandler}->get($origurl);
138 >        # do we already have an appropriate object?
139 >        ($fileref)=$self->config()->find($url);
140 >        #undef $fileref;
141 >        if (  defined $fileref ) {
142 >         print "found $url in database ----\n";
143 >         $fileref->update();
144 >        }
145 >        else {
146 >         if ( $file eq "" ) {
147 >           $self->parseerror("Unable to get $origurl");
148 >         }
149 >         #-- set up a new preprocess file
150 >         print "Making a new file $url----\n";
151 >         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
152 >         $fileref->url($url);
153 >         $fileref->update();
154 >        }
155 >        return $fileref;
156 > }
157  
158 <        die $string."\n";
158 > # -------- Error Handling and Error services --------------
159  
160 + sub error {
161 +        my $self=shift;
162 +        my $string=shift;
163 +
164 +        die $string."\n";
165   }
166 +
167   sub parseerror {
168 <        my $self=shift;
169 <        my $string=shift;
168 >        my $self=shift;
169 >        my $string=shift;
170  
171 <        print "Parse Error in $self->{url}, line ".
172 <                                        $self->line()."\n";
173 <        print $string."\n";
174 <        die;
171 >        ($line, $file)=$self->line();
172 >        print "Parse Error in ".$file->url().", line ".
173 >                                        $line."\n";
174 >        print $string."\n";
175 >        die;
176   }
177  
178   sub checktag {
179 +        my $self=shift;
180 +        my $tagname=shift;
181 +        my $hashref=shift;
182 +        my $param=shift;
183 +
184 +        if ( ! exists $$hashref{$param} ) {
185 +          $self->parseerror("Incomplete Tag <$tagname> : $param required");
186 +        }
187 + }
188 +
189 + sub line {
190          my $self=shift;
191 <        my $hashref=shift;
192 <        my $param=shift;
193 <        my $tagname=shift;
191 >        my ($line, $fileobj)=
192 >                $self->{File}->line($self->{currentparser}->line());
193 >        return ($line, $fileobj);
194 > }
195  
196 <        if ( ! exists $$hashref{$param} ) {
197 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");  
198 <        }
196 > sub tagstartline {
197 >        my $self=shift;
198 >        my ($line, $fileobj)=$self->{File}->line(
199 >                $self->{currentparser}->tagstartline());
200 >        return ($line, $fileobj);
201   }
202  
203 < # ------------------------ Tag Routines ------------------------------
203 > sub file {
204 >        my $self=shift;
205 >
206 >        $self->{File}->file();
207 > }
208 >
209 > # --------------- Initialisation Methods ---------------------------
210 >
211 > sub init {
212 >        # Dummy Routine - override for derived classes
213 > }
214 >
215 > # ------------------- Tag Routines -----------------------------------
216   #
217 < # The Include tag
217 > # Base - for setting url bases
218   #
219 + sub Base_start {
220 +        my $self=shift;
221 +        my $name=shift;
222 +        my $hashref=shift;
223  
224 < sub Include_Start {
225 <        my $self=shift;
226 <        my $name=shift;
227 <        my $hashref=shift;
224 >        $self->checktag($name, $hashref, 'type' );
225 >        $self->checktag($name, $hashref, 'base' );
226 >      
227 >        # Keep track of base tags
228 >        push @{$self->{basestack}}, $$hashref{"type"};
229 >        # Set the base
230 >        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
231  
146        $self->{switch}->checkparam( $name, "ref");
147        print "<Include> tag not yet implemented\n";
148 #        $self->include($$hashref{'ref'},$$hashref{'linkdoc'});
232   }
233  
234 < sub Use_Start {
235 <        my $self=shift;
234 > sub Base_end {
235 >        my $self=shift;
236          my $name=shift;
237 <        my $hashref=shift;
237 >        my $type;
238  
239 <        print "<Use> tag not yet implemented\n";
239 >        if ( $#{$self->{basestack}} == -1 ) {
240 >                print "Parse Error : unmatched </".$name."> on line ".
241 >                        $self->line()."\n";
242 >                die;
243 >        }
244 >        else {
245 >          $type = pop @{$self->{basestack}};
246 >          $self->{urlhandler}->unsetbase($type);
247 >        }
248   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines