ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/DOChandler.pm
Revision: 1.2
Committed: Thu Sep 23 10:35:41 1999 UTC (25 years, 7 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.1: +10 -2 lines
Log Message:
cont updates

File Contents

# User Rev Content
1 williamc 1.1 #
2     # The base ActiveDoc generator and support utility
3     # Create the appropriate object for a document given its url
4     # Class type determined by <DocType class=> tag
5     # Will create and return the pointer to the apporpriate object rather than
6     # itself.
7     #
8     # Interface
9     # ---------
10     # new(UserQuery) : Add a new DOChandler with a UserQuery
11     # UserQuery Parameters :
12     # cache -> cache directory
13     # UserInterface -> Set a User interface to use
14     # (default is that of the UserQuery)
15     #
16     # newdoc(filename) : Create an Object of the appropriate type for the
17     # document specified in filename
18     # defaultcache() : Return the default cache location
19     # inputvalue(param) : return the value of param as given by the
20     # initialising UserQuery
21     # asksingleinputvalue(param, string) : Query the user to supply a given input
22     # value the initialising UserQuery)
23    
24     package ActiveDoc::DOChandler;
25     require 5.001;
26    
27     use ActiveDoc::BaseTags;
28     use ActiveDoc::ActiveDoc;
29     use ActiveDoc::UserInterface_basic;
30     use ActiveDoc::UserQuery;
31     use ObjectStore;
32    
33     sub new {
34     my $class=shift;
35     my $UserQuery=shift;
36     my $cache=shift;
37    
38     $self={};
39     bless $self, $class;
40    
41     # set up data
42     $self->{UserQuery}=$UserQuery;
43     $self->{objectstore}=ObjectStore->new();
44     $self->{treenode}=ActiveDoc::TreeNode->new("/"); # create a root node
45     $self->{treenode}->setassociate($self);
46    
47     # set our cache area - and ask user if not
48     $self->{defaultcache}=$self->inputvalue('cache');
49     while ( ! defined $self->{defaultcache} ) {
50 williamc 1.2 $self->{UserQuery}->setquery( "basic", "cache");
51     $self->{UserQuery}->askuser(
52 williamc 1.1 "No cache directory Has Been Specified - Please enter a".
53     "suitable directory to use as a cache");
54 williamc 1.2 $self->setcache($self->{UserQuery}->getparam("cache"));
55 williamc 1.1 }
56    
57     # Determine the UserInterface
58     if ( ! defined $self->inputvalue('UserInterface') ) {
59     $self->{UserInterface}=$self->{UserQuery}->interface();
60     }
61     else {
62     $self->{UserInterface}=$self->inputvalue('UserInterface');
63     }
64    
65     return $self;
66 williamc 1.2 }
67    
68     sub setcache {
69     my $self=shift;
70     my $cache=shift;
71    
72     $self->{defaultcache}=$cache;
73 williamc 1.1 }
74    
75     sub newdoc {
76     my $self=shift;
77     my $filename=shift;
78    
79     # Set up the required service objects
80     $self->{base}=BaseTags->new($filename);
81     $self->{base}->{tags}->addtag("DocType", \&DocTypeTag, "", "");
82     $self->{base}->{gc}->include("doctype");
83     $self->{base}->{gc}->uninclude("all");
84     $self->{base}->{otherself}=$self;
85    
86     # Set up a parser and parse the File
87     $self->{base}->{tagfound}=0;
88     $self->{base}->parse();
89     if ( ! defined $self->{object} ) {
90     print "No <DocType type=> Specified in $filename\n";
91     exit 1;
92     }
93     undef $self->{base};
94     return $self->{object};
95     }
96    
97     sub addobj {
98     my $self=shift;
99    
100     # --- Add to our local objectstore
101     $self->{objectstore}->add(@_);
102    
103     # Now indicate weve found one
104     $self->{object}=shift;
105     }
106    
107     sub defaultcache {
108     my $self=shift;
109     return $self->{defaultcache};
110     }
111    
112     sub inputvalue {
113     my $self=shift;
114     my $value=shift;
115    
116     return $self->{UserQuery}->getparam($value);
117     }
118    
119     sub asksingleinputvalue {
120     my $self=shift;
121     my $param=shift;
122     my $string=shift;
123    
124     $self->{UserQuery}->clearquery();
125     $self->{UserQuery}->setquery('basic', $param, $string );
126     $self->{UserQuery}->askuser();
127     }
128    
129     # ------------------------------- Tag Routines --------------------------
130     #
131     # Check type and create object of appropriate type
132     #
133     # !! remember that $self refers to the base
134     #
135    
136     sub DocTypeTag {
137     my $self=shift;
138     my $name=shift;
139     my $hashref=shift;
140    
141     my $object;
142     my $res;
143    
144     # - Syntax Checking
145     $self->{switch}->checkparam($name, "type");
146    
147     # -- Check for default types - and convert
148     if ( $$hashref{type}=~/ActiveDoc/i ) {
149     $$hashref{type}="ActiveDoc::ActiveDoc";
150     }
151     $res = eval { eval "require $$hashref{type}"; };
152     if ( ! defined $res ) {
153     $self->report("Unknown Document Type : $$hashref{type}\n $@");
154     }
155    
156     # --- create an object of the appropriate type
157     $object=$$hashref{type}->new($self->{filename}, $self->{otherself});
158    
159     # --- store it in our Object Storage Facility
160     if ( defined $object ) {
161     $self->{otherself}->addobj(
162     $object, $$hashref{type}, $self->{otherself}->{url} );
163     }
164     else {
165     $self->report(
166     "Unable to Initialise Object of type $$hashref{type}");
167     }
168     }