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.9 by williamc, Mon Nov 29 17:32:14 1999 UTC vs.
Revision 1.25.2.1.2.5 by williamc, Mon Aug 21 18:02:49 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 < # checktag(tagname, hashref, param) : check for existence of param in
19 < #                                       hashref from a tag call
20 < # 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   # activatedoc(url) : Return the object ref for a doc described by the given url
23 # config([ActiveConfig]) : Set up/return Configuration for the document
24 # basequery([ActiveConfig]) : Set up/return UserQuery for the doc
25 # copydocconfig(ActiveDoc) : Copy the basic configuration from the ActiveDoc
26 # copydocquery(ActiveDoc) : Copy the basicquery from the ActiveDoc
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;
37 < use ActiveDoc::ActiveConfig;
29 > use ActiveDoc::SimpleURLDoc;
30   use ActiveDoc::PreProcessedFile;
31 < use ObjectUtilities::ObjectBase;
40 < 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());
52 <
53 <        $self->init(@_);
39 >        $self->cache(shift);
40 >        $self->{dbstore}=shift;
41 >        $self->_initdoc("doc",@_);
42 > #       $self->{switch}=ActiveDoc::SimpleURLDoc->new($self->{cache});
43          return $self;
44   }
45  
57 # ----- parse related routines --------------
58 sub parse {
59        my $self=shift;
60        $parselabel=shift;
61
62        my $file=$self->file();
63        if ( $file ) {
64          $self->{currentparser}=$self->{parsers}{$parselabel};
65          $self->{parsers}{$parselabel}->parse($file,@_);
66          delete $self->{currentparser};
67        }
68        else {
69          print "Cannot parse - file not known\n";
70        }
71 }
72
73 sub newparse {
74        my $self=shift;
75        my $parselabel=shift;
76
77        $self->{parsers}{$parselabel}=ActiveDoc::Parse->new();
78        $self->{parsers}{$parselabel}->addignoretags();
79        $self->{parsers}{$parselabel}->addgrouptags();
80 }
81
82 sub addtag {
83        my $self=shift;
84        my $parselabel=shift;
85        if ( $#_ != 6 ) {
86                $self->error("Incorrect addtags specification\n".
87                                "called with :\n@_ \n");
88        }
89        $self->{parsers}{$parselabel}->addtag(@_);
90 }
91
92 sub addurltags {
93        my $self=shift;
94        my $parselabel=shift;
95        
96        $self->{parsers}{$parselabel}->
97                addtag("Base", \&Base_start, $self, "", $self,
98                        \&Base_end, $self);
99 }
100
46   sub url {
47          my $self=shift;
48          # get file & preprocess
49 <        if ( @_  ) {$self->{File}=$self->getfile(shift)}
50 <        $self->{File}->url();
51 < }
52 <
53 < sub copydocconfig {
54 <        my $self=shift;
55 <        my $ActiveDoc=shift;
56 <        
57 <        $self->config($ActiveDoc->config());
58 <
114 < }
115 <
116 < sub copydocquery {
117 <        my $self=shift;
118 <        my $ActiveDoc=shift;
119 <
120 <         $self->basequery($ActiveDoc->basequery());
121 < }
122 <
123 < sub config {
124 <        my $self=shift;
125 <        @_?$self->{ActiveConfig}=shift
126 <           : $self->{ActiveConfig};
127 < }
128 <
129 < sub basequery {
130 <        my $self=shift;
131 <        @_ ? $self->{UserQuery}=shift
132 <           : $self->{UserQuery};
49 >        if ( @_  ) {
50 >                $self->{origurl}=shift;
51 >                $self->{File}=$self->getfile($self->{origurl});
52 >                $self->filetoparse($self->{File}->ProcessedFile());
53 >                $self->verbose("url downloaded to ".$self->{File}->ProcessedFile());
54 >        }
55 >        if ( defined $self->{File} ) {
56 >          return $self->{File}->url();
57 >        }
58 >        else { return "undefined"; }
59   }
60  
61 < sub getfile() {
61 > sub getfile {
62          my $self=shift;
63          my $origurl=shift;
64  
65          my $fileref;
66 <        my ($url, $file)=$self->{urlhandler}->get($origurl);
66 >        my ($url, $file);
67 >        if ( 0 ) {
68 >             $self->verbose("Forced download of $origurl");
69 >             ($url, $file)=$self->urldownload($origurl);
70 >        }
71 >        else {
72 >           $self->verbose("Attempting to get $origurl");
73 >           ($url, $file)=$self->urlget($origurl);
74 >        }
75          # do we already have an appropriate object?
76 <        ($fileref)=$self->config()->find($url);
143 <        #undef $fileref;
76 >        ($fileref)=$self->{dbstore}->find($url);
77          if (  defined $fileref ) {
78 <         print "found $url in database ----\n";
78 >         $self->verbose("Found $url in database");
79           $fileref->update();
80          }
81          else {
82           if ( $file eq "" ) {
83             $self->parseerror("Unable to get $origurl");
84           }
85 <         #-- set up a new preprocess file
86 <         print "Making a new file $url----\n";
87 <         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
85 >         # -- set up a new preprocess file
86 >         $self->verbose("Making a new preprocessed file $url");
87 >         $fileref=ActiveDoc::PreProcessedFile->new($self->{cache},
88 >                                                        $self->{dbstore});
89           $fileref->url($url);
90           $fileref->update();
91          }
# Line 163 | Line 97 | sub activatedoc {
97          my $url=shift;
98  
99          # first get a preprocessed copy of the file
100 <        my $fileob=$self->getfile($url);
100 >        my $fileobj=$self->getfile($url);
101  
102 <        # now parse it for the <DocType> tag
103 <        $self->newparse("doctype");
104 <        $self->addtag("doctype","Doc", \&Doc_Start, $self,
105 <                                          "", $self, "", $self);
106 <        $self->parse("doctype");
107 <
108 <        if ( ! defined $self->{docobject} ) {
109 <          print "No <Doc type=> Specified in ".$fileob->url()."\n";
176 <          exit 1;
102 >        # now parse it for the <Doc> tag
103 >        my $tempdoc=ActiveDoc::SimpleURLDoc->new($self->{cache});
104 >        $tempdoc->filetoparse($fileobj->ProcessFile());
105 >        my ($doctype,$docversion)=$tempdoc->doctype();
106 >        undef $tempdoc;
107 >        
108 >        if ( ! defined $doctype ) {
109 >          $self->parseerror("No <Doc type=> Specified in ".$url);
110          }
111 +        $self->verbose("doctype required is $doctype $docversion");
112 +
113          # Set up a new object of the specified type
114 <        my $newobj=$self->{docobject}->new($self->config());
114 >        eval "require $doctype";
115 >        die $@ if $@;
116 >        my $newobj=$doctype->new($self->{cache},$self->{dbstore});
117 >        $newobj->url($url);
118 >        $newobj->parent($self);
119          return $newobj;
120   }
121  
122 < # -------- Error Handling and Error services --------------
123 <
185 < sub error {
186 <        my $self=shift;
187 <        my $string=shift;
122 > sub parent {
123 >        my $self=shift;
124  
125 <        die $string."\n";
125 >        @_?$self->{parent}=shift
126 >          :$self->{parent};
127   }
128  
129 + # -------- Error Handling and Error services --------------
130 +
131   sub parseerror {
132          my $self=shift;
133          my $string=shift;
134  
135 <        ($line, $file)=$self->line();
136 <        print "Parse Error in ".$file->url().", line ".
135 >        if ( $self->currentparsename() eq "" ) {
136 >                $self->error($string);
137 >        }
138 >        elsif ( ! defined $self->{File} ) {
139 >         print "Parse Error in ".$self->filenameref()." line "
140 >                                .$self->{currentparser}->line()."\n";
141 >         print $string."\n";
142 >        }
143 >        else {
144 >         ($line, $file)=$self->line();
145 >         print "Parse Error in ".$file->url().", line ".
146                                          $line."\n";
147 <        print $string."\n";
148 <        die;
149 < }
202 <
203 < sub checktag {
204 <        my $self=shift;
205 <        my $tagname=shift;
206 <        my $hashref=shift;
207 <        my $param=shift;
208 <
209 <        print keys %$hashref;
210 <        print "-----------------------------------\n";
211 <        if ( ! exists $$hashref{$param} ) {
212 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");
213 <        }
147 >         print $string."\n";
148 >        }
149 >        exit;
150   }
151  
152   sub line {
153          my $self=shift;
154 +        my $parseline;
155 +
156 +        if ( @_ ) {
157 +          $parseline=shift;
158 +        }
159 +        else {
160 +          $parseline=$self->{currentparser}->line();
161 +        }
162  
163          my ($line, $fileobj)=
164 <                $self->{File}->realline($self->{currentparser}->line());
164 >                $self->{File}->realline($parseline);
165          return ($line, $fileobj);
166   }
167  
# Line 234 | Line 178 | sub file {
178          $self->{File}->file();
179   }
180  
181 < # --------------- Initialisation Methods ---------------------------
181 > sub ProcessFile {
182 >        my $self=shift;
183  
184 < sub init {
240 <        # Dummy Routine - override for derived classes
184 >        return $self->{File}->ProcessedFile();
185   }
186  
243 # ------------------- Tag Routines -----------------------------------
187   #
188 < # Base - for setting url bases
188 > # Delegate all else to the switch
189   #
190 < sub Base_start {
191 <        my $self=shift;
249 <        my $name=shift;
250 <        my $hashref=shift;
190 > #sub AUTOLOAD {
191 > #        my $self=shift;
192  
193 <        $self->checktag($name, $hashref, 'type' );
194 <        $self->checktag($name, $hashref, 'base' );
254 <      
255 <        # Keep track of base tags
256 <        push @{$self->{basestack}}, $$hashref{"type"};
257 <        # Set the base
258 <        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
193 >        # dont propogate destroy methods
194 > #        return if $AUTOLOAD=~/::DESTROY/;
195  
196 < }
196 >        # remove this package name
197 > #        ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://;
198  
199 < sub Base_end {
200 <        my $self=shift;
201 <        my $name=shift;
265 <        my $type;
199 >        # pass the message to SimpleDoc
200 > #        $self->{switch}->$name(@_);
201 > #}
202  
267        if ( $#{$self->{basestack}} == -1 ) {
268                print "Parse Error : unmatched </".$name."> on line ".
269                        $self->line()."\n";
270                die;
271        }
272        else {
273          $type = pop @{$self->{basestack}};
274          $self->{urlhandler}->unsetbase($type);
275        }
276 }
203  
204 + # ------------------- Tag Routines -----------------------------------
205   sub Doc_Start {
206          my $self=shift;
207          my $name=shift;
208          my $hashref=shift;
209          
210          $self->checktag($name, $hashref, "type");
211 <        $self->{docobject}=$$hashref{'type'};
211 >        $self->{doctypefound}++;
212 >        if ( $self->{doctypefound} == 1 ) { # only take first doctype
213 >           $self->{docobject}=$$hashref{'type'};
214 >        }
215   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines