1 |
#
|
2 |
# Easy Setup of cache etc for ActiveDoc enactivation
|
3 |
#
|
4 |
# Author : C.Williams
|
5 |
#
|
6 |
# Interface
|
7 |
# ---------
|
8 |
# new(location) : Create a new activeation area at location
|
9 |
# activatedoc($url) : Return the object corresponding to the activedoc
|
10 |
# provided by the url
|
11 |
# get(url) : download url and return the filename
|
12 |
# of the processed doc
|
13 |
|
14 |
package ActiveDoc::Activate;
|
15 |
use ActiveDoc::ActiveDoc;
|
16 |
use ActiveDoc::ActiveStore;
|
17 |
use Utilities::Verbose;
|
18 |
|
19 |
@ISA=qw(Utilities::Verbose);
|
20 |
|
21 |
|
22 |
sub new {
|
23 |
my $class=shift;
|
24 |
my $self={};
|
25 |
bless $self, $class;
|
26 |
|
27 |
# -- initiate cgi work area
|
28 |
$self->{workarea}=shift;
|
29 |
$self->_initarea($self->{workarea});
|
30 |
return $self;
|
31 |
}
|
32 |
|
33 |
sub _initarea {
|
34 |
my $self=shift;
|
35 |
my $dir=shift;
|
36 |
$self->{dbstore}=ActiveDoc::ActiveStore->new($dir);
|
37 |
$self->{ad}=ActiveDoc::ActiveDoc->new($self->{dbstore});
|
38 |
}
|
39 |
|
40 |
sub get {
|
41 |
my $self=shift;
|
42 |
my $url=shift;
|
43 |
$self->verbose("Attempt to get $url");
|
44 |
my $file;
|
45 |
# We dont want it messaging
|
46 |
require FileHandle;
|
47 |
local (*FHOLD);
|
48 |
local (*FHOLDERR);
|
49 |
# - copy STDERR and STDOUT
|
50 |
open(FHOLD,">&STDOUT");
|
51 |
open(FHOLDERR,">&STDERR");
|
52 |
|
53 |
# - redirect STDERR and STDOUT
|
54 |
my $rfile="/tmp/$$";
|
55 |
$self->verbose("Redirecting STDOUT to $rfile");
|
56 |
open(STDOUT, ">".$rfile) || die "Unable to open $!\n";
|
57 |
open(STDERR, ">&STDOUT") || die "Unable to open $!\n";
|
58 |
|
59 |
# -- call
|
60 |
my @rv=();
|
61 |
eval { $file=$self->{ad}->getfile($url)->ProcessedFile() };
|
62 |
if ( (! defined $file) || ($file eq "") ) {
|
63 |
push @rv, (undef,$rfile);
|
64 |
}
|
65 |
else {
|
66 |
push @rv, ($file,$rfile);
|
67 |
}
|
68 |
close STDOUT;
|
69 |
close STDERR;
|
70 |
|
71 |
# -- restore STDOUT & STDERR
|
72 |
open(STDOUT, ">&FHOLD");
|
73 |
open(STDERR, ">&FHOLDERR");
|
74 |
close FHOLD;
|
75 |
close FHOLDERR;
|
76 |
|
77 |
$self->verbose("Redirection Finnished of STDOUT");
|
78 |
return (@rv);
|
79 |
}
|
80 |
|
81 |
sub activatedoc {
|
82 |
my $self=shift;
|
83 |
my $url=shift;
|
84 |
|
85 |
my $obj;
|
86 |
$self->verbose("Attempting activation of $url");
|
87 |
if ( eval { $obj=$self->{ad}->activatedoc($url) } ) {
|
88 |
return ($obj, $@);
|
89 |
}
|
90 |
else {
|
91 |
return (undef, $@);
|
92 |
}
|
93 |
}
|