ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm
Revision: 1.25.2.1.2.1
Committed: Thu Aug 17 15:59:21 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
Changes since 1.25.2.1: +40 -83 lines
Log Message:
Integrated to simpledoc from dev

File Contents

# User Rev Content
1 williamc 1.1 #
2 williamc 1.6 # ActiveDoc.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7 williamc 1.1 #
8     # Interface
9     # ---------
10 williamc 1.25.2.1.2.1 # new(cache,dbstore) : A new ActiveDoc object
11 williamc 1.6 # url() : Return/set the docs url - essential
12     # file() : Return the local filename of document
13 williamc 1.21 # ProcessFile() : Return the filename of PreProcessed document
14 williamc 1.6 #
15 williamc 1.21 # parent() : return the object ref of the calling parent
16 williamc 1.6 # getfile(url) : get a processedfile object given a url
17 williamc 1.9 # activatedoc(url) : Return the object ref for a doc described by the given url
18 williamc 1.14 # -- any parse called "init" will also be run
19 williamc 1.10 # userinterface() : Return the defaullt userinterface
20 williamc 1.6 #
21     # -- error methods --
22     # error(string) : Report an general error to the user
23     # parseerror(string) : Report an error during parsing a file
24     # line() : Return the current line number of the document
25     # and the ProcessedFileObj it is in
26 williamc 1.23 #
27 williamc 1.2
28     package ActiveDoc::ActiveDoc;
29 williamc 1.6 require 5.004;
30 williamc 1.25.2.1.2.1 use ActiveDoc::SimpleURLDoc;
31     use Utilities::Verbose;
32 williamc 1.6
33 williamc 1.25.2.1.2.1 @ISA = qw(Utilities::Verbose);
34 williamc 1.2
35 williamc 1.25.2.1.2.1 sub new {
36     my $class=shift;
37     my $self={};
38     bless $self, $class;
39     $self->{cache}=shift;
40     $self->{dbstore}=shift;
41     $self->{switch}=ActiveDoc::SimpleURLDoc->new($self->{cache});
42     return $self;
43 williamc 1.1 }
44    
45 williamc 1.6 sub url {
46 williamc 1.2 my $self=shift;
47 williamc 1.8 # get file & preprocess
48 williamc 1.21 if ( @_ ) {
49     $self->{File}=$self->getfile(shift);
50     $self->verbose("url downloaded to $self->{File}");
51     }
52 williamc 1.25 if ( defined $self->{File} ) {
53     return $self->{File}->url();
54     }
55     else { return "undefined"; }
56 williamc 1.2 }
57    
58 williamc 1.22 sub getfile {
59 williamc 1.3 my $self=shift;
60 williamc 1.6 my $origurl=shift;
61    
62     my $fileref;
63 williamc 1.20 my ($url, $file);
64 williamc 1.25.2.1.2.1 if ( 0 ) {
65 williamc 1.21 $self->verbose("Forced download of $origurl");
66 williamc 1.25.2.1.2.1 ($url, $file)=$self->{switch}->urldownload($origurl);
67 williamc 1.20 }
68     else {
69 williamc 1.21 $self->verbose("Attempting to get $origurl");
70 williamc 1.25.2.1.2.1 ($url, $file)=$self->{switch}->urlget($origurl);
71 williamc 1.20 }
72 williamc 1.6 # do we already have an appropriate object?
73 williamc 1.25.2.1.2.1 ($fileref)=$self->{dbstore}->find($url);
74 williamc 1.6 if ( defined $fileref ) {
75 williamc 1.20 $self->verbose("Found $url in database");
76 williamc 1.6 $fileref->update();
77     }
78     else {
79     if ( $file eq "" ) {
80     $self->parseerror("Unable to get $origurl");
81     }
82 williamc 1.25.2.1.2.1 # -- set up a new preprocess file
83 williamc 1.21 $self->verbose("Making a new preprocessed file $url");
84 williamc 1.25.2.1.2.1 $fileref=ActiveDoc::PreProcessedFile->new($self->{cache},
85     $self->{dbstore});
86 williamc 1.6 $fileref->url($url);
87     $fileref->update();
88     }
89     return $fileref;
90 williamc 1.3 }
91    
92 williamc 1.9 sub activatedoc {
93     my $self=shift;
94     my $url=shift;
95    
96     # first get a preprocessed copy of the file
97 williamc 1.25.2.1.2.1 #my $fileob=$self->getfile($url);
98 williamc 1.9
99 williamc 1.25.2.1.2.1 # now parse it for the <Doc> tag
100     my $tempdoc=ActiveDoc::SimpleURLDoc->new($self->{cache});
101     my ($doctype,$docversion)=$tempdoc->doctype();
102     undef $tempdoc;
103    
104     if ( ! defined $doctype ) {
105     $self->parseerror("No <Doc type=> Specified in ".$url);
106 williamc 1.9 }
107 williamc 1.25.2.1.2.1
108 williamc 1.9 # Set up a new object of the specified type
109 williamc 1.25.2.1.2.1 eval "require $doctype";
110 williamc 1.14 die $@ if $@;
111 williamc 1.25.2.1.2.1 my $newobj=$doctype->new($self->{cache},$self->{dbstore});
112 williamc 1.10 $newobj->url($url);
113 williamc 1.21 $newobj->parent($self);
114 williamc 1.9 return $newobj;
115     }
116    
117 williamc 1.21 sub parent {
118     my $self=shift;
119    
120     @_?$self->{parent}=shift
121     :$self->{parent};
122     }
123    
124 williamc 1.6 # -------- Error Handling and Error services --------------
125    
126     sub parseerror {
127     my $self=shift;
128     my $string=shift;
129    
130 williamc 1.20 if ( $self->currentparsename() eq "" ) {
131 williamc 1.18 $self->error($string);
132     }
133     else {
134     ($line, $file)=$self->line();
135     print "Parse Error in ".$file->url().", line ".
136 williamc 1.6 $line."\n";
137 williamc 1.18 print $string."\n";
138 williamc 1.20 exit;
139 williamc 1.18 }
140 williamc 1.6 }
141    
142     sub line {
143 williamc 1.7 my $self=shift;
144 williamc 1.9
145 williamc 1.6 my ($line, $fileobj)=
146 williamc 1.9 $self->{File}->realline($self->{currentparser}->line());
147 williamc 1.6 return ($line, $fileobj);
148 williamc 1.7 }
149    
150     sub tagstartline {
151     my $self=shift;
152 williamc 1.8 my ($line, $fileobj)=$self->{File}->line(
153 williamc 1.7 $self->{currentparser}->tagstartline());
154     return ($line, $fileobj);
155 williamc 1.3 }
156 williamc 1.6
157     sub file {
158 williamc 1.2 my $self=shift;
159    
160 williamc 1.8 $self->{File}->file();
161 williamc 1.21 }
162    
163     sub ProcessFile {
164     my $self=shift;
165    
166     return $self->{File}->ProcessedFile();
167 williamc 1.2 }
168    
169 williamc 1.1 #
170 williamc 1.25.2.1.2.1 # Delegate all else to the switch
171 williamc 1.1 #
172 williamc 1.25.2.1.2.1 sub AUTOLOAD {
173 williamc 1.6 my $self=shift;
174 williamc 1.2
175 williamc 1.25.2.1.2.1 # dont propogate destroy methods
176     return if $AUTOLOAD=~/::DESTROY/;
177 williamc 1.1
178 williamc 1.25.2.1.2.1 # remove this package name
179     ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://;
180 williamc 1.1
181 williamc 1.25.2.1.2.1 # pass the message to SimpleDoc
182     $self->{switch}->$name(@_);
183 williamc 1.9 }
184    
185 williamc 1.25.2.1.2.1
186     # ------------------- Tag Routines -----------------------------------
187 williamc 1.9 sub Doc_Start {
188     my $self=shift;
189     my $name=shift;
190     my $hashref=shift;
191    
192     $self->checktag($name, $hashref, "type");
193 williamc 1.10 $self->{doctypefound}++;
194     if ( $self->{doctypefound} == 1 ) { # only take first doctype
195     $self->{docobject}=$$hashref{'type'};
196     }
197 williamc 1.1 }