21 #include <QtXml/qdom.h>
22 #include <QtNetwork/QTcpSocket>
23 #include <QtCore/QRegExp>
56 call_tree(element, endpoint);
60 return call_soap(element, endpoint);
66 void Soap::call_tree(
const QDomElement& element,
const QString &endpoint)
72 QDomNodeList l = element.childNodes();
73 for (
int i = 0; i < l.count(); i++) {
74 QDomNode tmp = l.item(i);
85 QByteArray data = s.toUtf8();
94 m_socket->connectToHost(hostname, port);
96 m_socket->write(data, data.size());
102 SIGNAL(error(QAbstractSocket::SocketError)),
103 SLOT(slotSocketError(QAbstractSocket::SocketError)));
105 m_buffer = QByteArray();
108 int Soap::call_soap(QDomElement element,
const QString &endpoint)
114 QDomElement env = doc.createElement(
"SOAP-ENV:Envelope");
115 env.setAttribute(
"xmlns:SOAP-ENV",
"http://schemas.xmlsoap.org/soap/envelope/");
116 doc.appendChild(env);
117 QDomElement body = doc.createElement(
"SOAP-ENV:Body");
118 env.appendChild(body);
119 element.setAttribute(
"xmlns:ns",
"urn:DXS");
120 body.appendChild(element);
123 QByteArray data = s.toUtf8();
130 int thisjobid = ++m_lastjobid;
131 m_jobids.insert(job, thisjobid);
132 job->addMetaData(
"content-type",
"Content-Type: text/xml");
138 SLOT(slotData(
KIO::Job*,QByteArray)));
140 SIGNAL(result(
KJob*)),
141 SLOT(slotResult(
KJob*)));
143 m_buffer = QByteArray();
147 void Soap::slotData(
KIO::Job *job,
const QByteArray& data)
154 int bufferlen = m_buffer.size();
155 m_buffer.resize(bufferlen + data.size());
159 memcpy(m_buffer.data() + bufferlen, data.data(), data.size());
164 void Soap::slotResult(
KJob *job)
168 if ((job) && (job->error())) {
177 int bufferlen = m_buffer.size();
178 m_buffer.resize(bufferlen + 1);
179 m_buffer.data()[bufferlen] = 0;
180 m_data = QString::fromUtf8(m_buffer);
184 if (m_model ==
soap) {
186 doc.setContent(m_data);
188 QDomElement envelope = doc.documentElement();
189 QDomNode bodynode = envelope.firstChild();
190 QDomNode contentnode = bodynode.firstChild();
196 m_jobids.remove(job);
204 m_data = m_data.simplified();
205 doc = buildtree(doc, doc.documentElement(), m_data);
207 QDomElement root = doc.documentElement();
219 QDomElement el = node.toElement();
220 QString s = el.tagName().section(
':', -1);
227 QDomNode n = node.firstChild();
228 while (!n.isNull()) {
229 if ((n.isElement()) && (n.toElement().tagName() == name)) {
249 const QStringList explist = expr.split(
'/', QString::SkipEmptyParts);
250 for (QStringList::const_iterator it = explist.begin(); it != explist.end(); ++it) {
251 QDomElement el = n.toElement();
252 QDomNodeList l = el.elementsByTagName((*it));
258 QString s = n.toElement().text();
267 void Soap::slotSocketError(QAbstractSocket::SocketError error)
279 void Soap::slotSocket()
284 a.resize(m_socket->bytesAvailable());
285 m_socket->read(a.data(), m_socket->bytesAvailable());
291 if (m_socket->atEnd()) {
300 QDomDocument Soap::buildtree(QDomDocument doc, QDomElement cur,
const QString& data)
302 int start = -1,
end = -1;
307 if (data.indexOf(
'(') == -1) {
308 QDomText t = doc.createTextNode(data);
313 for (
int i = 0; i < data.length(); i++) {
314 const QChar c = data.at(i);
321 }
else if (c ==
'(') {
326 }
else if (c ==
')') {
328 if ((stack == 0) && (end == -1)) {
331 QString expression = data.mid(offset, start - offset);
332 QString sub = data.mid(start + 1, end - start - 1);
333 expression = expression.trimmed();
339 elem = doc.createElement(
"ns:" + expression);
340 doc.appendChild(elem);
342 elem = doc.createElement(expression);
343 cur.appendChild(elem);
346 buildtree(doc, elem, sub);
void setModel(Model m)
Set the model to be either soap or canonicaltree.
QList< QDomNode > directChildNodes(const QDomNode &node, const QString &name)
QString xpath(const QDomNode &node, const QString &expr)
Find the text element to a xpath like expression.
QString localname(const QDomNode &node)
Name of the QDomElement for node without the namespace.
void signalResult(QDomNode node, int jobid)
TransferJob * http_post(const KUrl &url, const QByteArray &postData, JobFlags flags=DefaultFlags)
int call(const QDomElement &element, const QString &endpoint)
Send to the server - uses either soap or tree.
QStringList list(const QString &fileClass)