]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/perlmods/OpenSRF/Transport/SlimJabber/MessageWrapper.pm
Initial revision
[OpenSRF.git] / src / perlmods / OpenSRF / Transport / SlimJabber / MessageWrapper.pm
1 package OpenSRF::Transport::SlimJabber::MessageWrapper;
2 use OpenSRF::DOM;
3
4 sub new {
5         my $class = shift;
6         $class = ref($class) || $class;
7
8         my $xml = shift;
9
10         my ($doc, $msg);
11         if ($xml) {
12                 $doc = OpenSRF::DOM->new->parse_string($xml);
13                 $msg = $doc->documentElement;
14         } else {
15                 $doc = OpenSRF::DOM->createDocument;
16                 $msg = $doc->createElement( 'message' );
17                 $doc->documentElement->appendChild( $msg );
18         }
19
20         
21         my $self = { msg_node => $msg };
22
23         return bless $self => $class;
24 }
25
26 sub toString {
27         my $self = shift;
28         return $self->{msg_node}->toString(@_);
29 }
30
31 sub get_body {
32         my $self = shift;
33         my ($t_body) = grep {$_->nodeName eq 'body'} $self->{msg_node}->childNodes;
34         if( $t_body ) {
35                 my $body = $t_body->textContent;
36                 return $body;
37         }
38         return "";
39 }
40
41 sub get_sess_id {
42         my $self = shift;
43         my ($t_node) = grep {$_->nodeName eq 'thread'} $self->{msg_node}->childNodes;
44         if( $t_node ) {
45                 return $t_node->textContent;
46         }
47         return "";
48 }
49
50 sub get_msg_type {
51         my $self = shift;
52         $self->{msg_node}->getAttribute( 'type' );
53 }
54
55 sub get_remote_id {
56         my $self = shift;
57
58         #
59         my $rid = $self->{msg_node}->getAttribute( 'router_from' );
60         return $rid if $rid;
61
62         return $self->{msg_node}->getAttribute( 'from' );
63 }
64
65 sub setType {
66         my $self = shift;
67         $self->{msg_node}->setAttribute( type => shift );
68 }
69
70 sub setTo {
71         my $self = shift;
72         $self->{msg_node}->setAttribute( to => shift );
73 }
74
75 sub setThread {
76         my $self = shift;
77         $self->{msg_node}->appendTextChild( thread => shift );
78 }
79
80 sub setBody {
81         my $self = shift;
82         my $body = shift;
83         $self->{msg_node}->appendTextChild( body => $body );
84 }
85
86 sub set_router_command {
87         my( $self, $router_command ) = @_;
88         if( $router_command ) {
89                 $self->{msg_node}->setAttribute( router_command => $router_command );
90         }
91 }
92 sub set_router_class {
93         my( $self, $router_class ) = @_;
94         if( $router_class ) {
95                 $self->{msg_node}->setAttribute( router_class => $router_class );
96         }
97 }
98
99 1;