1 |
|
# |
2 |
< |
# The base functionality for the ActiveDocument - inherits from Basetags |
2 |
> |
# ActiveDoc.pm |
3 |
> |
# |
4 |
> |
# Originally Written by Christopher Williams |
5 |
> |
# |
6 |
> |
# Description |
7 |
|
# |
4 |
– |
# Inherits from BaseTags |
5 |
– |
# -------- |
8 |
|
# Interface |
9 |
|
# --------- |
10 |
< |
# new(filename, DOChandler): create a new object based on a file and |
11 |
< |
# associate with a base DOChandler |
12 |
< |
# parse() : parse the input file |
13 |
< |
# include(url) : Activate include file mechanism, returns the object ref if OK |
14 |
< |
# treenode() : return the associated TreeNode object reference |
15 |
< |
# getincludeObjectStore : Return a pointer to the ObectStore that contains all |
16 |
< |
# included objects |
17 |
< |
# find(string) : find the object reference related to string in the associated |
18 |
< |
# tree. Mechanism for getting object references |
19 |
< |
# _addgroup() : Add group functionality to document |
20 |
< |
# parseerror(String) : Report an error to the user |
21 |
< |
# userinterface() : return the default User Interface object |
22 |
< |
# checktag($hashref, param , tagname) : Check a hash returned from switcher |
23 |
< |
# for a given parameter |
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 |
> |
# 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 |
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([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.001; |
29 |
< |
use ActiveDoc::DOChandler; |
30 |
< |
use ActiveDoc::TreeNode; |
31 |
< |
use ActiveDoc::UserQuery; |
32 |
< |
use ObjectStoreCont; |
33 |
< |
|
34 |
< |
@ISA = qw(BaseTags); |
28 |
> |
require 5.004; |
29 |
> |
use ActiveDoc::SimpleURLDoc; |
30 |
> |
use ActiveDoc::PreProcessedFile; |
31 |
> |
use Utilities::Verbose; |
32 |
> |
|
33 |
> |
@ISA = qw(Utilities::Verbose); |
34 |
> |
|
35 |
> |
sub new { |
36 |
> |
my $class=shift; |
37 |
> |
my $self={}; |
38 |
> |
bless $self, $class; |
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 |
> |
|
46 |
> |
sub url { |
47 |
> |
my $self=shift; |
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 |
< |
# Initialise |
33 |
< |
sub _init { |
59 |
> |
sub getfile { |
60 |
|
my $self=shift; |
61 |
< |
my $DOChandler=shift; |
36 |
< |
my $OC=shift; |
61 |
> |
my $origurl=shift; |
62 |
|
|
63 |
< |
$self->_addurl(); |
64 |
< |
$self->{urlhandler}->setcache($DOChandler->defaultcache()); |
65 |
< |
$self->{treenode}=ActiveDoc::TreeNode->new(); |
66 |
< |
$self->{dochandler}=$DOChandler; |
67 |
< |
$self->{UserQuery}=$DOChandler->{UserQuery}; |
68 |
< |
$self->{tags}->addtag("Use", \&Use_Start, "", ""); |
69 |
< |
# Add the minimal functionality tag - feel free to override |
70 |
< |
$self->{tags}->addtag("Include", \&Include_Start, "", ""); |
71 |
< |
$self->init(); |
63 |
> |
my $fileref; |
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 |
> |
($fileref)=$self->{dbstore}->find($url); |
75 |
> |
if ( defined $fileref ) { |
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 |
> |
$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(); |
89 |
> |
} |
90 |
> |
return $fileref; |
91 |
|
} |
92 |
|
|
93 |
< |
sub init { |
94 |
< |
# Dummy Routine - override for derrived classes |
95 |
< |
} |
52 |
< |
# |
53 |
< |
# use mechanism |
54 |
< |
# |
55 |
< |
sub include { |
56 |
< |
my $self=shift; |
57 |
< |
my $url=shift; |
58 |
< |
my $linkfile=shift; |
59 |
< |
my $filename; |
60 |
< |
my $obj; |
93 |
> |
sub activatedoc { |
94 |
> |
my $self=shift; |
95 |
> |
my $url=shift; |
96 |
|
|
97 |
< |
$file=$self->{urlhandler}->get($url); |
98 |
< |
if ( $linkfile ne "" ) { |
64 |
< |
$filename=$file."/".$linkfile; |
65 |
< |
} |
66 |
< |
$obj=$self->{dochandler}->newdoc($filename); |
97 |
> |
# first get a preprocessed copy of the file |
98 |
> |
my $fileobj=$self->getfile($url); |
99 |
|
|
100 |
< |
# Now Extend our tree |
101 |
< |
$self->{treenode}->grow($obj->treenode()); |
102 |
< |
return $obj; |
103 |
< |
} |
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 |
< |
sub userinterface { |
112 |
< |
my $self=shift; |
113 |
< |
return $self->{dochandler}->{UserInterface}; |
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 treenode { |
120 |
> |
sub parent { |
121 |
|
my $self=shift; |
122 |
< |
return $self->{treenode}; |
122 |
> |
|
123 |
> |
@_?$self->{parent}=shift |
124 |
> |
:$self->{parent}; |
125 |
|
} |
126 |
|
|
127 |
< |
sub getincludeObjectStore { |
127 |
> |
# -------- Error Handling and Error services -------------- |
128 |
> |
|
129 |
> |
sub parseerror { |
130 |
|
my $self=shift; |
131 |
< |
return $self->{includeOS}; |
131 |
> |
my $string=shift; |
132 |
> |
|
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 |
> |
exit; |
142 |
> |
} |
143 |
|
} |
144 |
|
|
145 |
< |
sub find($) { |
145 |
> |
sub line { |
146 |
|
my $self=shift; |
147 |
< |
my $string=shift; |
91 |
< |
my $tn; |
147 |
> |
my $parseline; |
148 |
|
|
149 |
< |
$tn=$self->{treenode}->find($string); |
150 |
< |
if ( $tn eq "" ) { |
151 |
< |
$self->parseerror("Unable to find $string"); |
149 |
> |
if ( @_ ) { |
150 |
> |
$parseline=shift; |
151 |
> |
} |
152 |
> |
else { |
153 |
> |
$parseline=$self->{currentparser}->line(); |
154 |
|
} |
155 |
< |
return $tn->associate(); |
155 |
> |
|
156 |
> |
my ($line, $fileobj)= |
157 |
> |
$self->{File}->realline($parseline); |
158 |
> |
return ($line, $fileobj); |
159 |
|
} |
160 |
|
|
161 |
< |
sub parseerror { |
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; |
102 |
– |
my $string=shift; |
170 |
|
|
171 |
< |
print "Parse Error in $self->{url}, line $self-{switch}->line()\n"; |
105 |
< |
print $string."\n"; |
106 |
< |
die; |
171 |
> |
$self->{File}->file(); |
172 |
|
} |
173 |
|
|
174 |
< |
sub checktag { |
174 |
> |
sub ProcessFile { |
175 |
|
my $self=shift; |
111 |
– |
my $hashref=shift; |
112 |
– |
my $param=shift; |
113 |
– |
my $tagname=shift; |
176 |
|
|
177 |
< |
if ( ! exists $$hashref{$param} ) { |
116 |
< |
$self->parseerror("Incomplete Tag <$tagname> : $param required"); |
117 |
< |
} |
177 |
> |
return $self->{File}->ProcessedFile(); |
178 |
|
} |
179 |
|
|
120 |
– |
# ------------------------ Tag Routines ------------------------------ |
180 |
|
# |
181 |
< |
# The Include tag |
181 |
> |
# Delegate all else to the switch |
182 |
|
# |
183 |
+ |
#sub AUTOLOAD { |
184 |
+ |
# my $self=shift; |
185 |
|
|
186 |
< |
sub Include_Start { |
187 |
< |
my $self=shift; |
127 |
< |
my $name=shift; |
128 |
< |
my $hashref=shift; |
186 |
> |
# dont propogate destroy methods |
187 |
> |
# return if $AUTOLOAD=~/::DESTROY/; |
188 |
|
|
189 |
< |
$self->{switch}->checkparam( $name, "ref"); |
190 |
< |
print "<Include> tag not yet implemented\n"; |
132 |
< |
# $self->include($$hashref{'ref'},$$hashref{'linkdoc'}); |
133 |
< |
} |
189 |
> |
# remove this package name |
190 |
> |
# ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://; |
191 |
|
|
192 |
< |
sub Use_Start { |
193 |
< |
my $self=shift; |
194 |
< |
my $name=shift; |
138 |
< |
my $hashref=shift; |
192 |
> |
# pass the message to SimpleDoc |
193 |
> |
# $self->{switch}->$name(@_); |
194 |
> |
#} |
195 |
|
|
196 |
< |
print "<Use> tag not yet implemented\n"; |
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 |
|
} |