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.1 by williamc, Fri Aug 20 09:09:28 1999 UTC vs.
Revision 1.25.2.1 by williamc, Wed May 17 13:59:42 2000 UTC

# Line 1 | Line 1
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, ObjectStoreCont): create a new object based on a file and
11 < #                                 associate with the given ObjectStoreCont
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
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 > # parent()         : return the object ref of the calling parent
17 > # getfile(url)  : get a processedfile object given a url
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::SimpleDoc;
34 > use URL::URLhandler;
35  
36 + @ISA = qw(ActiveDoc::SimpleDoc);
37  
38 < package ActiveDoc;
39 < use BaseTags;
40 < use DOChandler;
41 < use ObjectStoreCont;
38 > sub addurltags {
39 >        my $self=shift;
40 >        my $parselabel=shift;
41 >        
42 >        $self->{parsers}{$parselabel}->
43 >                addtag("Base", \&Base_start, $self, "", $self,
44 >                        \&Base_end, $self);
45 > }
46  
47 < @ISA = qw (BaseTags);
47 > sub url {
48 >        my $self=shift;
49 >        # get file & preprocess
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 < # Initialise
27 < sub _init {
60 > sub config {
61          my $self=shift;
62 <        my $OC=shift;
62 >        @_?$self->{ActiveConfig}=shift
63 >           : $self->{ActiveConfig};
64 > }
65 >
66 > sub getfile {
67 >        my $self=shift;
68 >        my $origurl=shift;
69  
70 <        $self->_addurl();
71 <        $self->{OC}=$OC;
72 <        $self->{treenode)=TreeNode->new();
73 <        $self->{includeOS}=$self->{OC}->newStore();
74 <        $self->{dochandler}=DOChandler->new($self->{includeOS});
75 <        # Add the minimal functionality tag - feel free to override
76 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
70 >        my $fileref;
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 >         $self->verbose("Found $url in database");
86 >         $fileref->update();
87 >        }
88 >        else {
89 >         if ( $file eq "" ) {
90 >           $self->parseerror("Unable to get $origurl");
91 >         }
92 >         #-- set up a new preprocess file
93 >         $self->verbose("Making a new preprocessed file $url");
94 >         $fileref=ActiveDoc::PreProcessedFile->new($self->config());
95 >         $fileref->url($url);
96 >         $fileref->update();
97 >        }
98 >        return $fileref;
99   }
100  
101 < #
102 < # Include mechanism
103 < #
104 < sub include {
105 <        my $self=shift;
106 <        my $url=shift;
46 <        my $obj;
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 <        $obj=$self->{dochandler}->newdoc($url);
109 <        # Now Extend our tree
110 <        $self->{treenode}->grow($obj->treenode());
111 <        return $obj;
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 treenode {
133 > sub parent {
134          my $self=shift;
135 <        return $self->treenode;
135 >
136 >        @_?$self->{parent}=shift
137 >          :$self->{parent};
138 > }
139 >
140 > # -------- Error Handling and Error services --------------
141 >
142 > sub error {
143 >        my $self=shift;
144 >        my $string=shift;
145 >
146 >        die $string."\n";
147   }
148  
149 < sub getincludeObjectStore {
149 > sub parseerror {
150          my $self=shift;
151 <        return $self->{includeOS};
151 >        my $string=shift;
152 >
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 >         exit;
162 >        }
163   }
164  
165 < sub find($) {
165 > sub line {
166          my $self=shift;
66        my $string=shift;
167  
168 <        $self->{treenode}->find($string);
168 >        my ($line, $fileobj)=
169 >                $self->{File}->realline($self->{currentparser}->line());
170 >        return ($line, $fileobj);
171   }
172  
173 < # ------------------------ Tag Routines ------------------------------
174 < #
175 < # A default Include tag
176 < #
177 < sub Include_Start {
178 <        my $returnval;
179 <        # Just call the basic - this is only a default wrapper for the
180 <        # <INCLUDE> tag assuming with no futher processing of the DOCObjref
181 <        $returnval=_includetag(@_)
182 <        # dont return anything if its a basic tag
173 > sub tagstartline {
174 >        my $self=shift;
175 >        my ($line, $fileobj)=$self->{File}->line(
176 >                $self->{currentparser}->tagstartline());
177 >        return ($line, $fileobj);
178 > }
179 >
180 > sub file {
181 >        my $self=shift;
182 >
183 >        $self->{File}->file();
184 > }
185 >
186 > sub ProcessFile {
187 >        my $self=shift;
188 >
189 >        return $self->{File}->ProcessedFile();
190   }
191  
192 < # ----------------------- Support Routines ---------------------------
192 > # --------------- Initialisation Methods ---------------------------
193 >
194 > sub init {
195 >        # Dummy Routine - override for derived classes
196 > }
197 >
198 > # ------------------- Tag Routines -----------------------------------
199   #
200 < # the real workings of the include tag returns the ref
200 > # Base - for setting url bases
201   #
202 < sub _includetag {
202 > sub Base_start {
203          my $self=shift;
204          my $name=shift;
205          my $hashref=shift;
206  
207 <        $self->{switch}->checkparam( $name, "ref");
208 <        $url=$$hashref{'ref'};
209 <        return $self->include($url);
207 >        $self->checktag($name, $hashref, 'type' );
208 >        $self->checktag($name, $hashref, 'base' );
209 >      
210 >        # Keep track of base tags
211 >        push @{$self->{basestack}}, $$hashref{"type"};
212 >        # Set the base
213 >        $self->{urlhandler}->setbase($$hashref{"type"},$hashref);
214 > }
215 >
216 > sub Base_end {
217 >        my $self=shift;
218 >        my $name=shift;
219 >        my $type;
220 >
221 >        if ( $#{$self->{basestack}} == -1 ) {
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