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.15 by williamc, Thu Jan 20 18:18:45 2000 UTC vs.
Revision 1.25.2.1 by williamc, Wed May 17 13:59:42 2000 UTC

# Line 7 | Line 7
7   #
8   # Interface
9   # ---------
10 < # new(ActiveConfig[,options])           : A new ActiveDoc object
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 <        # have some override options been passed
59 <        if ( @_ ) {
60 <           $self->basequery(shift);
61 <        }
62 <        else {
63 <           # --- is there a starter document?
64 <           my $basedoc=$self->config()->basedoc();
65 <           if ( defined $basedoc ) {
66 <             $self->copydocquery($basedoc);
67 <           }
68 <           else {
69 <             $self->error("Error : No base doc found");
70 <           }
71 <        }
72 <        $self->_init2();
73 < }
74 <
75 < sub _init2 {
76 <
77 <        my $self=shift;
78 <        # A URL handler per document
79 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
80 <
81 <        # A default UserInterface
82 <        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
83 <        $self->init(@_);
84 <        return $self;
85 <
86 < }
87 <
88 < # ----- parse related routines --------------
89 < sub parse {
90 <        my $self=shift;
91 <        $parselabel=shift;
92 <
93 <        my $file=$self->file();
94 <        if ( $file ) {
95 <          if ( exists $self->{parsers}{$parselabel} ) {
96 <            $self->{currentparsename}=$parselabel;
97 <            $self->{currentparser}=$self->{parsers}{$parselabel};
98 <            $self->{parsers}{$parselabel}->parse($file,@_);
99 <            delete $self->{currentparser};
100 <            $self->{currentparsename}="";
101 <          }
102 <        }
103 <        else {
104 <          print "Cannot parse - file not known\n";
105 <        }
106 < }
107 <
108 < sub currentparsename {
109 <        my $self=shift;
110 <        @_?$self->{currentparsename}=shift
111 <          :$self->{currentparsename};
112 < }
113 <
114 < sub newparse {
115 <        my $self=shift;
116 <        my $parselabel=shift;
117 <
118 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
119 <        $self->{parsers}{$parselabel}->addignoretags();
120 <        $self->{parsers}{$parselabel}->addgrouptags();
121 < }
122 <
123 < sub cleartags {
124 <        my $self=shift;
125 <        my $parselabel=shift;
126 <
127 <        $self->{parsers}{$parselabel}->cleartags();
128 < }
129 <
130 <
131 < sub includeparse {
132 <        my $self=shift;
133 <        my $parselabel=shift;
134 <        my $remoteparselabel=shift;
135 <        my $activedoc=shift;
136 <
137 <        # Some error trapping
138 <        if ( ! exists $self->{parsers}{$parselabel} ) {
139 <          $self->error("Unknown local parse name specified");
140 <        }
141 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
142 <          $self->error("Unknown parse name specified in remote obj $activedoc");
143 <        }
144 <
145 <        #
146 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
147 <        $self->{parsers}{$parselabel}->includeparse($rp);
148 < }
149 <
150 < sub addtag {
151 <        my $self=shift;
152 <        my $parselabel=shift;
153 <        if ( $#_ != 6 ) {
154 <                $self->error("Incorrect addtags specification\n".
155 <                                "called with :\n@_ \n");
156 <        }
157 <        $self->{parsers}{$parselabel}->addtag(@_);
158 < }
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37  
38   sub addurltags {
39          my $self=shift;
# Line 169 | 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 <        
180 <        $self->config($ActiveDoc->config());
181 <
182 < }
183 <
184 < sub copydocquery {
185 <        my $self=shift;
186 <        my $ActiveDoc=shift;
187 <
188 <        $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 194 | Line 63 | sub config {
63             : $self->{ActiveConfig};
64   }
65  
66 < sub basequery {
66 > sub getfile {
67          my $self=shift;
68 <        @_ ? $self->{Query}=shift
200 <           : $self->{Query};
201 < }
68 >        my $origurl=shift;
69  
70 < sub option {
71 <        my $self=shift;
72 <        my $param=shift;
73 <        if ( defined $self->basequery()) {
74 <                return $self->basequery()->getparam($param);
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 <                return $undef;
78 >           $self->verbose("Attempting to get $origurl");
79 >           ($url, $file)=$self->{urlhandler}->get($origurl);
80          }
212 }
213
214 sub requestoption {
215        my $self=shift;
216        my $param=shift;
217        my $string=shift;
218
219        my $par=undef;
220        if ( defined $self->basequery()) {
221        $par=$self->basequery()->getparam($param);
222        while ( ! defined $par ) {
223          $self->basequery()->querytype( $param, "basic");
224          $self->basequery()->querymessage( $param, $string);
225          $self->userinterface()->askuser($self->basequery());
226          $par=$self->basequery()->getparam($param);
227        }
228        }
229        return $par;
230 }
231
232 sub getfile() {
233        my $self=shift;
234        my $origurl=shift;
235
236        my $fileref;
237        my ($url, $file)=$self->{urlhandler}->get($origurl);
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 247 | 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 264 | 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 281 | 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 303 | 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 < }
312 <
313 < sub checktag {
314 <        my $self=shift;
315 <        my $tagname=shift;
316 <        my $hashref=shift;
317 <        my $param=shift;
318 <
319 <        if ( ! exists $$hashref{$param} ) {
320 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
321 <        }
160 >         print $string."\n";
161 >         exit;
162 >        }
163   }
164  
165   sub line {
# Line 342 | 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 363 | Line 210 | sub Base_start {
210          # Keep track of base tags
211          push @{$self->{basestack}}, $$hashref{"type"};
212          # Set the base
366        print "BASE SET for ".$$hashref{"type"}."\n";
213          $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
368        print "BASE SET for ".$$hashref{"type"}."\n";
369
214   }
215  
216   sub Base_end {
# Line 375 | Line 219 | sub Base_end {
219          my $type;
220  
221          if ( $#{$self->{basestack}} == -1 ) {
222 <                print "Parse Error : unmatched </".$name."> on line ".
379 <                        $self->line()."\n";
380 <                die;
222 >                $self->parseerror("Parse Error : unmatched </$name>");
223          }
224          else {
225            $type = pop @{$self->{basestack}};
# Line 396 | Line 238 | sub Doc_Start {
238             $self->{docobject}=$$hashref{'type'};
239          }
240   }
399
400 sub userinterface {
401        my $self=shift;
402        @_?$self->{userinterface}=shift
403          :$self->{userinterface}
404 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines