1 |
williamc |
1.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 |
williamc |
1.2 |
# new(store,query) : A new Application object
|
14 |
williamc |
1.1 |
# 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 |
williamc |
1.2 |
# newdoc(type) : Instantiate a new ActiveDoc
|
20 |
|
|
# object of the specified type
|
21 |
|
|
# find(@keys) : find an object in the activedoc objectdb
|
22 |
williamc |
1.1 |
|
23 |
|
|
package ActiveDoc::Application;
|
24 |
|
|
require 5.004;
|
25 |
|
|
use ActiveDoc::SimpleUserInterface;
|
26 |
|
|
|
27 |
|
|
sub new {
|
28 |
|
|
my $class=shift;
|
29 |
|
|
$self={};
|
30 |
|
|
bless $self, $class;
|
31 |
|
|
$self->{store}=shift;
|
32 |
williamc |
1.2 |
$self->{options}=shift;
|
33 |
williamc |
1.1 |
|
34 |
|
|
# make sure data is empty
|
35 |
|
|
undef $self->{StarterDoc};
|
36 |
|
|
undef $self->{UI};
|
37 |
|
|
|
38 |
williamc |
1.2 |
$self->_initdoc();
|
39 |
williamc |
1.1 |
return $self;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
sub store {
|
43 |
|
|
my $self=shift;
|
44 |
|
|
return $self->{store};
|
45 |
|
|
}
|
46 |
williamc |
1.2 |
|
47 |
|
|
sub find {
|
48 |
|
|
my $self=shift;
|
49 |
|
|
return ($self->{store}->find(@_));
|
50 |
|
|
}
|
51 |
|
|
|
52 |
williamc |
1.1 |
sub userinterface {
|
53 |
|
|
my $self=shift;
|
54 |
|
|
|
55 |
|
|
if ( @_ ) {
|
56 |
|
|
$self->{UI}=shift;
|
57 |
|
|
}
|
58 |
|
|
elsif ( ! defined $self->{UI} ) {
|
59 |
|
|
$self->{UI}=ActiveDoc::SimpleUserInterface->new();
|
60 |
|
|
}
|
61 |
|
|
return $self->{UI};
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
sub activatedoc {
|
65 |
|
|
my $self=shift;
|
66 |
|
|
my $url=shift;
|
67 |
|
|
|
68 |
|
|
# Create a new document
|
69 |
|
|
return $self->{StarterDoc}->activatedoc($url);
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
sub options {
|
73 |
|
|
my $self=shift;
|
74 |
|
|
|
75 |
|
|
if ( @_ ) {
|
76 |
|
|
$self->{options}=shift;
|
77 |
|
|
}
|
78 |
|
|
else {
|
79 |
|
|
(defined $self->{options})?$self->{options}:undef;
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
|
83 |
williamc |
1.2 |
sub newdoc {
|
84 |
|
|
my $self=shift;
|
85 |
|
|
my $type=shift;
|
86 |
|
|
|
87 |
|
|
return $type->new($self->{store},$self->{StarterDoc});
|
88 |
|
|
}
|
89 |
williamc |
1.1 |
|
90 |
|
|
# ---------------- private methods
|
91 |
|
|
sub _initdoc {
|
92 |
|
|
my $self=shift;
|
93 |
|
|
|
94 |
|
|
if ( ! defined $self->{StarterDoc} ) {
|
95 |
|
|
$self->{StarterDoc}=ActiveDoc::StarterDoc->new($self->{store},
|
96 |
|
|
$self->userinterface(),$self->options());
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|