line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Tridion::BusinessConnector |
2
|
|
|
|
|
|
|
# written by Toby Corkindale (perl (at) corkindale.net) |
3
|
|
|
|
|
|
|
# Copyright (c) 2004 Toby Corkindale, All rights reserved. |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: BusinessConnector.pm 18 2005-12-21 16:38:11Z tjc $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This Perl module is distributed under the terms of the LGPL: |
8
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public |
10
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either |
11
|
|
|
|
|
|
|
# version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# This license can be found at http://www.gnu.org/licenses/lgpl.html |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# This module will help you interface Perl programs to Tridion(tm)'s |
17
|
|
|
|
|
|
|
# content management system. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Tridion::BusinessConnector; |
20
|
1
|
|
|
1
|
|
32696
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
21
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
515
|
use XML::LibXML; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Tridion namespaces: (Current as of 2004 - may need to be updated one day?) |
28
|
|
|
|
|
|
|
our $TCM_NS = 'http://www.tridion.com/ContentManager/5.0'; |
29
|
|
|
|
|
|
|
our $TCMAPI_NS = 'http://www.tridion.com/ContentManager/5.0/TCMAPI'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Initialise the SOAP subsystem: |
33
|
|
|
|
|
|
|
use SOAP::Lite |
34
|
|
|
|
|
|
|
on_fault => sub { |
35
|
|
|
|
|
|
|
my $soap = shift; |
36
|
|
|
|
|
|
|
my $res = shift; |
37
|
|
|
|
|
|
|
ref $res ? die(join "\n", "--- SOAP FAULT ---", $res->faultcode, |
38
|
|
|
|
|
|
|
$res->faultstring, '') |
39
|
|
|
|
|
|
|
: die(join "\n", "--- TRANSPORT ERROR ---", |
40
|
|
|
|
|
|
|
$soap->transport->status, ''); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my $proto = shift; |
47
|
|
|
|
|
|
|
my %args = @_; |
48
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
49
|
|
|
|
|
|
|
my $self = {}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->{hostname} = $args{hostname}; |
52
|
|
|
|
|
|
|
$self->{username} = $args{username}; |
53
|
|
|
|
|
|
|
$self->{password} = $args{password}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->{_parser} = new XML::LibXML; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->{_soaplite} = new SOAP::Lite |
58
|
|
|
|
|
|
|
uri => 'http://schemas.xmlsoap.org/soap/encoding/', |
59
|
|
|
|
|
|
|
proxy => 'http://' . $self->{hostname} . '/BCListener/services/urn:bc' |
60
|
|
|
|
|
|
|
; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->{_soaplite}->transport->credentials( |
63
|
|
|
|
|
|
|
$self->{hostname} . ':80', |
64
|
|
|
|
|
|
|
$self->{hostname}, |
65
|
|
|
|
|
|
|
$self->{username}, |
66
|
|
|
|
|
|
|
$self->{password} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
bless($self, $class); |
70
|
|
|
|
|
|
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub execute |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
my $requestXML = shift; |
78
|
|
|
|
|
|
|
my $method = SOAP::Data->name('execute') |
79
|
|
|
|
|
|
|
->attr({xmlns => 'urn:bc'}); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $obj = $self->{_soaplite}->call($method => ('default', $requestXML)); |
82
|
|
|
|
|
|
|
return $obj->result; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub GetItem |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
my $uri = shift; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
die("Invalid TCM URI: $uri\n") unless ($uri =~ /^tcm:\d+(\-\d+)*$/); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $requestXML =<
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
version="5.0" from="SOAPMod" failOnError="true"> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
EOM |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $result = $self->execute($requestXML); |
103
|
|
|
|
|
|
|
my $xml = $self->{_parser}->parse_string($result); |
104
|
|
|
|
|
|
|
if ($xml->findvalue('/tcmapi:Message/tcmapi:Response/@success') ne 'true') { |
105
|
|
|
|
|
|
|
die("---- Request Failed, Dumping output ----\n$result\n"); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# get the first, and only, child of , and make that the new |
109
|
|
|
|
|
|
|
# document root |
110
|
|
|
|
|
|
|
my ($data) = $xml->documentElement()->findnodes('/tcmapi:Message/tcmapi:Response/tcmapi:Result/*'); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $newdoc = new XML::LibXML::Document; |
113
|
|
|
|
|
|
|
$newdoc->setDocumentElement($data); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
return $newdoc; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub SaveItem |
120
|
|
|
|
|
|
|
{ |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my $xml = shift; |
123
|
|
|
|
|
|
|
my $uri = shift; |
124
|
|
|
|
|
|
|
my $context_uri = shift; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
die("Invalid TCM URI: $uri\n") unless ($uri =~ /^tcm:\d+(\-\d+)*$/); |
127
|
|
|
|
|
|
|
die("Invalid TCM URI: $context_uri\n") unless ($context_uri =~ /^tcm:\d+(\-\d+)*$/); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
my $requestDoc = new XML::LibXML::Document; |
130
|
|
|
|
|
|
|
my $root = $requestDoc->createElement('Message'); |
131
|
|
|
|
|
|
|
$root->setNamespace($TCMAPI_NS, 'tcmapi', 1); |
132
|
|
|
|
|
|
|
$root->setAttribute('version', '5.0'); |
133
|
|
|
|
|
|
|
$root->setAttribute('from', 'SOAPMod'); |
134
|
|
|
|
|
|
|
$root->setAttribute('failOnError', 'true'); |
135
|
|
|
|
|
|
|
$requestDoc->setDocumentElement($root); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
my $node = $requestDoc->createElement('tcmapi:Request'); |
138
|
|
|
|
|
|
|
$node->setAttribute('ID', 'Request1'); |
139
|
|
|
|
|
|
|
$node->setAttribute('preserve', 'false'); |
140
|
|
|
|
|
|
|
$root->addChild($node); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $savenode = $requestDoc->createElement('tcmapi:SaveItem'); |
143
|
|
|
|
|
|
|
$savenode->setAttribute('itemURI', $uri); |
144
|
|
|
|
|
|
|
$savenode->setAttribute('contextURI', $context_uri); |
145
|
|
|
|
|
|
|
$savenode->setAttribute('doneEditing', 'true'); |
146
|
|
|
|
|
|
|
$node->addChild($savenode); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# set 'itemType' attr to correct type |
149
|
|
|
|
|
|
|
my $type = $xml->documentElement->nodeName; |
150
|
|
|
|
|
|
|
$type =~ s/^\w+://; |
151
|
|
|
|
|
|
|
$savenode->setAttribute('itemType', $type); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# And add the provided component or whatever. |
154
|
|
|
|
|
|
|
$savenode->addChild($xml->documentElement); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
my $result = $self->execute($requestDoc->toString); |
157
|
|
|
|
|
|
|
$xml = $self->{_parser}->parse_string($result); |
158
|
|
|
|
|
|
|
if ($xml->findvalue('/tcmapi:Message/tcmapi:Response/@success') ne 'true') { |
159
|
|
|
|
|
|
|
die("---- Request Failed, Dumping output ----\n$result\n"); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# get the first, and only, child of , and make that the new |
163
|
|
|
|
|
|
|
# document root |
164
|
|
|
|
|
|
|
my ($data) = $xml->documentElement()->findnodes('/tcmapi:Message/tcmapi:Response/tcmapi:Result/*'); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my $newdoc = new XML::LibXML::Document; |
167
|
|
|
|
|
|
|
$newdoc->setDocumentElement($data); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
return $newdoc; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# In case you need to discover the proper values for realm or netloc for |
174
|
|
|
|
|
|
|
# your own server, uncomment these: |
175
|
|
|
|
|
|
|
#sub SOAP::Transport::HTTP::Client::get_basic_credentials |
176
|
|
|
|
|
|
|
#{ |
177
|
|
|
|
|
|
|
# my($self, $realm, $uri, $proxy) = @_; |
178
|
|
|
|
|
|
|
# warn "Realm[$realm]\nURI[$uri]\nproxy[$proxy]\n"; |
179
|
|
|
|
|
|
|
# warn "host_port[" . $uri->host_port . "]\n"; |
180
|
|
|
|
|
|
|
#} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
1; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
__END__ |