Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
|
| 3 | * you may not use this file except in compliance with the License.
|
| 4 | * You may obtain a copy of the License at
|
| 5 | *
|
| 6 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 7 | *
|
| 8 | * Unless required by applicable law or agreed to in writing, software
|
| 9 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 11 | * See the License for the specific language governing permissions and
|
| 12 | * limitations under the License.
|
| 13 | */
|
| 14 | package org.jivesoftware.smackx.pubsub;
|
| 15 |
|
| 16 | import org.jivesoftware.smack.packet.PacketExtension;
|
| 17 |
|
| 18 | /**
|
| 19 | * A class which represents a common element within the pubsub defined
|
| 20 | * schemas. One which has a <b>node</b> as an attribute. This class is
|
| 21 | * used on its own as well as a base class for many others, since the
|
| 22 | * node is a central concept to most pubsub functionality.
|
| 23 | *
|
| 24 | * @author Robin Collier
|
| 25 | */
|
| 26 | public class NodeExtension implements PacketExtension
|
| 27 | {
|
| 28 | private PubSubElementType element;
|
| 29 | private String node;
|
| 30 |
|
| 31 | /**
|
| 32 | * Constructs a <tt>NodeExtension</tt> with an element name specified
|
| 33 | * by {@link PubSubElementType} and the specified node id.
|
| 34 | *
|
| 35 | * @param elem Defines the element name and namespace
|
| 36 | * @param nodeId Specifies the id of the node
|
| 37 | */
|
| 38 | public NodeExtension(PubSubElementType elem, String nodeId)
|
| 39 | {
|
| 40 | element = elem;
|
| 41 | this.node = nodeId;
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Constructs a <tt>NodeExtension</tt> with an element name specified
|
| 46 | * by {@link PubSubElementType}.
|
| 47 | *
|
| 48 | * @param elem Defines the element name and namespace
|
| 49 | */
|
| 50 | public NodeExtension(PubSubElementType elem)
|
| 51 | {
|
| 52 | this(elem, null);
|
| 53 | }
|
| 54 |
|
| 55 | /**
|
| 56 | * Gets the node id
|
| 57 | *
|
| 58 | * @return The node id
|
| 59 | */
|
| 60 | public String getNode()
|
| 61 | {
|
| 62 | return node;
|
| 63 | }
|
| 64 |
|
| 65 | public String getElementName()
|
| 66 | {
|
| 67 | return element.getElementName();
|
| 68 | }
|
| 69 |
|
| 70 | public String getNamespace()
|
| 71 | {
|
| 72 | return element.getNamespace().getXmlns();
|
| 73 | }
|
| 74 |
|
| 75 | public String toXML()
|
| 76 | {
|
| 77 | return '<' + getElementName() + (node == null ? "" : " node='" + node + '\'') + "/>";
|
| 78 | }
|
| 79 |
|
| 80 | @Override
|
| 81 | public String toString()
|
| 82 | {
|
| 83 | return getClass().getName() + " - content [" + toXML() + "]";
|
| 84 | }
|
| 85 | }
|