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.13 by williamc, Fri Jan 14 18:49:57 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 < # 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
19 > #                    -- any parse called "init" will also be run
20   # userinterface()       : Return the defaullt userinterface
21 < # options(var)          : return the value of the option var
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;
42 < use ActiveDoc::ActiveConfig;
43 < use ActiveDoc::PreProcessedFile;
44 < use ObjectUtilities::StorableObject;
33 > use ActiveDoc::SimpleDoc;
34   use URL::URLhandler;
35  
36 < @ISA = qw(ObjectUtilities::StorableObject);
48 <
49 < sub new {
50 <        my $class=shift;
51 <        $self={};
52 <        bless $self, $class;
53 <        $self->config(shift);
54 <        
55 <        # A URL handler per document
56 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
57 <
58 <        # A default UserInterface
59 <        $self->{userinterface}=ActiveDoc::SimpleUserInterface->new();
60 <        $self->init(@_);
61 <        return $self;
62 < }
63 <
64 < # ----- parse related routines --------------
65 < sub parse {
66 <        my $self=shift;
67 <        $parselabel=shift;
68 <
69 <        my $file=$self->file();
70 <        if ( $file ) {
71 <          $self->{currentparsename}=$parselabel;
72 <          $self->{currentparser}=$self->{parsers}{$parselabel};
73 <          $self->{parsers}{$parselabel}->parse($file,@_);
74 <          delete $self->{currentparser};
75 <          $self->{currentparsename}="";
76 <        }
77 <        else {
78 <          print "Cannot parse - file not known\n";
79 <        }
80 < }
81 <
82 < sub currentparsename {
83 <        my $self=shift;
84 <        @_?$self->{currentparsename}=shift
85 <          :$self->{currentparsename};
86 < }
87 <
88 < sub newparse {
89 <        my $self=shift;
90 <        my $parselabel=shift;
91 <
92 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
93 <        $self->{parsers}{$parselabel}->addignoretags();
94 <        $self->{parsers}{$parselabel}->addgrouptags();
95 < }
96 <
97 < sub cleartags {
98 <        my $self=shift;
99 <        my $parselabel=shift;
100 <
101 <        $self->{parsers}{$parselabel}->cleartags();
102 < }
103 <
104 <
105 < sub includeparse {
106 <        my $self=shift;
107 <        my $parselabel=shift;
108 <        my $remoteparselabel=shift;
109 <        my $activedoc=shift;
110 <
111 <        # Some error trapping
112 <        if ( ! exists $self->{parsers}{$parselabel} ) {
113 <          $self->error("Unknown local parse name specified");
114 <        }
115 <        if ( ! exists $activedoc->{parsers}{$remoteparselabel} ) {
116 <          $self->error("Unknown parse name specified in remote obj $activedoc");
117 <        }
118 <
119 <        #
120 <        my $rp=$activedoc->{parsers}{$remoteparselabel};
121 <        $self->{parsers}{$parselabel}->includeparse($rp);
122 < }
123 <
124 < sub addtag {
125 <        my $self=shift;
126 <        my $parselabel=shift;
127 <        if ( $#_ != 6 ) {
128 <                $self->error("Incorrect addtags specification\n".
129 <                                "called with :\n@_ \n");
130 <        }
131 <        $self->{parsers}{$parselabel}->addtag(@_);
132 < }
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37  
38   sub addurltags {
39          my $self=shift;
# Line 143 | 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 <        
154 <        $self->config($ActiveDoc->config());
155 <
156 < }
157 <
158 < sub copydocquery {
159 <        my $self=shift;
160 <        my $ActiveDoc=shift;
161 <
162 <         $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 168 | Line 63 | sub config {
63             : $self->{ActiveConfig};
64   }
65  
66 < sub basequery {
172 <        my $self=shift;
173 <        @_ ? $self->{Query}=shift
174 <           : $self->{Query};
175 < }
176 <
177 < sub options {
178 <        my $self=shift;
179 <        my $param=shift;
180 <        $self->basequery()->getparam('option_'.$param);
181 < }
182 <
183 < 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 198 | 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 211 | Line 103 | sub activatedoc {
103          my $url=shift;
104  
105          # first get a preprocessed copy of the file
106 <        my $fileob=$self->getfile($url);
106 > #       my $fileob=$self->getfile($url);
107  
108          # now parse it for the <DocType> tag
109 <        $self->{doctypefound}=0;
110 <        $self->newparse("doctype");
111 <        $self->addtag("doctype","Doc", \&Doc_Start, $self,
112 <                                          "", $self, "", $self);
113 <        $self->parse("doctype");
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 $self->{docobject} ) {
120 <          print "No <Doc type=> Specified in ".$fileob->url()."\n";
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 <        my $newobj=$self->{docobject}->new($self->config());
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 parent {
134 +        my $self=shift;
135 +
136 +        @_?$self->{parent}=shift
137 +          :$self->{parent};
138 + }
139 +
140   # -------- Error Handling and Error services --------------
141  
142   sub error {
# Line 243 | 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 < }
252 <
253 < sub checktag {
254 <        my $self=shift;
255 <        my $tagname=shift;
256 <        my $hashref=shift;
257 <        my $param=shift;
258 <
259 <        if ( ! exists $$hashref{$param} ) {
260 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
261 <        }
160 >         print $string."\n";
161 >         exit;
162 >        }
163   }
164  
165   sub line {
# Line 282 | 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 304 | Line 211 | sub Base_start {
211          push @{$self->{basestack}}, $$hashref{"type"};
212          # Set the base
213          $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
307
214   }
215  
216   sub Base_end {
# Line 313 | Line 219 | sub Base_end {
219          my $type;
220  
221          if ( $#{$self->{basestack}} == -1 ) {
222 <                print "Parse Error : unmatched </".$name."> on line ".
317 <                        $self->line()."\n";
318 <                die;
222 >                $self->parseerror("Parse Error : unmatched </$name>");
223          }
224          else {
225            $type = pop @{$self->{basestack}};
# Line 334 | Line 238 | sub Doc_Start {
238             $self->{docobject}=$$hashref{'type'};
239          }
240   }
337
338 sub userinterface {
339        my $self=shift;
340        @_?$self->{userinterface}=shift
341          :$self->{userinterface}
342 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines