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.2 by williamc, Mon Sep 20 16:27:57 1999 UTC vs.
Revision 1.25.2.1 by williamc, Wed May 17 13:59:42 2000 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 > # config([ActiveConfig]) :    Set up/return Configuration for the document
12 > # url()         : Return/set the docs url - essential
13 > # file()        : Return the local filename of document
14 > # ProcessFile() : Return the filename of PreProcessed document
15 > #
16 > # parent()         : return the object ref of the calling parent
17 > # getfile(url)  : get a processedfile object given a url
18 > # activatedoc(url) : Return the object ref for a doc described by the given url
19 > #                    -- any parse called "init" will also be run
20 > # userinterface()       : Return the defaullt userinterface
21 > # option(var)           : return the value of the option var ( or undef )
22 > #
23 > # addurltags(parse) : add the <base> tags to manage urls to parse
24 > # -- error methods --
25 > # error(string)       : Report an general error to the user
26 > # parseerror(string)  : Report an error during parsing a file
27 > # line()              : Return the current line number of the document
28 > #                       and the ProcessedFileObj it is in
29 > #
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::SimpleDoc;
34 > use URL::URLhandler;
35 >
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37 >
38 > sub addurltags {
39 >        my $self=shift;
40 >        my $parselabel=shift;
41 >        
42 >        $self->{parsers}{$parselabel}->
43 >                addtag("Base", \&Base_start, $self, "", $self,
44 >                        \&Base_end, $self);
45 > }
46 >
47 > sub url {
48 >        my $self=shift;
49 >        # get file & preprocess
50 >        if ( @_  ) {
51 >                $self->{File}=$self->getfile(shift);
52 >                $self->verbose("url downloaded to $self->{File}");
53 >        }
54 >        if ( defined $self->{File} ) {
55 >          return $self->{File}->url();
56 >        }
57 >        else { return "undefined"; }
58   }
59  
60 < sub init {
61 <        # Dummy Routine - override for derrived classes
60 > sub config {
61 >        my $self=shift;
62 >        @_?$self->{ActiveConfig}=shift
63 >           : $self->{ActiveConfig};
64   }
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;
65  
66 <        $file=$self->{urlhandler}->get($url);
67 <        if ( $linkfile ne "" ) {
68 <          $filename=$file."/".$linkfile;
65 <        }
66 <        $obj=$self->{dochandler}->newdoc($filename);
66 > sub getfile {
67 >        my $self=shift;
68 >        my $origurl=shift;
69  
70 <        # Now Extend our tree
71 <        $self->{treenode}->grow($obj->treenode());
72 <        return $obj;
70 >        my $fileref;
71 >        my ($url, $file);
72 >        if ( (defined ($it=$self->option('url_update'))) &&
73 >                ( $it eq "1" || $origurl=~/^$it/ )) {
74 >             $self->verbose("Forced download of $origurl");
75 >             ($url, $file)=$self->{urlhandler}->download($origurl);
76 >        }
77 >        else {
78 >           $self->verbose("Attempting to get $origurl");
79 >           ($url, $file)=$self->{urlhandler}->get($origurl);
80 >        }
81 >        # do we already have an appropriate object?
82 >        ($fileref)=$self->config()->find($url);
83 >        #undef $fileref;
84 >        if (  defined $fileref ) {
85 >         $self->verbose("Found $url in database");
86 >         $fileref->update();
87 >        }
88 >        else {
89 >         if ( $file eq "" ) {
90 >           $self->parseerror("Unable to get $origurl");
91 >         }
92 >         #-- set up a new preprocess file
93 >         $self->verbose("Making a new preprocessed file $url");
94 >         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
95 >         $fileref->url($url);
96 >         $fileref->update();
97 >        }
98 >        return $fileref;
99   }
100  
101 < sub userinterface {
101 > sub activatedoc {
102          my $self=shift;
103 <        return $self->{dochandler}->{UserInterface};
103 >        my $url=shift;
104 >
105 >        # first get a preprocessed copy of the file
106 > #       my $fileob=$self->getfile($url);
107 >
108 >        # now parse it for the <DocType> tag
109 >        my $tempdoc=ActiveDoc::ActiveDoc->new($self->config());
110 >        $tempdoc->{urlhandler}=$self->{urlhandler};
111 >        my $fullurl=$tempdoc->url($url);
112 >        $url=$fullurl;
113 >        $tempdoc->{doctypefound}=0;
114 >        $tempdoc->newparse("doctype");
115 >        $tempdoc->addtag("doctype","Doc", \&Doc_Start, $tempdoc,
116 >                                          "", $tempdoc, "", $tempdoc);
117 >        $tempdoc->parse("doctype");
118 >
119 >        if ( ! defined $tempdoc->{docobject} ) {
120 >          print "No <Doc type=> Specified in ".$url."\n";
121 >          exit 1;
122 >        }
123 >        # Set up a new object of the specified type
124 >        eval "require $tempdoc->{docobject}";
125 >        die $@ if $@;
126 >        my $newobj=$tempdoc->{docobject}->new($self->config());
127 >        undef $tempdoc;
128 >        $newobj->url($url);
129 >        $newobj->parent($self);
130 >        return $newobj;
131   }
132  
133 < sub treenode {
133 > sub parent {
134          my $self=shift;
135 <        return $self->{treenode};
135 >
136 >        @_?$self->{parent}=shift
137 >          :$self->{parent};
138   }
139  
140 < sub getincludeObjectStore {
140 > # -------- Error Handling and Error services --------------
141 >
142 > sub error {
143          my $self=shift;
144 <        return $self->{includeOS};
144 >        my $string=shift;
145 >
146 >        die $string."\n";
147   }
148  
149 < sub find($) {
150 <        my $self=shift;
151 <        my $string=shift;
91 <        my $tn;
149 > sub parseerror {
150 >        my $self=shift;
151 >        my $string=shift;
152  
153 <        $tn=$self->{treenode}->find($string);
154 <        if ( $tn eq "" ) {
155 <          $self->parseerror("Unable to find $string");
153 >        if ( $self->currentparsename() eq "" ) {
154 >                $self->error($string);
155 >        }
156 >        else {
157 >         ($line, $file)=$self->line();
158 >         print "Parse Error in ".$file->url().", line ".
159 >                                        $line."\n";
160 >         print $string."\n";
161 >         exit;
162          }
97        return $tn->associate();
163   }
164  
165 < sub parseerror {
165 > sub line {
166          my $self=shift;
102        my $string=shift;
167  
168 <        print "Parse Error in $self->{url}, line $self-{switch}->line()\n";
169 <        print $string."\n";
170 <        die;
168 >        my ($line, $fileobj)=
169 >                $self->{File}->realline($self->{currentparser}->line());
170 >        return ($line, $fileobj);
171   }
172  
173 < sub checktag {
173 > sub tagstartline {
174          my $self=shift;
175 <        my $hashref=shift;
176 <        my $param=shift;
177 <        my $tagname=shift;
114 <
115 <        if ( ! exists $$hashref{$param} ) {
116 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");  
117 <        }
175 >        my ($line, $fileobj)=$self->{File}->line(
176 >                $self->{currentparser}->tagstartline());
177 >        return ($line, $fileobj);
178   }
179  
180 < # ------------------------ Tag Routines ------------------------------
121 < #
122 < # The Include tag
123 < #
124 <
125 < sub Include_Start {
180 > sub file {
181          my $self=shift;
127        my $name=shift;
128        my $hashref=shift;
182  
183 <        $self->{switch}->checkparam( $name, "ref");
131 <        print "<Include> tag not yet implemented\n";
132 < #        $self->include($$hashref{'ref'},$$hashref{'linkdoc'});
183 >        $self->{File}->file();
184   }
185  
186 < sub Use_Start {
186 > sub ProcessFile {
187          my $self=shift;
188 +
189 +        return $self->{File}->ProcessedFile();
190 + }
191 +
192 + # --------------- Initialisation Methods ---------------------------
193 +
194 + sub init {
195 +        # Dummy Routine - override for derived classes
196 + }
197 +
198 + # ------------------- Tag Routines -----------------------------------
199 + #
200 + # Base - for setting url bases
201 + #
202 + sub Base_start {
203 +        my $self=shift;
204          my $name=shift;
205          my $hashref=shift;
206  
207 <        print "<Use> tag not yet implemented\n";
207 >        $self->checktag($name, $hashref, 'type' );
208 >        $self->checktag($name, $hashref, 'base' );
209 >      
210 >        # Keep track of base tags
211 >        push @{$self->{basestack}}, $$hashref{"type"};
212 >        # Set the base
213 >        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
214 > }
215 >
216 > sub Base_end {
217 >        my $self=shift;
218 >        my $name=shift;
219 >        my $type;
220 >
221 >        if ( $#{$self->{basestack}} == -1 ) {
222 >                $self->parseerror("Parse Error : unmatched </$name>");
223 >        }
224 >        else {
225 >          $type = pop @{$self->{basestack}};
226 >          $self->{urlhandler}->unsetbase($type);
227 >        }
228 > }
229 >
230 > sub Doc_Start {
231 >        my $self=shift;
232 >        my $name=shift;
233 >        my $hashref=shift;
234 >        
235 >        $self->checktag($name, $hashref, "type");
236 >        $self->{doctypefound}++;
237 >        if ( $self->{doctypefound} == 1 ) { # only take first doctype
238 >           $self->{docobject}=$$hashref{'type'};
239 >        }
240   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines