ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleXMLURLDoc.pm
Revision: 1.1
Committed: Tue Jul 26 15:13:59 2005 UTC (19 years, 9 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_0_4p1, V1_0_2, V1_0_2_p1
Branch point for: v103_branch
Log Message:
Added XML version of ToolParser classes. Started to add support for upgrade mode of project command

File Contents

# Content
1 #
2 # Added XML support: SFA 26/07/05
3 #
4 # SimpleXMLURLDoc.pm. - Extends SimpleDoc with URL download functionality
5 #
6 # Originally Written by Christopher Williams
7 #
8 # Description
9 # -----------
10 #
11 # Interface
12 # ---------
13 # new(URLcache[,DocVersionTag] : A new SimpleXMLURLDoc object. You can also
14 # specify an alternative doc version tag
15 # addbasetags(parse) : Add Base Tags to the given parse
16 # urlget(urlstring[,location]) : get the given url - using the cache.
17 # Returns (url, filename)
18 # urldownload(urlstring[,location]) : get the given url ignoring any cached
19 # version. Returns (url, filename)
20 # expandurl(urlstring) : return a URLclass object of the given url expanded
21 # according to the base settings
22 # cache([cache]) : get/set the current URL cache
23 # doctype() : return the (type,version) of the document
24 # as specified by the DocVersionTag
25 package ActiveDoc::SimpleXMLURLDoc;
26 use ActiveDoc::SimpleXMLDoc;
27 use URL::URLhandler;
28 require 5.001;
29 @ISA=qw(ActiveDoc::SimpleXMLDoc);
30
31 sub new {
32 my $class=shift;
33 my $self={};
34 bless $self, $class;
35 $self->cache(shift);
36 $self->_initdoc("doc",@_);
37 return $self;
38 }
39
40 sub addbasetags
41 {
42 my $self=shift;
43 my $parse=shift;
44
45 $self->registerTag($parse, "base",
46 \&basetaghandler,
47 [ "url" ],
48 1);
49 }
50
51 sub cache {
52 my $self=shift;
53 if ( @_ ) {
54 $self->{cache}=shift;
55 $self->{urlhandler}=URL::URLhandler->new($self->{cache});
56 }
57 return $self->{cache};
58 }
59
60 sub expandurl {
61 my $self=shift;
62 my $urlstring=shift;
63
64 return $self->{urlhandler}->expandurl($urlstring);
65 }
66
67 sub urldownload {
68 my $self=shift;
69 my $urlstring=shift;
70
71 ($fullurl,$filename)=$self->{urlhandler}->download($urlstring, @_);
72 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
73 $self->parseerror("Failed to get $fullurl");
74 }
75 return ($fullurl,$filename);
76 }
77
78 sub urlget {
79 my $self=shift;
80 my $urlstring=shift;
81
82 ($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
83
84 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
85 $self->parseerror("Failed to get $fullurl");
86 }
87 return ($fullurl,$filename);
88 }
89
90 # ------------------------ Support Routines ---------------------------
91
92 # ------------------------ Tag Routines -------------------------------
93 sub basetaghandler()
94 {
95 my ($name, $hashref, $nesting)=@_;
96 # No action for Char handler:
97 return if ($nesting == 2);
98
99 # Closing tag:
100 if ($nesting == 1)
101 {
102 # Probably not needed as error handling (tags not closed etc.) is
103 # handled by the XML parser anyway:
104 if ( $#{$self->{basestack}} >= 0 )
105 {
106 my $type=pop @{$self->{basestack}};
107 $self->{urlhandler}->unsetbase($type);
108 }
109 }
110 else
111 {
112 my $url=$self->{urlhandler}->setbase($$hashref{'url'});
113 # Add store for url of the file currently being parsed. This info can
114 # then be extracted in Requirements objects
115 $self->{configurl}=$url;
116 push @{$self->{basestack}}, $url->type();
117 }
118 }