ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleURLDoc.pm
Revision: 1.1.2.5
Committed: Fri Aug 11 10:26:41 2000 UTC (24 years, 9 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: V0_14_0
Changes since 1.1.2.4: +15 -1 lines
Log Message:
add urldownload method

File Contents

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