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.1 by williamc, Fri Aug 20 09:09:28 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, ObjectStoreCont): create a new object based on a file and
11 < #                                 associate with the given ObjectStoreCont
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
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.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 < package ActiveDoc;
55 < use BaseTags;
56 < use DOChandler;
57 < use ObjectStoreCont;
54 > # ----- parse related routines --------------
55 > sub parse {
56 >        my $self=shift;
57 >        $parselabel=shift;
58  
59 < @ISA = qw (BaseTags);
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 < # Initialise
27 < sub _init {
70 > sub newparse {
71          my $self=shift;
72 <        my $OC=shift;
72 >        my $parselabel=shift;
73  
74 <        $self->_addurl();
75 <        $self->{OC}=$OC;
76 <        $self->{treenode)=TreeNode->new();
34 <        $self->{includeOS}=$self->{OC}->newStore();
35 <        $self->{dochandler}=DOChandler->new($self->{includeOS});
36 <        # Add the minimal functionality tag - feel free to override
37 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
74 >        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
75 >        $self->{parsers}{$parselabel}->addignoretags();
76 >        $self->{parsers}{$parselabel}->addgrouptags();
77   }
78  
79 < #
80 < # Include mechanism
81 < #
82 < sub include {
83 <        my $self=shift;
84 <        my $url=shift;
85 <        my $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 addurltags {
90 >        my $self=shift;
91 >        my $parselabel=shift;
92 >        
93 >        $self->{parsers}{$parselabel}->
94 >                addtag("Base", \&Base_start, $self, "", $self,
95 >                        \&Base_end, $self);
96 > }
97 >
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 copydocconfig {
106 >        my $self=shift;
107 >        my $ActiveDoc=shift;
108 >        
109 >        $self->config($ActiveDoc->config());
110 >
111 > }
112 >
113 > sub copydocquery {
114 >        my $self=shift;
115 >        my $ActiveDoc=shift;
116 >
117 >         $self->basequery($ActiveDoc->basequery());
118 > }
119 >
120 > sub config {
121 >        my $self=shift;
122 >        @_?$self->{ActiveConfig}=shift
123 >           : $self->{ActiveConfig};
124 > }
125  
126 <        $obj=$self->{dochandler}->newdoc($url);
127 <        # Now Extend our tree
128 <        $self->{treenode}->grow($obj->treenode());
129 <        return $obj;
126 > sub basequery {
127 >        my $self=shift;
128 >        @_ ? $self->{UserQuery}=shift
129 >           : $self->{UserQuery};
130   }
131  
132 < sub treenode {
132 > sub getfile() {
133          my $self=shift;
134 <        return $self->treenode;
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 > # -------- 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 getincludeObjectStore {
167 > sub parseerror {
168          my $self=shift;
169 <        return $self->{includeOS};
169 >        my $string=shift;
170 >
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 find($) {
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 $string=shift;
191 >        my ($line, $fileobj)=
192 >                $self->{File}->line($self->{currentparser}->line());
193 >        return ($line, $fileobj);
194 > }
195  
196 <        $self->{treenode}->find($string);
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 ------------------------------
204 < #
205 < # A default Include tag
206 < #
75 < sub Include_Start {
76 <        my $returnval;
77 <        # Just call the basic - this is only a default wrapper for the
78 <        # <INCLUDE> tag assuming with no futher processing of the DOCObjref
79 <        $returnval=_includetag(@_)
80 <        # dont return anything if its a basic tag
203 > sub file {
204 >        my $self=shift;
205 >
206 >        $self->{File}->file();
207   }
208  
209 < # ----------------------- Support Routines ---------------------------
209 > # --------------- Initialisation Methods ---------------------------
210 >
211 > sub init {
212 >        # Dummy Routine - override for derived classes
213 > }
214 >
215 > # ------------------- Tag Routines -----------------------------------
216   #
217 < # the real workings of the include tag returns the ref
217 > # Base - for setting url bases
218   #
219 < sub _includetag {
219 > sub Base_start {
220          my $self=shift;
221          my $name=shift;
222          my $hashref=shift;
223  
224 <        $self->{switch}->checkparam( $name, "ref");
225 <        $url=$$hashref{'ref'};
226 <        return $self->include($url);
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 >
232   }
233  
234 + sub Base_end {
235 +        my $self=shift;
236 +        my $name=shift;
237 +        my $type;
238 +
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