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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines