source: perl/lib/XML/Stream/Namespace.pm @ b13438c

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since b13438c was 0ff8d110, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 17 years ago
Adding XML::Stream, Net::XMPP, and Net::Jabber to perl/lib/
  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[0ff8d110]1##############################################################################
2#
3#  This library is free software; you can redistribute it and/or
4#  modify it under the terms of the GNU Library General Public
5#  License as published by the Free Software Foundation; either
6#  version 2 of the License, or (at your option) any later version.
7#
8#  This library is distributed in the hope that it will be useful,
9#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11#  Library General Public License for more details.
12#
13#  You should have received a copy of the GNU Library General Public
14#  License along with this library; if not, write to the
15#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16#  Boston, MA  02111-1307, USA.
17#
18#  Jabber
19#  Copyright (C) 1998-2004 Jabber Software Foundation http://jabber.org/
20#
21##############################################################################
22
23package XML::Stream::Namespace;
24
25=head1 NAME
26
27XML::Stream::Namespace - Object to make defining Namespaces easier in
28                         XML::Stream.
29
30=head1 SYNOPSIS
31
32XML::Stream::Namespace is a helper package to XML::Stream.  It provides
33a clean way of defining Namespaces for XML::Stream to use when connecting.
34
35=head1 DESCRIPTION
36
37  This module allows you to set and read elements from an XML::Stream
38  Namespace.
39
40=head1 METHODS
41
42  SetNamespace("mynamespace");
43  SetXMLNS("http://www.mynamespace.com/xmlns");
44  SetAttributes(attrib1=>"value1",
45                attrib2=>"value2");
46
47  GetNamespace() returns "mynamespace"
48  GetXMLNS() returns "http://www.mynamespace.com/xmlns"
49  GetAttributes() returns a hash ( attrib1=>"value1",attrib2=>"value2")
50  GetStream() returns the following string:
51    "xmlns:mynamespace='http://www.nynamespace.com/xmlns'
52     mynamespace:attrib1='value1'
53     mynamespace:attrib2='value2'"
54
55=head1 EXAMPLES
56
57
58  $myNamespace = new XML::Stream::Namespace("mynamspace");
59  $myNamespace->SetXMLNS("http://www.mynamespace.org/xmlns");
60  $myNamespace->SetAttributes(foo=>"bar",
61                              bob=>"vila");
62
63  $stream = new XML::Stream;
64  $stream->Connect(name=>"foo.bar.org",
65                   port=>1234,
66                   namespace=>"foo:bar",
67                   namespaces=>[ $myNamespace ]);
68
69  #
70  # The above Connect will send the following as the opening string
71  # of the stream to foo.bar.org:1234...
72  #
73  #   <stream:stream
74  #    xmlns:stream="http://etherx.jabber.org/streams"
75  #    to="foo.bar.org"
76  #    xmlns="foo:bar"
77  #    xmlns:mynamespace="http://www.mynamespace.org/xmlns"
78  #    mynamespace:foo="bar"
79  #    mynamespace:bob="vila">
80  #
81   
82
83=head1 AUTHOR
84
85Written by Ryan Eatmon in February 2000
86Idea By Thomas Charron in January of 2000 for http://etherx.jabber.org/streams/
87
88=head1 COPYRIGHT
89
90This module is free software; you can redistribute it and/or modify
91it under the same terms as Perl itself.
92
93=cut
94
95use strict;
96use Carp;
97use vars qw( $VERSION );
98
99$VERSION = "1.22";
100
101sub new
102{
103  my $proto = shift;
104  my $self = { };
105
106  ($self->{Namespace}) = @_ if ($#_ > -1);
107
108  $self->{Attributes} = {};
109
110  bless($self,$proto);
111  return $self;
112}
113
114
115sub SetNamespace
116{
117  my $self = shift;
118  my ($namespace) = @_;
119
120  $self->{Namespace} = $namespace;
121}
122
123
124sub SetXMLNS
125{
126  my $self = shift;
127  my ($xmlns) = @_;
128
129  $self->{XMLNS} = $xmlns;
130}
131
132
133sub SetAttributes
134{
135  my $self = shift;
136  my %att = @_;
137
138  my $key;
139  foreach $key (keys(%att))
140  {
141    $self->{Attributes}->{$key} = $att{$key};
142  }
143}
144
145
146sub GetNamespace
147{
148  my $self = shift;
149
150  return $self->{Namespace};
151}
152
153sub GetXMLNS
154{
155  my $self = shift;
156
157  return $self->{XMLNS};
158}
159
160sub GetAttributes
161{
162  my $self = shift;
163  my ($attrib) = @_;
164
165  return $self->{Attributes} if ($attrib eq "");
166  return $self->{Attributes}->{$attrib};
167}
168
169
170sub GetStream
171{
172  my $self = shift;
173
174  my $string = "";
175
176  $string .= "xmlns:".$self->GetNamespace();
177  $string .= "='".$self->GetXMLNS()."'";
178  my $attrib;
179  foreach $attrib (keys(%{$self->GetAttributes()}))
180  {
181    $string .= " ".$self->GetNamespace().":";
182    $string .= $attrib;
183    $string .= "='".$self->GetAttributes($attrib)."'";
184  }
185   
186  return $string;
187}
188
1891;
190
Note: See TracBrowser for help on using the repository browser.