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.6 by williamc, Fri Nov 19 15:27:46 1999 UTC vs.
Revision 1.25.2.1.2.3 by williamc, Mon Aug 21 15:32:21 2000 UTC

# Line 7 | Line 7
7   #
8   # Interface
9   # ---------
10 < # new()         : A new ActiveDoc object
10 > # new(cache,dbstore)            : A new ActiveDoc object
11   # url()         : Return/set the docs url - essential
12   # file()        : Return the local filename of document
13 + # ProcessFile() : Return the filename of PreProcessed document
14   #
15 < # 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
15 > # parent()         : return the object ref of the calling parent
16   # getfile(url)  : get a processedfile object given a url
17 < # config([ActiveConfig]) : Set up/return Configuration for the document
21 < # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
22 < # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
23 < # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
17 > # activatedoc(url) : Return the object ref for a doc described by the given url
18   #
19   # -- error methods --
20   # error(string)       : Report an general error to the user
21   # parseerror(string)  : Report an error during parsing a file
22 < # line()              : Return the current line number of the document
23 < #                       and the ProcessedFileObj it is in
22 > # line([linenumber])     : Return the line number of the document
23 > #                       and the ProcessedFileObj it is in corresponding to the
24 > #                       supplied number of the expanded document
25 > #                       If no number supplied - the currentparse number will be #                       used
26  
27   package ActiveDoc::ActiveDoc;
28   require 5.004;
29 < use ActiveDoc::Parse;
34 < use ActiveDoc::ActiveConfig;
29 > use ActiveDoc::SimpleURLDoc;
30   use ActiveDoc::PreProcessedFile;
31 < use ObjectUtilities::ObjectBase;
37 < use URL::URLhandler;
31 > use Utilities::Verbose;
32  
33 < @ISA = qw(ObjectUtilities::ObjectBase);
33 > @ISA = qw(ActiveDoc::SimpleURLDoc Utilities::Verbose);
34  
35   sub new {
36          my $class=shift;
37 <        $self={};
37 >        my $self={};
38          bless $self, $class;
39 <        $self->config(shift);
40 <        
41 <        # A URL handler per document
42 <        $self->{urlhandler}=URL::URLhandler->new($self->config()->cache());
49 <
50 <        $self->init(@_);
39 >        $self->cache(shift);
40 >        $self->{dbstore}=shift;
41 >        $self->_initdoc(@_);
42 > #       $self->{switch}=ActiveDoc::SimpleURLDoc->new($self->{cache});
43          return $self;
44   }
45  
54 # ----- parse related routines --------------
55 sub parse {
56        my $self=shift;
57        $parselabel=shift;
58
59        my $file=$self->file();
60        print "Parse called on file $file\n";
61        if ( $file ) {
62          $self->{parsers}{$parselabel}->parse($file,@_);
63        }
64        else {
65          print "Cannot parse - file not known\n";
66        }
67 }
68
69 sub newparse {
70        my $self=shift;
71        my $parselabel=shift;
72
73        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
74        $self->{parsers}{$parselabel}->addignoretags();
75        $self->{parsers}{$parselabel}->addgrouptags();
76 }
77
78 sub addtag {
79        my $self=shift;
80        my $parselabel=shift;
81        if ( $#_ != 6 ) {
82                $self->error("Incorrect addtags specification\n".
83                                "called with :\n@_ \n");
84        }
85        $self->{parsers}{$parselabel}->addtag(@_);
86 }
87
88 sub addurltags {
89        my $self=shift;
90        my $parselabel=shift;
91        
92        $self->{parsers}{$parselabel}->
93                addtag("Base", \&Base_start, $self, "", $self,
94                        \&Base_end, $self);
95 }
96
46   sub url {
47          my $self=shift;
48 <        @_ ?$self->{File}=$self->getfile(shift)
49 <            : $self->{File};
50 < }
51 <
52 < sub copydocconfig {
53 <        my $self=shift;
54 <        my $ActiveDoc=shift;
55 <        
56 <        $self->config($ActiveDoc->config());
108 <
109 < }
110 <
111 < sub copydocquery {
112 <        my $self=shift;
113 <        my $ActiveDoc=shift;
114 <
115 <         $self->basequery($ActiveDoc->basequery());
116 < }
117 <
118 < sub config {
119 <        my $self=shift;
120 <        @_?$self->{ActiveConfig}=shift
121 <           : $self->{ActiveConfig};
122 < }
123 <
124 < sub basequery {
125 <        my $self=shift;
126 <        @_ ? $self->{UserQuery}=shift
127 <           : $self->{UserQuery};
48 >        # get file & preprocess
49 >        if ( @_  ) {
50 >                $self->{File}=$self->getfile(shift);
51 >                $self->verbose("url downloaded to $self->{File}");
52 >        }
53 >        if ( defined $self->{File} ) {
54 >          return $self->{File}->url();
55 >        }
56 >        else { return "undefined"; }
57   }
58  
59 < sub getfile() {
59 > sub getfile {
60          my $self=shift;
61          my $origurl=shift;
62  
63          my $fileref;
64 <        print "GETFILE called\n";
65 <        my ($url, $file)=$self->{urlhandler}->get($origurl);
64 >        my ($url, $file);
65 >        if ( 0 ) {
66 >             $self->verbose("Forced download of $origurl");
67 >             ($url, $file)=$self->urldownload($origurl);
68 >        }
69 >        else {
70 >           $self->verbose("Attempting to get $origurl");
71 >           ($url, $file)=$self->urlget($origurl);
72 >        }
73          # do we already have an appropriate object?
74 <        #my ($fileref)=$self->config()->find("__preprocessed",$url);
139 <        undef $fileref;
74 >        ($fileref)=$self->{dbstore}->find($url);
75          if (  defined $fileref ) {
76 <         print "found $url in database ----\n";
76 >         $self->verbose("Found $url in database");
77           $fileref->update();
78          }
79          else {
80           if ( $file eq "" ) {
81             $self->parseerror("Unable to get $origurl");
82           }
83 <         #-- set up a new preprocess file
84 <         print "Making a new file $url----\n";
85 <         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
83 >         # -- set up a new preprocess file
84 >         $self->verbose("Making a new preprocessed file $url");
85 >         $fileref=ActiveDoc::PreProcessedFile->new($self->{cache},
86 >                                                        $self->{dbstore});
87           $fileref->url($url);
88           $fileref->update();
153         $self->config()->store($fileref,"__preprocessed",$url);
89          }
155        print "---------- returning".$fileref."\n";
90          return $fileref;
91   }
92  
93 < # -------- Error Handling and Error services --------------
93 > sub activatedoc {
94 >        my $self=shift;
95 >        my $url=shift;
96  
97 < sub error {
98 <        my $self=shift;
99 <        my $string=shift;
97 >        # first get a preprocessed copy of the file
98 >        my $fileobj=$self->getfile($url);
99 >
100 >        # now parse it for the <Doc> tag
101 >        my $tempdoc=ActiveDoc::SimpleURLDoc->new($self->{cache});
102 >        $tempdoc->filetoparse($fileobj->ProcessFile());
103 >        my ($doctype,$docversion)=$tempdoc->doctype();
104 >        undef $tempdoc;
105 >        
106 >        if ( ! defined $doctype ) {
107 >          $self->parseerror("No <Doc type=> Specified in ".$url);
108 >        }
109 >        $self->verbose("doctype required is $doctype $docversion");
110 >
111 >        # Set up a new object of the specified type
112 >        eval "require $doctype";
113 >        die $@ if $@;
114 >        my $newobj=$doctype->new($self->{cache},$self->{dbstore});
115 >        $newobj->url($url);
116 >        $newobj->parent($self);
117 >        return $newobj;
118 > }
119 >
120 > sub parent {
121 >        my $self=shift;
122  
123 <        die $string."\n";
123 >        @_?$self->{parent}=shift
124 >          :$self->{parent};
125   }
126  
127 + # -------- Error Handling and Error services --------------
128 +
129   sub parseerror {
130          my $self=shift;
131          my $string=shift;
132  
133 <        ($line, $file)=$self->line();
134 <        print "Parse Error in ".$file->url().", line ".
133 >        if ( $self->currentparsename() eq "" ) {
134 >                $self->error($string);
135 >        }
136 >        else {
137 >         ($line, $file)=$self->line();
138 >         print "Parse Error in ".$file->url().", line ".
139                                          $line."\n";
140 <        print $string."\n";
141 <        die;
140 >         print $string."\n";
141 >         exit;
142 >        }
143   }
144  
145 < sub checktag {
146 <        my $self=shift;
147 <        my $tagname=shift;
182 <        my $hashref=shift;
183 <        my $param=shift;
145 > sub line {
146 >        my $self=shift;
147 >        my $parseline;
148  
149 <        if ( ! exists $$hashref{$param} ) {
150 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
151 <        }
152 < }
149 >        if ( @_ ) {
150 >          $parseline=shift;
151 >        }
152 >        else {
153 >          $parseline=$self->{currentparser}->line();
154 >        }
155  
190 sub line {
191        $self=shift;
156          my ($line, $fileobj)=
157 <                $self->{Processedfile}->line($self->{switch}->line());
157 >                $self->{File}->realline($parseline);
158          return ($line, $fileobj);
159   }
160  
161 + sub tagstartline {
162 +        my $self=shift;
163 +        my ($line, $fileobj)=$self->{File}->line(
164 +                $self->{currentparser}->tagstartline());
165 +        return ($line, $fileobj);
166 + }
167 +
168   sub file {
169          my $self=shift;
170  
171 <        $self->{PPf}->file();
171 >        $self->{File}->file();
172   }
173  
174 < # --------------- Initialisation Methods ---------------------------
204 <
205 < sub preprocess_init {
174 > sub ProcessFile {
175          my $self=shift;
207        $self->{PPfile}=PreProcessedFile->new($self->config());
208 }
176  
177 < sub init {
211 <        # Dummy Routine - override for derived classes
177 >        return $self->{File}->ProcessedFile();
178   }
179  
214 # ------------------- Tag Routines -----------------------------------
180   #
181 < # Base - for setting url bases
181 > # Delegate all else to the switch
182   #
183 < sub Base_start {
184 <        my $self=shift;
220 <        my $name=shift;
221 <        my $hashref=shift;
183 > #sub AUTOLOAD {
184 > #        my $self=shift;
185  
186 <        $self->checktag($name, $hashref, 'type' );
187 <        $self->checktag($name, $hashref, 'base' );
225 <      
226 <        # Keep track of base tags
227 <        push @{$self->{basestack}}, $$hashref{"type"};
228 <        # Set the base
229 <        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
186 >        # dont propogate destroy methods
187 > #        return if $AUTOLOAD=~/::DESTROY/;
188  
189 < }
189 >        # remove this package name
190 > #        ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://;
191  
192 < sub Base_end {
193 <        my $self=shift;
194 <        my $name=shift;
236 <        my $type;
192 >        # pass the message to SimpleDoc
193 > #        $self->{switch}->$name(@_);
194 > #}
195  
196 <        if ( $#{$self->{basestack}} == -1 ) {
197 <                print "Parse Error : unmatched </".$name."> on line ".
198 <                        $self->line()."\n";
199 <                die;
200 <        }
201 <        else {
202 <          $type = pop @{$self->{basestack}};
203 <          $self->{urlhandler}->unsetbase($type);
204 <        }
196 >
197 > # ------------------- Tag Routines -----------------------------------
198 > sub Doc_Start {
199 >        my $self=shift;
200 >        my $name=shift;
201 >        my $hashref=shift;
202 >        
203 >        $self->checktag($name, $hashref, "type");
204 >        $self->{doctypefound}++;
205 >        if ( $self->{doctypefound} == 1 ) { # only take first doctype
206 >           $self->{docobject}=$$hashref{'type'};
207 >        }
208   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines