ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/DOChandler.pm
Revision: 1.3
Committed: Fri Dec 17 08:36:23 1999 UTC (25 years, 4 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: v102p1, V1_0_1, V1_0_0, V1_pre0, SCRAM_V1, SCRAMV1_IMPORT, V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1, V0_19_0, V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2, V0_18_1, ProtoEnd
Branch point for: V1_pre1, SCRAM_V1_BRANCH, V0_19_4_B
Changes since 1.2: +6 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 $self->{UserQuery}->setquery( "basic", "cache");
51 $self->{UserQuery}->askuser(
52 "No cache directory Has Been Specified - Please enter a".
53 "suitable directory to use as a cache");
54 $self->setcache($self->{UserQuery}->getparam("cache"));
55 }
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 }
67
68 sub setcache {
69 my $self=shift;
70 my $cache=shift;
71
72 $self->{defaultcache}=$cache;
73 }
74
75 sub newdoc {
76 my $self=shift;
77 my $filename=shift;
78
79 # Set up the required service objects
80 $self->{base}=ActiveDoc::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 my $obj=shift;
100
101 # --- Add to our local objectstore
102 #$self->{objectstore}->add(@_);
103
104 # Now indicate weve found one
105 $self->{object}=$obj;
106 }
107
108 sub defaultcache {
109 my $self=shift;
110 return $self->{defaultcache};
111 }
112
113 sub inputvalue {
114 my $self=shift;
115 my $value=shift;
116
117 return $self->{UserQuery}->getparam($value);
118 }
119
120 sub asksingleinputvalue {
121 my $self=shift;
122 my $param=shift;
123 my $string=shift;
124
125 $self->{UserQuery}->clearquery();
126 $self->{UserQuery}->setquery('basic', $param, $string );
127 $self->{UserQuery}->askuser();
128 }
129
130 # ------------------------------- Tag Routines --------------------------
131 #
132 # Check type and create object of appropriate type
133 #
134 # !! remember that $self refers to the base
135 #
136
137 sub DocTypeTag {
138 my $self=shift;
139 my $name=shift;
140 my $hashref=shift;
141
142 my $object;
143 my $res;
144
145 # - Syntax Checking
146 $self->{switch}->checkparam($name, "type");
147
148 # -- Check for default types - and convert
149 if ( $$hashref{type}=~/ActiveDoc/i ) {
150 $$hashref{type}="ActiveDoc::ActiveDoc";
151 }
152 $res = eval { eval "require $$hashref{type}"; };
153 if ( ! defined $res ) {
154 $self->report("Unknown Document Type : $$hashref{type}\n $@");
155 }
156
157 # --- create an object of the appropriate type
158 $object=$$hashref{type}->new($self->{filename}, $self->{otherself});
159
160 # --- store it in our Object Storage Facility
161 if ( defined $object ) {
162 $self->{otherself}->addobj(
163 $object, $$hashref{type}, $self->{otherself}->{url} );
164 }
165 else {
166 $self->report(
167 "Unable to Initialise Object of type $$hashref{type}");
168 }
169 }