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.2.2 by williamc, Mon Aug 21 15:19:49 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(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.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 < package ActiveDoc;
60 < use BaseTags;
61 < use DOChandler;
22 < use ObjectStoreCont;
59 > sub getfile {
60 >        my $self=shift;
61 >        my $origurl=shift;
62  
63 < @ISA = qw (BaseTags);
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 < # Initialise
27 < sub _init {
93 > sub activatedoc {
94          my $self=shift;
95 <        my $OC=shift;
95 >        my $url=shift;
96 >
97 >        # first get a preprocessed copy of the file
98 >        my $fileobj=$self->getfile($url);
99  
100 <        $self->_addurl();
101 <        $self->{OC}=$OC;
102 <        $self->{treenode)=TreeNode->new();
103 <        $self->{includeOS}=$self->{OC}->newStore();
104 <        $self->{dochandler}=DOChandler->new($self->{includeOS});
105 <        # Add the minimal functionality tag - feel free to override
106 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
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 < #
121 < # Include mechanism
122 < #
123 < sub include {
120 > sub parent {
121 >        my $self=shift;
122 >
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 $url=shift;
46 <        my $obj;
131 >        my $string=shift;
132  
133 <        $obj=$self->{dochandler}->newdoc($url);
134 <        # Now Extend our tree
135 <        $self->{treenode}->grow($obj->treenode());
136 <        return $obj;
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 treenode {
145 > sub line {
146          my $self=shift;
147 <        return $self->treenode;
147 >        my $parseline;
148 >
149 >        if ( @_ ) {
150 >          $parseline=shift;
151 >        }
152 >        else {
153 >          $parseline=$self->{currentparser}->line();
154 >        }
155 >
156 >        my ($line, $fileobj)=
157 >                $self->{File}->realline($parseline);
158 >        return ($line, $fileobj);
159   }
160  
161 < sub getincludeObjectStore {
162 <        my $self=shift;
163 <        return $self->{includeOS};
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 find($) {
168 > sub file {
169          my $self=shift;
66        my $string=shift;
170  
171 <        $self->{treenode}->find($string);
171 >        $self->{File}->file();
172   }
173  
174 < # ------------------------ Tag Routines ------------------------------
175 < #
176 < # A default Include tag
177 < #
75 < sub Include_Start {
76 <        my $returnval;
77 <        # Just call the basic - this is only a default wrapper for the
78 <        # <INCLUDE> tag assuming with no futher processing of the DOCObjref
79 <        $returnval=_includetag(@_)
80 <        # dont return anything if its a basic tag
174 > sub ProcessFile {
175 >        my $self=shift;
176 >
177 >        return $self->{File}->ProcessedFile();
178   }
179  
83 # ----------------------- Support Routines ---------------------------
180   #
181 < # the real workings of the include tag returns the ref
181 > # Delegate all else to the switch
182   #
183 < sub _includetag {
184 <        my $self=shift;
89 <        my $name=shift;
90 <        my $hashref=shift;
183 > #sub AUTOLOAD {
184 > #        my $self=shift;
185  
186 <        $self->{switch}->checkparam( $name, "ref");
187 <        $url=$$hashref{'ref'};
188 <        return $self->include($url);
189 < }
186 >        # dont propogate destroy methods
187 > #        return if $AUTOLOAD=~/::DESTROY/;
188 >
189 >        # remove this package name
190 > #        ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://;
191 >
192 >        # pass the message to SimpleDoc
193 > #        $self->{switch}->$name(@_);
194 > #}
195  
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