ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/DOChandler.pm
Revision: 1.5
Committed: Thu Dec 8 15:43:43 2005 UTC (19 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -0 lines
State: FILE REMOVED
Log Message:
Obsolete packages removed.

File Contents

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