ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleURLDoc.pm
Revision: 1.3
Committed: Mon Dec 3 19:02:04 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1
Branch point for: SCRAM_V1_BRANCH, V0_19_4_B
Changes since 1.2: +0 -14 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 williamc 1.2 #
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     return $self;
37     }
38    
39     sub addbasetags {
40     my $self=shift;
41     my $parse=shift;
42    
43     $self->addtag($parse,"base", \&Base_start, $self,
44     "", $self,
45     \&Base_end,$self);
46     }
47    
48     sub cache {
49     my $self=shift;
50     if ( @_ ) {
51     $self->{cache}=shift;
52     $self->{urlhandler}=URL::URLhandler->new($self->{cache});
53     }
54     return $self->{cache};
55     }
56    
57     sub expandurl {
58     my $self=shift;
59     my $urlstring=shift;
60    
61     return $self->{urlhandler}->expandurl($urlstring);
62     }
63    
64     sub urldownload {
65     my $self=shift;
66     my $urlstring=shift;
67    
68     ($fullurl,$filename)=$self->{urlhandler}->download($urlstring, @_);
69     if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
70     $self->parseerror("Failed to get $fullurl");
71     }
72     return ($fullurl,$filename);
73     }
74    
75     sub urlget {
76     my $self=shift;
77     my $urlstring=shift;
78    
79     ($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
80     if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
81     $self->parseerror("Failed to get $fullurl");
82     }
83     return ($fullurl,$filename);
84     }
85    
86     # ------------------------ Support Routines ---------------------------
87    
88     # ------------------------ Tag Routines -------------------------------
89    
90     sub Base_start {
91     my $self=shift;
92     my $name=shift;
93     my $hashref=shift;
94    
95     $self->checktag($name, $hashref, "url");
96     my $url=$self->{urlhandler}->setbase($$hashref{'url'});
97     push @{$self->{basestack}}, $url->type();
98     }
99    
100     sub Base_end {
101     my $self=shift;
102     if ( $#{$self->{basestack}} >= 0 ) {
103     my $type=pop @{$self->{basestack}};
104     $self->{urlhandler}->unsetbase($type);
105     }
106     else {
107     $self->parseerror("Unmatched <$name>");
108     }
109     }