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.5 by williamc, Wed Sep 29 07:47:06 1999 UTC vs.
Revision 1.25.2.1.2.1 by williamc, Thu Aug 17 15:59:21 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, 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 > #                    -- any parse called "init" will also be run
19 > # userinterface()       : Return the defaullt userinterface
20 > #
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 > #
27  
28   package ActiveDoc::ActiveDoc;
29 < require 5.001;
30 < use ActiveDoc::DOChandler;
31 < use ActiveDoc::TreeNode;
32 < use ActiveDoc::UserQuery;
33 < use ObjectStoreCont;
34 <
35 < @ISA = qw(ActiveDoc::BaseTags);
29 > require 5.004;
30 > use ActiveDoc::SimpleURLDoc;
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->{switch}=ActiveDoc::SimpleURLDoc->new($self->{cache});
42 >        return $self;
43 > }
44 >
45 > sub url {
46 >        my $self=shift;
47 >        # get file & preprocess
48 >        if ( @_  ) {
49 >                $self->{File}=$self->getfile(shift);
50 >                $self->verbose("url downloaded to $self->{File}");
51 >        }
52 >        if ( defined $self->{File} ) {
53 >          return $self->{File}->url();
54 >        }
55 >        else { return "undefined"; }
56 > }
57  
58 < # Initialise
33 < sub _init {
58 > sub getfile {
59          my $self=shift;
60 <        my $DOChandler=shift;
36 <        my $OC=shift;
60 >        my $origurl=shift;
61  
62 <        $self->_addurl();
63 <        $self->{urlhandler}->setcache($DOChandler->defaultcache());
64 <        $self->{treenode}=ActiveDoc::TreeNode->new();
65 <        $self->{dochandler}=$DOChandler;
66 <        $self->{UserQuery}=$DOChandler->{UserQuery};
43 <        $self->{tags}->addtag("Use", \&Use_Start, "", "");
44 <        # Add the minimal functionality tag - feel free to override
45 <        $self->{tags}->addtag("Include", \&Include_Start, "", "");
46 <        $self->init();
47 < }
48 <
49 < sub init {
50 <        # Dummy Routine - override for derrived classes
51 < }
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;
61 <
62 <        $file=$self->{urlhandler}->get($url);
63 <        if ( ( defined $linkfile) && ( $linkfile ne "" ) ) {
64 <          $filename=$file."/".$linkfile;
62 >        my $fileref;
63 >        my ($url, $file);
64 >        if ( 0 ) {
65 >             $self->verbose("Forced download of $origurl");
66 >             ($url, $file)=$self->{switch}->urldownload($origurl);
67          }
68          else {
69 <          $filename=$file;
69 >           $self->verbose("Attempting to get $origurl");
70 >           ($url, $file)=$self->{switch}->urlget($origurl);
71          }
72 <        $obj=$self->{dochandler}->newdoc($filename);
73 <
74 <        # Now Extend our tree
75 <        $self->{treenode}->grow($obj->treenode());
76 <        return $obj;
72 >        # do we already have an appropriate object?
73 >        ($fileref)=$self->{dbstore}->find($url);
74 >        if (  defined $fileref ) {
75 >         $self->verbose("Found $url in database");
76 >         $fileref->update();
77 >        }
78 >        else {
79 >         if ( $file eq "" ) {
80 >           $self->parseerror("Unable to get $origurl");
81 >         }
82 >         # -- set up a new preprocess file
83 >         $self->verbose("Making a new preprocessed file $url");
84 >         $fileref=ActiveDoc::PreProcessedFile->new($self->{cache},
85 >                                                        $self->{dbstore});
86 >         $fileref->url($url);
87 >         $fileref->update();
88 >        }
89 >        return $fileref;
90   }
91  
92 < sub userinterface {
92 > sub activatedoc {
93          my $self=shift;
94 <        return $self->{dochandler}->{UserInterface};
94 >        my $url=shift;
95 >
96 >        # first get a preprocessed copy of the file
97 >        #my $fileob=$self->getfile($url);
98 >
99 >        # 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 >        }
107 >
108 >        # Set up a new object of the specified type
109 >        eval "require $doctype";
110 >        die $@ if $@;
111 >        my $newobj=$doctype->new($self->{cache},$self->{dbstore});
112 >        $newobj->url($url);
113 >        $newobj->parent($self);
114 >        return $newobj;
115   }
116  
117 < sub treenode {
117 > sub parent {
118          my $self=shift;
83        return $self->{treenode};
84 }
119  
120 < sub getincludeObjectStore {
121 <        my $self=shift;
88 <        return $self->{includeOS};
120 >        @_?$self->{parent}=shift
121 >          :$self->{parent};
122   }
123  
124 < sub find($) {
92 <        my $self=shift;
93 <        my $string=shift;
94 <        my $tn;
124 > # -------- Error Handling and Error services --------------
125  
126 <        $tn=$self->{treenode}->find($string);
127 <        if ( $tn eq "" ) {
128 <          $self->parseerror("Unable to find $string");
126 > sub parseerror {
127 >        my $self=shift;
128 >        my $string=shift;
129 >
130 >        if ( $self->currentparsename() eq "" ) {
131 >                $self->error($string);
132 >        }
133 >        else {
134 >         ($line, $file)=$self->line();
135 >         print "Parse Error in ".$file->url().", line ".
136 >                                        $line."\n";
137 >         print $string."\n";
138 >         exit;
139          }
100        return $tn->associate();
140   }
141  
142   sub line {
143          my $self=shift;
144 <        return $self->{switch}->line();
144 >
145 >        my ($line, $fileobj)=
146 >                $self->{File}->realline($self->{currentparser}->line());
147 >        return ($line, $fileobj);
148   }
149  
150 < sub error {
150 > sub tagstartline {
151          my $self=shift;
152 <        my $string=shift;
153 <
154 <        die $string."\n";
113 <
152 >        my ($line, $fileobj)=$self->{File}->line(
153 >                $self->{currentparser}->tagstartline());
154 >        return ($line, $fileobj);
155   }
156 < sub parseerror {
156 >
157 > sub file {
158          my $self=shift;
117        my $string=shift;
159  
160 <        print "Parse Error in $self->{url}, line ".
120 <                                        $self->line()."\n";
121 <        print $string."\n";
122 <        die;
160 >        $self->{File}->file();
161   }
162  
163 < sub checktag {
163 > sub ProcessFile {
164          my $self=shift;
127        my $hashref=shift;
128        my $param=shift;
129        my $tagname=shift;
165  
166 <        if ( ! exists $$hashref{$param} ) {
132 <          $self->parseerror("Incomplete Tag <$tagname> : $param required");  
133 <        }
166 >        return $self->{File}->ProcessedFile();
167   }
168  
136 # ------------------------ Tag Routines ------------------------------
169   #
170 < # The Include tag
170 > # Delegate all else to the switch
171   #
172 + sub AUTOLOAD {
173 +        my $self=shift;
174  
175 < sub Include_Start {
176 <        my $self=shift;
177 <        my $name=shift;
178 <        my $hashref=shift;
175 >        # dont propogate destroy methods
176 >        return if $AUTOLOAD=~/::DESTROY/;
177 >
178 >        # remove this package name
179 >        ($name=$AUTOLOAD)=~s/ActiveDoc::ActiveDoc:://;
180  
181 <        $self->{switch}->checkparam( $name, "ref");
182 <        print "<Include> tag not yet implemented\n";
148 < #        $self->include($$hashref{'ref'},$$hashref{'linkdoc'});
181 >        # pass the message to SimpleDoc
182 >        $self->{switch}->$name(@_);
183   }
184  
151 sub Use_Start {
152        my $self=shift;
153        my $name=shift;
154        my $hashref=shift;
185  
186 <        print "<Use> tag not yet implemented\n";
186 > # ------------------- Tag Routines -----------------------------------
187 > sub Doc_Start {
188 >        my $self=shift;
189 >        my $name=shift;
190 >        my $hashref=shift;
191 >        
192 >        $self->checktag($name, $hashref, "type");
193 >        $self->{doctypefound}++;
194 >        if ( $self->{doctypefound} == 1 ) { # only take first doctype
195 >           $self->{docobject}=$$hashref{'type'};
196 >        }
197   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines