ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleURLDoc.pm
Revision: 1.1.2.6
Committed: Mon Aug 21 15:19:50 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: BuildSystemProto1, V0_18_0, V0_18_0model, V0_17_1, V0_18_0alpha, V0_17_0, V0_16_4, V0_16_3, V0_16_2, V0_16_1, V0_16_0, V0_15_1, V0_15_0, V0_15_0beta
Branch point for: V0_17branch, V0_16branch, V0_15branch
Changes since 1.1.2.5: +15 -13 lines
Log Message:
Move to inheritance model for error handling :(

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[,DocVersionTag] : A new SimpleURLDoc object. You can also
12 # specify an alternative doc version tag
13 # addbasetags(parse) : Add Base Tags to the given parse
14 # urlget(urlstring[,location]) : get the given url - using the cache.
15 # Returns (url, filename)
16 # urldownload(urlstring[,location]) : get the given url ignoring any cached
17 # version. Returns (url, filename)
18 # expandurl(urlstring) : return a URLclass object of the given url expanded
19 # according to the base settings
20 # cache([cache]) : get/set the current URL cache
21 # doctype() : return the (type,version) of the document
22 # as specified by the DocVersionTag
23
24 package ActiveDoc::SimpleURLDoc;
25 use ActiveDoc::SimpleDoc;
26 use URL::URLhandler;
27 require 5.001;
28 @ISA=qw(ActiveDoc::SimpleDoc);
29
30 sub new {
31 my $class=shift;
32 my $self={};
33 bless $self, $class;
34 $self->cache(shift);
35 $self->_initdoc("doc",@_);
36 #$self->{switch}=ActiveDoc::SimpleDoc->new(@_);
37 return $self;
38 }
39
40 sub addbasetags {
41 my $self=shift;
42 my $parse=shift;
43
44 $self->addtag($parse,"base", \&Base_start, $self,
45 "", $self,
46 \&Base_end,$self);
47 }
48
49 sub cache {
50 my $self=shift;
51 if ( @_ ) {
52 $self->{cache}=shift;
53 $self->{urlhandler}=URL::URLhandler->new($self->{cache});
54 }
55 return $self->{cache};
56 }
57
58 sub expandurl {
59 my $self=shift;
60 my $urlstring=shift;
61
62 return $self->{urlhandler}->expandurl($urlstring);
63 }
64
65 sub urldownload {
66 my $self=shift;
67 my $urlstring=shift;
68
69 ($fullurl,$filename)=$self->{urlhandler}->download($urlstring, @_);
70 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
71 $self->parseerror("Failed to get $fullurl");
72 }
73 return ($fullurl,$filename);
74 }
75
76 sub urlget {
77 my $self=shift;
78 my $urlstring=shift;
79
80 ($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
81 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
82 $self->parseerror("Failed to get $fullurl");
83 }
84 return ($fullurl,$filename);
85 }
86
87 #sub AUTOLOAD {
88 # my $self=shift;
89 #
90 # dont propogate destroy methods
91 # return if $AUTOLOAD=~/::DESTROY/;
92
93 # remove this package name
94 # ($name=$AUTOLOAD)=~s/ActiveDoc::SimpleURLDoc:://;
95
96 # pass the message to SimpleDoc
97 # $self->{switch}->$name(@_);
98 #}
99
100 # ------------------------ Support Routines ---------------------------
101
102 # ------------------------ Tag Routines -------------------------------
103
104 sub Base_start {
105 my $self=shift;
106 my $name=shift;
107 my $hashref=shift;
108
109 $self->checktag($name, $hashref, "url");
110 my $url=$self->{urlhandler}->setbase($$hashref{'url'});
111 push @{$self->{basestack}}, $url->type();
112 }
113
114 sub Base_end {
115 my $self=shift;
116 if ( $#{$self->{basestack}} >= 0 ) {
117 my $type=pop @{$self->{basestack}};
118 $self->{urlhandler}->unsetbase($type);
119 }
120 else {
121 $self->parseerror("Unmatched <$name>");
122 }
123 }