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.8 by williamc, Tue Nov 23 17:31:10 1999 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 < # 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 < # config([ActiveConfig]) : Set up/return Configuration for the document
19 < # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
20 < # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
21 < # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
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.004;
33 < use ActiveDoc::Parse;
34 < use ActiveDoc::ActiveConfig;
35 < use ActiveDoc::PreProcessedFile;
36 < use ObjectUtilities::ObjectBase;
33 > use ActiveDoc::SimpleDoc;
34   use URL::URLhandler;
35  
36 < @ISA = qw(ObjectUtilities::ObjectBase);
40 <
41 < sub new {
42 <        my $class=shift;
43 <        $self={};
44 <        bless $self, $class;
45 <        $self->config(shift);
46 <        
47 <        # A URL handler per document
48 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
49 <
50 <        $self->init(@_);
51 <        return $self;
52 < }
53 <
54 < # ----- parse related routines --------------
55 < sub parse {
56 <        my $self=shift;
57 <        $parselabel=shift;
58 <
59 <        my $file=$self->file();
60 <        if ( $file ) {
61 <          $self->{currentparser}=$self->{parsers}{$parselabel};
62 <          $self->{parsers}{$parselabel}->parse($file,@_);
63 <          delete $self->{currentparser};
64 <        }
65 <        else {
66 <          print "Cannot parse - file not known\n";
67 <        }
68 < }
69 <
70 < sub newparse {
71 <        my $self=shift;
72 <        my $parselabel=shift;
73 <
74 <        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
75 <        $self->{parsers}{$parselabel}->addignoretags();
76 <        $self->{parsers}{$parselabel}->addgrouptags();
77 < }
78 <
79 < sub addtag {
80 <        my $self=shift;
81 <        my $parselabel=shift;
82 <        if ( $#_ != 6 ) {
83 <                $self->error("Incorrect addtags specification\n".
84 <                                "called with :\n@_ \n");
85 <        }
86 <        $self->{parsers}{$parselabel}->addtag(@_);
87 < }
36 > @ISA = qw(ActiveDoc::SimpleDoc);
37  
38   sub addurltags {
39          my $self=shift;
# Line 98 | 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 <        
109 <        $self->config($ActiveDoc->config());
110 <
111 < }
112 <
113 < sub copydocquery {
114 <        my $self=shift;
115 <        my $ActiveDoc=shift;
116 <
117 <         $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 123 | Line 63 | sub config {
63             : $self->{ActiveConfig};
64   }
65  
66 < sub basequery {
127 <        my $self=shift;
128 <        @_ ? $self->{UserQuery}=shift
129 <           : $self->{UserQuery};
130 < }
131 <
132 < 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 147 | 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 155 | Line 98 | sub getfile() {
98          return $fileref;
99   }
100  
101 + sub activatedoc {
102 +        my $self=shift;
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 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 168 | 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 < }
177 <
178 < sub checktag {
179 <        my $self=shift;
180 <        my $tagname=shift;
181 <        my $hashref=shift;
182 <        my $param=shift;
183 <
184 <        if ( ! exists $$hashref{$param} ) {
185 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
186 <        }
160 >         print $string."\n";
161 >         exit;
162 >        }
163   }
164  
165   sub line {
166          my $self=shift;
167 +
168          my ($line, $fileobj)=
169 <                $self->{File}->line($self->{currentparser}->line());
169 >                $self->{File}->realline($self->{currentparser}->line());
170          return ($line, $fileobj);
171   }
172  
# Line 206 | 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 228 | Line 211 | sub Base_start {
211          push @{$self->{basestack}}, $$hashref{"type"};
212          # Set the base
213          $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
231
214   }
215  
216   sub Base_end {
# Line 237 | Line 219 | sub Base_end {
219          my $type;
220  
221          if ( $#{$self->{basestack}} == -1 ) {
222 <                print "Parse Error : unmatched </".$name."> on line ".
241 <                        $self->line()."\n";
242 <                die;
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