1 |
#____________________________________________________________________
|
2 |
# File: ActiveDoc::SimpleXMLURLDoc.pm
|
3 |
#____________________________________________________________________
|
4 |
#
|
5 |
# Author: Shaun Ashby <Shaun.Ashby@cern.ch>
|
6 |
# Update: 2005-12-02 17:44:08+0100
|
7 |
# Revision: $Id: SimpleXMLURLDoc.pm,v 1.7.2.1 2007/01/24 13:24:17 sashby Exp $
|
8 |
#
|
9 |
# Copyright: 2005 (C) Shaun Ashby
|
10 |
#
|
11 |
#--------------------------------------------------------------------
|
12 |
|
13 |
=head1 NAME
|
14 |
|
15 |
ActiveDoc::SimpleXMLURLDoc - Base class for URL-based SCRAM documents.
|
16 |
|
17 |
=head1 SYNOPSIS
|
18 |
|
19 |
my $obj = ActiveDoc::SimpleXMLURLDoc->new();
|
20 |
|
21 |
=head1 DESCRIPTION
|
22 |
|
23 |
Any document class inheriting from ActiveDoc::SimpleXMLURLDoc will have access to
|
24 |
URL handling.
|
25 |
|
26 |
=head1 METHODS
|
27 |
|
28 |
=over
|
29 |
|
30 |
=cut
|
31 |
|
32 |
package ActiveDoc::SimpleXMLURLDoc;
|
33 |
|
34 |
BEGIN
|
35 |
{
|
36 |
die "\n\n".__PACKAGE__.": this package can be dropped from releases.\n\n";
|
37 |
}
|
38 |
|
39 |
use ActiveDoc::SimpleXMLDoc;
|
40 |
use URL::URLhandler;
|
41 |
require 5.004;
|
42 |
use Exporter;
|
43 |
use vars qw(@ISA);
|
44 |
|
45 |
@ISA=qw(Exporter ActiveDoc::SimpleXMLDoc);
|
46 |
@EXPORT_OK=qw( );
|
47 |
|
48 |
sub new()
|
49 |
{
|
50 |
###############################################################
|
51 |
# new #
|
52 |
###############################################################
|
53 |
# modified : Fri Dec 2 17:44:11 2005 / SFA #
|
54 |
# params : #
|
55 |
# : #
|
56 |
# function : #
|
57 |
# : #
|
58 |
###############################################################
|
59 |
my $proto=shift;
|
60 |
my $class=ref($proto) || $proto;
|
61 |
my ($urlcache,$context,@defhandlers)=@_;
|
62 |
my $self= bless($proto->SUPER::new($context,@defhandlers),$class);
|
63 |
$self->{CONTEXT}=$context;
|
64 |
# Register supported tags for this doc class, and specify which
|
65 |
# attributes should be checked for:
|
66 |
my $nested = 1;
|
67 |
my $unnested = 0;
|
68 |
my %recognised_tags = ('base' => [ { 'url' => 'REQUIRED' }, $nested ],
|
69 |
'download' => [ { 'url' => 'REQUIRED', 'name' => 'OPTION' }, $unnested ]);
|
70 |
|
71 |
# Register these recognised tags to the base class (which registers them
|
72 |
# to the container class):
|
73 |
$self->register_handlers_(\%recognised_tags);
|
74 |
|
75 |
# Set up a URL cache:
|
76 |
$self->cache($urlcache);
|
77 |
return $self;
|
78 |
}
|
79 |
|
80 |
sub cache
|
81 |
{
|
82 |
my $self=shift;
|
83 |
|
84 |
if ( @_ )
|
85 |
{
|
86 |
$self->{cache}=shift;
|
87 |
$self->urlhandler_(URL::URLhandler->new($self->{cache}));
|
88 |
}
|
89 |
|
90 |
return $self->{cache};
|
91 |
}
|
92 |
|
93 |
sub expandurl
|
94 |
{
|
95 |
my $self=shift;
|
96 |
my $urlstring=shift;
|
97 |
return $self->urlhandler_()->expandurl($urlstring);
|
98 |
}
|
99 |
|
100 |
sub urldownload
|
101 |
{
|
102 |
my $self=shift;
|
103 |
my $urlstring=shift;
|
104 |
my ($fullurl,$filename)=$self->urlhandler_()->download($urlstring, @_);
|
105 |
|
106 |
if ( ( ! defined $filename ) || ( $filename eq "" ) )
|
107 |
{
|
108 |
$self->parseerror("Failed to get $fullurl");
|
109 |
}
|
110 |
|
111 |
return ($fullurl,$filename);
|
112 |
}
|
113 |
|
114 |
sub urlget
|
115 |
{
|
116 |
my $self=shift;
|
117 |
my $urlstring=shift;
|
118 |
my ($fullurl,$filename)=$self->urlhandler_()->get($urlstring, @_);
|
119 |
|
120 |
if ( ( ! defined $filename ) || ( $filename eq "" ) )
|
121 |
{
|
122 |
$self->parseerror("Failed to get $fullurl");
|
123 |
}
|
124 |
|
125 |
return ($fullurl,$filename);
|
126 |
}
|
127 |
|
128 |
sub setbaseurl()
|
129 |
{
|
130 |
my $self=shift;
|
131 |
my ($partialurl)=@_;
|
132 |
return $self->urlhandler_()->setbase($partialurl);
|
133 |
}
|
134 |
|
135 |
sub unsetbaseurl()
|
136 |
{
|
137 |
my $self=shift;
|
138 |
my ($type)=@_;
|
139 |
$self->urlhandler_()->unsetbase($type);
|
140 |
}
|
141 |
|
142 |
sub urlhandler_()
|
143 |
{
|
144 |
my $self=shift;
|
145 |
@_ ? $self->{urlhandler} = shift
|
146 |
: $self->{urlhandler};
|
147 |
}
|
148 |
|
149 |
sub parseerror()
|
150 |
{
|
151 |
my $self=shift;
|
152 |
my ($string)=@_;
|
153 |
die "Error in download: ",$string,"\n";
|
154 |
}
|
155 |
|
156 |
1;
|
157 |
|
158 |
=back
|
159 |
|
160 |
=head1 AUTHOR/MAINTAINER
|
161 |
|
162 |
Shaun ASHBY
|
163 |
|
164 |
=cut
|