ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleURLDoc.pm
Revision: 1.1.2.3
Committed: Wed Aug 9 13:52:17 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
Changes since 1.1.2.2: +9 -0 lines
Log Message:
add expandurl method

File Contents

# Content
1 #
2 # SimpleURLDoc.pm. - Extends SimpleDoc with URL download functionality
3 #
4 # Originally Written by Christopher Williams
5 #
6 # Description
7 # -----------
8 #
9 # Interface
10 # ---------
11 # new(URLcache) : A new SimpleURLDoc object
12 # addbasetags(parse) : Add Base Tags to the given parse
13 # urlget(urlstring[,location]) : get the given url. Returns (url, filename)
14 # expandurl(urlstring) : return a URLclass object of the given url expanded
15 # according to the base settings
16 # cache([cache]) : get/set the current URL cache
17
18 package ActiveDoc::SimpleURLDoc;
19 use ActiveDoc::SimpleDoc;
20 use URL::URLhandler;
21 require 5.001;
22
23 sub new {
24 my $class=shift;
25 my $self={};
26 bless $self, $class;
27 $self->cache(shift);
28 $self->{switch}=ActiveDoc::SimpleDoc->new();
29 return $self;
30 }
31
32 sub addbasetags {
33 my $self=shift;
34 my $parse=shift;
35
36 $self->{switch}->addtag($parse,"base", \&Base_start, $self,
37 "", $self,
38 \&Base_end,$self);
39 }
40
41 sub cache {
42 my $self=shift;
43 if ( @_ ) {
44 $self->{cache}=shift;
45 $self->{urlhandler}=URL::URLhandler->new($self->{cache});
46 }
47 return $self->{cache};
48 }
49
50 sub expandurl {
51 my $self=shift;
52 my $urlstring=shift;
53
54 return $self->{urlhandler}->expandurl($urlstring);
55 }
56
57 sub urlget {
58 my $self=shift;
59 my $urlstring=shift;
60
61 ($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
62 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
63 $self->{switch}->parseerror("Failed to get $fullurl");
64 }
65 return ($fullurl,$filename);
66 }
67
68 sub AUTOLOAD {
69 my $self=shift;
70
71 # dont propogate destroy methods
72 return if $AUTOLOAD=~/::DESTROY/;
73
74 # remove this package name
75 ($name=$AUTOLOAD)=~s/ActiveDoc::SimpleURLDoc:://;
76
77 # pass the message to SimpleDoc
78 $self->{switch}->$name(@_);
79 }
80
81 # ------------------------ Support Routines ---------------------------
82
83 # ------------------------ Tag Routines -------------------------------
84
85 sub Base_start {
86 my $self=shift;
87 my $name=shift;
88 my $hashref=shift;
89
90 $self->{switch}->checktag($name, $hashref, "url");
91 my $url=$self->{urlhandler}->setbase($$hashref{'url'});
92 push @{$self->{basestack}}, $url->type();
93 }
94
95 sub Base_end {
96 my $self=shift;
97 if ( $#{$self->{basestack}} >= 0 ) {
98 my $type=pop @{$self->{basestack}};
99 $self->{urlhandler}->unsetbase($type);
100 }
101 else {
102 $self->{switch}->parseerror("Unmatched <$name>");
103 }
104 }
105