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.14 by williamc, Tue Jan 18 18:30:10 2000 UTC vs.
Revision 1.25.2.1 by williamc, Wed May 17 13:59:42 2000 UTC

# Line 8 | Line 8
8   # Interface
9   # ---------
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 < # 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 < # checktag(tagname, hashref, param) : check for existence of param in
19 < #                                       hashref from a tag call
20 < # includeparse(local_parsename, objparsename, activedoc) : copy the parse from
21 < #                                                       one object to another
22 < # currentparsename([name]) : get/set current parse name
23 < # newdoc(file)  : Return an new object of the appropriate type
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
27 # config([ActiveConfig]) : Set up/return Configuration for the document
28 # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
29 # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
30 # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
20   # userinterface()       : Return the defaullt userinterface
21 < # option(var)           : return the value of the option var
33 < # requestoption("message") : Ask the user to supply a value for an option
34 < #                            if it dosnt already exist
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.004;
33 < use ActiveDoc::Parse;
45 < use ActiveDoc::ActiveConfig;
46 < use ActiveDoc::PreProcessedFile;
47 < use ObjectUtilities::StorableObject;
33 > use ActiveDoc::SimpleDoc;
34   use URL::URLhandler;
35  
36 < @ISA = qw(ObjectUtilities::StorableObject);
51 <
52 < sub new {
53 <        my $class=shift;
54 <        $self={};
55 <        bless $self, $class;
56 <        $self->config(shift);
57 <
58 <        # --- is there a starter document?
59 <        my $basedoc=$self->config()->basedoc();
60 <        if ( defined $basedoc ) {
61 <          $self->copydocquery($basedoc);
62 <        }
63 <        else {
64 <          $self->error("Error : No base doc found");
65 <        }
66 <        $self->_init2();
67 < }
68 <
69 < sub _init2 {
70 <
71 <        my $self=shift;
72 <        # A URL handler per document
73 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
74 <
75 <        # A default UserInterface
76 <        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
77 <        $self->init(@_);
78 <        return $self;
79 <
80 < }
81 <
82 < # ----- parse related routines --------------
83 < sub parse {
84 <        my $self=shift;
85 <        $parselabel=shift;
86 <
87 <        my $file=$self->file();
88 <        if ( $file ) {
89 <          if ( exists $self->{parsers}{$parselabel} ) {
90 <            $self->{currentparsename}=$parselabel;
91 <            $self->{currentparser}=$self->{parsers}{$parselabel};
92 <            $self->{parsers}{$parselabel}->parse($file,@_);
93 <            delete $self->{currentparser};
94 <            $self->{currentparsename}="";
95 <          }
96 <        }
97 <        else {
98 <          print "Cannot parse - file not known\n";
99 <        }
100 < }
101 <
102 < sub currentparsename {
103 <        my $self=shift;
104 <        @_?$self->{currentparsename}=shift
105 <          :$self->{currentparsename};
106 < }
107 <
108 < sub newparse {
109 <        my $self=shift;
110 <        my $parselabel=shift;
111 <
112 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
113 <        $self->{parsers}{$parselabel}->addignoretags();
114 <        $self->{parsers}{$parselabel}->addgrouptags();
115 < }
116 <
117 < sub cleartags {
118 <        my $self=shift;
119 <        my $parselabel=shift;
120 <
121 <        $self->{parsers}{$parselabel}->cleartags();
122 < }
123 <
124 <
125 < sub includeparse {
126 <        my $self=shift;
127 <        my $parselabel=shift;
128 <        my $remoteparselabel=shift;
129 <        my $activedoc=shift;
130 <
131 <        # Some error trapping
132 <        if ( ! exists $self->{parsers}{$parselabel} ) {
133 <          $self->error("Unknown local parse name specified");
134 <        }
135 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
136 <          $self->error("Unknown parse name specified in remote obj $activedoc");
137 <        }
138 <
139 <        #
140 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
141 <        $self->{parsers}{$parselabel}->includeparse($rp);
142 < }
143 <
144 < sub addtag {
145 <        my $self=shift;
146 <        my $parselabel=shift;
147 <        if ( $#_ != 6 ) {
148 <                $self->error("Incorrect addtags specification\n".
149 <                                "called with :\n@_ \n");
150 <        }
151 <        $self->{parsers}{$parselabel}->addtag(@_);
152 < }
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37  
38   sub addurltags {
39          my $self=shift;
# Line 163 | Line 47 | sub addurltags {
47   sub url {
48          my $self=shift;
49          # get file & preprocess
50 <        if ( @_  ) {$self->{File}=$self->getfile(shift)}
51 <        $self->{File}->url();
52 < }
53 <
54 < sub copydocconfig {
55 <        my $self=shift;
56 <        my $ActiveDoc=shift;
57 <        
174 <        $self->config($ActiveDoc->config());
175 <
176 < }
177 <
178 < sub copydocquery {
179 <        my $self=shift;
180 <        my $ActiveDoc=shift;
181 <
182 <        $self->basequery($ActiveDoc->basequery());
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 config {
# Line 188 | Line 63 | sub config {
63             : $self->{ActiveConfig};
64   }
65  
66 < sub basequery {
192 <        my $self=shift;
193 <        @_ ? $self->{Query}=shift
194 <           : $self->{Query};
195 < }
196 <
197 < sub option {
198 <        my $self=shift;
199 <        my $param=shift;
200 <        $self->basequery()->getparam($param);
201 < }
202 <
203 < sub requestoption {
204 <        my $self=shift;
205 <        my $param=shift;
206 <        my $string=shift;
207 <
208 <        my $par=$self->basequery()->getparam($param);
209 <        while ( ! defined $par ) {
210 <          $self->basequery()->querytype( $param, "basic");
211 <          $self->basequery()->querymessage( $param, $string);
212 <          $self->userinterface()->askuser($self->basequery());
213 <          $par=$self->basequery()->getparam('ActiveConfigdir');
214 <        }
215 <        return $par;
216 < }
217 <
218 < sub getfile() {
66 > sub getfile {
67          my $self=shift;
68          my $origurl=shift;
69  
70          my $fileref;
71 <        my ($url, $file)=$self->{urlhandler}->get($origurl);
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 <         print "found $url in database ----\n";
85 >         $self->verbose("Found $url in database");
86           $fileref->update();
87          }
88          else {
# Line 233 | Line 90 | sub getfile() {
90             $self->parseerror("Unable to get $origurl");
91           }
92           #-- set up a new preprocess file
93 <         print "Making a new file $url----\n";
93 >         $self->verbose("Making a new preprocessed file $url");
94           $fileref=ActiveDoc::PreProcessedFile->new($self->config());
95           $fileref->url($url);
96           $fileref->update();
# Line 250 | Line 107 | sub activatedoc {
107  
108          # now parse it for the <DocType> tag
109          my $tempdoc=ActiveDoc::ActiveDoc->new($self->config());
110 <        $tempdoc->url($url);
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,
# Line 267 | Line 126 | sub activatedoc {
126          my $newobj=$tempdoc->{docobject}->new($self->config());
127          undef $tempdoc;
128          $newobj->url($url);
129 <        $newobj->_initparse();
129 >        $newobj->parent($self);
130          return $newobj;
131   }
132  
133 < sub _initparse {
133 > sub parent {
134          my $self=shift;
135  
136 <        $self->parse("init");
136 >        @_?$self->{parent}=shift
137 >          :$self->{parent};
138   }
139 +
140   # -------- Error Handling and Error services --------------
141  
142   sub error {
# Line 289 | Line 150 | sub parseerror {
150          my $self=shift;
151          my $string=shift;
152  
153 <        ($line, $file)=$self->line();
154 <        print "Parse Error in ".$file->url().", line ".
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 <        die;
162 < }
298 <
299 < sub checktag {
300 <        my $self=shift;
301 <        my $tagname=shift;
302 <        my $hashref=shift;
303 <        my $param=shift;
304 <
305 <        if ( ! exists $$hashref{$param} ) {
306 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
307 <        }
160 >         print $string."\n";
161 >         exit;
162 >        }
163   }
164  
165   sub line {
# Line 328 | Line 183 | sub file {
183          $self->{File}->file();
184   }
185  
186 + sub ProcessFile {
187 +        my $self=shift;
188 +
189 +        return $self->{File}->ProcessedFile();
190 + }
191 +
192   # --------------- Initialisation Methods ---------------------------
193  
194   sub init {
# Line 350 | Line 211 | sub Base_start {
211          push @{$self->{basestack}}, $$hashref{"type"};
212          # Set the base
213          $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
353
214   }
215  
216   sub Base_end {
# Line 359 | Line 219 | sub Base_end {
219          my $type;
220  
221          if ( $#{$self->{basestack}} == -1 ) {
222 <                print "Parse Error : unmatched </".$name."> on line ".
363 <                        $self->line()."\n";
364 <                die;
222 >                $self->parseerror("Parse Error : unmatched </$name>");
223          }
224          else {
225            $type = pop @{$self->{basestack}};
# Line 380 | Line 238 | sub Doc_Start {
238             $self->{docobject}=$$hashref{'type'};
239          }
240   }
383
384 sub userinterface {
385        my $self=shift;
386        @_?$self->{userinterface}=shift
387          :$self->{userinterface}
388 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines