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.19 by williamc, Thu Jan 27 17:50:38 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
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
26 # config([ActiveConfig]) : Set up/return Configuration for the document
27 # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
28 # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
29 # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
20   # userinterface()       : Return the defaullt userinterface
21 < # option(var)           : return the value of the option var
32 < # requestoption("message") : Ask the user to supply a value for an option
33 < #                            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;
44 < use ActiveDoc::ActiveConfig;
45 < use ActiveDoc::PreProcessedFile;
46 < use ObjectUtilities::StorableObject;
33 > use ActiveDoc::SimpleDoc;
34   use URL::URLhandler;
35  
36 < @ISA = qw(ObjectUtilities::StorableObject);
50 <
51 < sub new {
52 <        my $class=shift;
53 <        $self={};
54 <        bless $self, $class;
55 <        $self->config(shift);
56 <
57 <        # have some override options been passed
58 <        if ( @_ ) {
59 <           $self->basequery(shift);
60 <        }
61 <        else {
62 <           # --- is there a starter document?
63 <           my $basedoc=$self->config()->basedoc();
64 <           if ( defined $basedoc ) {
65 <             $self->copydocquery($basedoc);
66 <           }
67 <           else {
68 <             $self->error("ActiveDoc Error : No base doc found");
69 <           }
70 <        }
71 <        $self->_init2();
72 < }
73 <
74 < sub _init2 {
75 <
76 <        my $self=shift;
77 <        # A URL handler per document
78 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
79 <
80 <        # A default UserInterface
81 <        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
82 <        $self->init(@_);
83 <        return $self;
84 <
85 < }
86 <
87 < # ----- parse related routines --------------
88 < sub parse {
89 <        my $self=shift;
90 <        $parselabel=shift;
91 <
92 <        my $file=$self->file();
93 <        if ( $file ) {
94 <          if ( exists $self->{parsers}{$parselabel} ) {
95 <            $self->{currentparsename}=$parselabel;
96 <            $self->{currentparser}=$self->{parsers}{$parselabel};
97 <            $self->{parsers}{$parselabel}->parse($file,@_);
98 <            delete $self->{currentparser};
99 <            $self->{currentparsename}="";
100 <          }
101 <        }
102 <        else {
103 <          print "Cannot parse - file not known\n";
104 <        }
105 < }
106 <
107 < sub currentparsename {
108 <        my $self=shift;
109 <        @_?$self->{currentparsename}=shift
110 <          :$self->{currentparsename};
111 < }
112 <
113 < sub newparse {
114 <        my $self=shift;
115 <        my $parselabel=shift;
116 <
117 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
118 <        $self->{parsers}{$parselabel}->addignoretags();
119 <        $self->{parsers}{$parselabel}->addgrouptags();
120 < }
121 <
122 < sub cleartags {
123 <        my $self=shift;
124 <        my $parselabel=shift;
125 <
126 <        $self->{parsers}{$parselabel}->cleartags();
127 < }
128 <
129 <
130 < sub includeparse {
131 <        my $self=shift;
132 <        my $parselabel=shift;
133 <        my $remoteparselabel=shift;
134 <        my $activedoc=shift;
135 <
136 <        # Some error trapping
137 <        if ( ! exists $self->{parsers}{$parselabel} ) {
138 <          $self->error("Unknown local parse name specified");
139 <        }
140 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
141 <          $self->error("Unknown parse name specified in remote obj $activedoc");
142 <        }
143 <
144 <        #
145 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
146 <        $self->{parsers}{$parselabel}->includeparse($rp);
147 < }
148 <
149 < sub addtag {
150 <        my $self=shift;
151 <        my $parselabel=shift;
152 <        if ( $#_ != 6 ) {
153 <                $self->error("Incorrect addtags specification\n".
154 <                                "called with :\n@_ \n");
155 <        }
156 <        $self->{parsers}{$parselabel}->addtag(@_);
157 < }
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37  
38   sub addurltags {
39          my $self=shift;
# Line 168 | 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;
177 <        my $ActiveDoc=shift;
178 <        
179 <        $self->config($ActiveDoc->config());
180 <
181 < }
182 <
183 < sub copydocquery {
184 <        my $self=shift;
185 <        my $ActiveDoc=shift;
186 <
187 <        if ( defined $ActiveDoc->basequery() ) {
188 <          $self->basequery($ActiveDoc->basequery());
189 <        }
190 <        else {
191 <          $self->error("Cannot copy basequery - undefined");
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 198 | Line 63 | sub config {
63             : $self->{ActiveConfig};
64   }
65  
66 < sub basequery {
66 > sub getfile {
67          my $self=shift;
68 <        @_ ? $self->{Query}=shift
204 <           : $self->{Query};
205 <        return $self->{Query};
206 < }
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;
79 <        }
217 < }
218 <
219 < sub requestoption {
220 <        my $self=shift;
221 <        my $param=shift;
222 <        my $string=shift;
223 <
224 <        my $par=undef;
225 <        if ( defined $self->basequery()) {
226 <        $par=$self->basequery()->getparam($param);
227 <        while ( ! defined $par ) {
228 <          $self->basequery()->querytype( $param, "basic");
229 <          $self->basequery()->querymessage( $param, $string);
230 <          $self->userinterface()->askuser($self->basequery());
231 <          $par=$self->basequery()->getparam($param);
232 <        }
78 >           $self->verbose("Attempting to get $origurl");
79 >           ($url, $file)=$self->{urlhandler}->get($origurl);
80          }
234        return $par;
235 }
236
237 sub getfile() {
238        my $self=shift;
239        my $origurl=shift;
240
241        my $fileref;
242        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 252 | 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 288 | 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 310 | Line 150 | sub parseerror {
150          my $self=shift;
151          my $string=shift;
152  
153 <        if ( ! defined $self->{currentparse} ) {
153 >        if ( $self->currentparsename() eq "" ) {
154                  $self->error($string);
155          }
156          else {
# Line 318 | Line 158 | sub parseerror {
158           print "Parse Error in ".$file->url().", line ".
159                                          $line."\n";
160           print $string."\n";
161 <         die;
161 >         exit;
162          }
163   }
164  
325 sub checktag {
326        my $self=shift;
327        my $tagname=shift;
328        my $hashref=shift;
329        my $param=shift;
330
331        if ( ! exists $$hashref{$param} ) {
332          $self->parseerror("Incomplete Tag <$tagname> : $param required");
333        }
334 }
335
165   sub line {
166          my $self=shift;
167  
# Line 354 | 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 403 | Line 238 | sub Doc_Start {
238             $self->{docobject}=$$hashref{'type'};
239          }
240   }
406
407 sub userinterface {
408        my $self=shift;
409        @_?$self->{userinterface}=shift
410          :$self->{userinterface}
411 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines