Tomek OsiĆski | 7a1db18 | 2018-02-03 17:15:06 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.xmpp.pubsub.model; |
| 18 | |
| 19 | import org.dom4j.Element; |
| 20 | import org.xmpp.packet.IQ; |
| 21 | |
| 22 | /** |
| 23 | * Abstracts Publish message of XMPP PubSub protocol. |
| 24 | */ |
| 25 | public class XmppPublish extends IQ { |
| 26 | |
| 27 | private String jabberId; |
| 28 | private String nodeID; |
| 29 | private Element item; |
| 30 | private String itemID; |
| 31 | private Element itemEntry; |
| 32 | private String itemEntryNamespace; |
| 33 | |
| 34 | /** |
| 35 | * Constructor for XmppPublish class. |
| 36 | * @param iq XMPP IQ stanza, which XmppPublish is based on. |
| 37 | */ |
| 38 | public XmppPublish(IQ iq) { |
| 39 | super(iq.getElement()); |
| 40 | this.jabberId = this.fromJID.toString(); |
| 41 | this.nodeID = this.getChildElement().element("publish").attribute("node").getValue(); |
| 42 | this.item = this.getChildElement().element("publish").element("item"); |
| 43 | this.itemID = this.item.attribute("id").getValue(); |
| 44 | this.itemEntry = this.item.element("entry"); |
| 45 | this.itemEntryNamespace = this.itemEntry.getNamespaceURI(); |
| 46 | } |
| 47 | |
| 48 | public String getJabberId() { |
| 49 | return this.jabberId; |
| 50 | } |
| 51 | |
| 52 | public String getNodeID() { |
| 53 | return this.nodeID; |
| 54 | } |
| 55 | |
| 56 | public Element getItem() { |
| 57 | return this.item; |
| 58 | } |
| 59 | |
| 60 | public String getItemID() { |
| 61 | return this.itemID; |
| 62 | } |
| 63 | |
| 64 | public Element getItemEntry() { |
| 65 | return this.itemEntry; |
| 66 | } |
| 67 | |
| 68 | public String getItemEntryNamespace() { |
| 69 | return this.itemEntryNamespace; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String toString() { |
| 74 | return "Publish{" + |
| 75 | "JID=" + fromJID + |
| 76 | "NodeID=" + this.getNodeID() + |
| 77 | "Item=\n" + this.getItem().asXML() + |
| 78 | '}'; |
| 79 | } |
| 80 | |
| 81 | } |