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.ExtensionElement;
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 ExtensionElement
028{
029    private final String elemName;
030    private final String ns;
031    private final CharSequence 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, CharSequence xmlPayload)
042    {
043        elemName = elementName;
044        payload = xmlPayload;
045        ns = namespace;
046    }
047
048    @Override
049    public String getElementName()
050    {
051        return elemName;
052    }
053
054    @Override
055    public String getNamespace()
056    {
057        return ns;
058    }
059
060    @Override
061    public CharSequence toXML()
062    {
063        return payload;
064    }
065
066    @Override
067    public String toString()
068    {
069        return getClass().getName() + "payload [" + toXML() + "]";
070    }
071}