001/**
002 *
003 * Copyright the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.pubsub;
018
019import org.jivesoftware.smack.packet.PacketExtension;
020
021/**
022 * The default payload representation for {@link PayloadItem#getPayload()}.  It simply 
023 * stores the XML payload as a string.
024 *  
025 * @author Robin Collier
026 */
027public class SimplePayload implements PacketExtension
028{
029        private String elemName;
030        private String ns;
031        private String payload;
032        
033        /**
034         * Construct a <tt>SimplePayload</tt> object with the specified element name, 
035         * namespace and content.  The content must be well formed XML.
036         * 
037         * @param elementName The root element name (of the payload)
038         * @param namespace The namespace of the payload, null if there is none
039         * @param xmlPayload The payload data
040         */
041        public SimplePayload(String elementName, String namespace, String xmlPayload)
042        {
043                elemName = elementName;
044                payload = xmlPayload;
045                ns = namespace;
046        }
047
048        public String getElementName()
049        {
050                return elemName;
051        }
052
053        public String getNamespace()
054        {
055                return ns;
056        }
057
058        public String toXML()
059        {
060                return payload;
061        }
062
063        @Override
064        public String toString()
065        {
066                return getClass().getName() + "payload [" + toXML() + "]";
067        }
068}