1 |
#
|
2 |
# Application.pm
|
3 |
#
|
4 |
# Originally Written by Christopher Williams
|
5 |
#
|
6 |
# Description
|
7 |
# -----------
|
8 |
# Sets up the basic Activedoc Structure - and provides applications with
|
9 |
# facilities to BootStrap an activedoc
|
10 |
#
|
11 |
# Interface
|
12 |
# ---------
|
13 |
# new(store,[query]) : A new Application object
|
14 |
# activatedoc(url[,options]) : return the oref of a doc corresponding
|
15 |
# to the url
|
16 |
# userinterface([IntObj]) : set/get user interface object - defaults
|
17 |
# to SimpleUserInterface if not overridden
|
18 |
# store() : return the store
|
19 |
# newdoc(type) : Instantiate a new ActiveDoc
|
20 |
# object of the specified type
|
21 |
# find(@keys) : find an object in the activedoc objectdb
|
22 |
# options() : Get/Set the options object - make one if
|
23 |
# not already provided
|
24 |
# setoption(name,value) : set an option in the current base options
|
25 |
|
26 |
package ActiveDoc::Application;
|
27 |
require 5.004;
|
28 |
use ActiveDoc::SimpleUserInterface;
|
29 |
|
30 |
sub new {
|
31 |
my $class=shift;
|
32 |
$self={};
|
33 |
bless $self, $class;
|
34 |
$self->{store}=shift;
|
35 |
if ( @_ ) {
|
36 |
$self->options(shift);
|
37 |
}
|
38 |
|
39 |
# make sure data is empty
|
40 |
undef $self->{StarterDoc};
|
41 |
undef $self->{UI};
|
42 |
|
43 |
$self->_initdoc();
|
44 |
return $self;
|
45 |
}
|
46 |
|
47 |
sub store {
|
48 |
my $self=shift;
|
49 |
return $self->{store};
|
50 |
}
|
51 |
|
52 |
sub find {
|
53 |
my $self=shift;
|
54 |
return ($self->{store}->find(@_));
|
55 |
}
|
56 |
|
57 |
sub userinterface {
|
58 |
my $self=shift;
|
59 |
|
60 |
if ( @_ ) {
|
61 |
$self->{UI}=shift;
|
62 |
}
|
63 |
elsif ( ! defined $self->{UI} ) {
|
64 |
$self->{UI}=ActiveDoc::SimpleUserInterface->new();
|
65 |
}
|
66 |
return $self->{UI};
|
67 |
}
|
68 |
|
69 |
sub activatedoc {
|
70 |
my $self=shift;
|
71 |
my $url=shift;
|
72 |
|
73 |
# Create a new document
|
74 |
return $self->{StarterDoc}->activatedoc($url);
|
75 |
}
|
76 |
|
77 |
sub setoption {
|
78 |
my $self=shift;
|
79 |
|
80 |
$self->options()->setparam(@_);
|
81 |
}
|
82 |
|
83 |
sub options {
|
84 |
my $self=shift;
|
85 |
|
86 |
if ( @_ ) {
|
87 |
$self->{options}=shift;
|
88 |
}
|
89 |
elsif ( ! defined $self->{options}) {
|
90 |
$self->{options}=ActiveDoc::Query->new();
|
91 |
}
|
92 |
return $self->{options};
|
93 |
}
|
94 |
|
95 |
sub newdoc {
|
96 |
my $self=shift;
|
97 |
my $type=shift;
|
98 |
|
99 |
return $type->new($self->{store},$self->{StarterDoc}->basequery());
|
100 |
}
|
101 |
|
102 |
# ---------------- private methods
|
103 |
sub _initdoc {
|
104 |
my $self=shift;
|
105 |
|
106 |
if ( ! defined $self->{StarterDoc} ) {
|
107 |
$self->{StarterDoc}=ActiveDoc::StarterDoc->new($self->{store},
|
108 |
$self->userinterface(),$self->options());
|
109 |
}
|
110 |
}
|
111 |
|