001    /*
002     Copyright (C) 2003 Adam Olsen
003    
004     This program is free software; you can redistribute it and/or modify
005     it under the terms of the GNU General Public License as published by
006     the Free Software Foundation; either version 1, or (at your option)
007     any later version.
008    
009     This program is distributed in the hope that it will be useful,
010     but WITHOUT ANY WARRANTY; without even the implied warranty of
011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012     GNU General Public License for more details.
013    
014     You should have received a copy of the GNU General Public License
015     along with this program; if not, write to the Free Software
016     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
017     */
018    
019    package com.valhalla.jbother.jabber.smack;
020    
021    import org.jivesoftware.smack.packet.PacketExtension;
022    
023    /**
024     * Builds extension to send encrypted & signed data
025     * 
026     * @author Andrey Zakirov
027     * @version 1.0
028     */
029    public class SecureExtension extends Object implements PacketExtension {
030        private String Type = null;
031    
032        private String Data = null;
033    
034        /**
035         * Default constructor - creates extension with type "encrypted"
036         */
037        public SecureExtension() {
038            this.Type = "encrypted";
039        }
040    
041        /**
042         * Creates extension with user-defined type
043         * 
044         * @param Type
045         *            user-defined type
046         */
047        public SecureExtension(String Type) {
048            this.Type = Type;
049        }
050    
051        /**
052         * Sets up user-defined type for extension
053         * 
054         * @param Type
055         *            user-defined type
056         */
057        public void setType(String Type) {
058            this.Type = Type;
059        }
060    
061        /**
062         * Gets extension type
063         * 
064         * @return extension type
065         */
066        public String getType() {
067            return this.Type;
068        }
069    
070        /**
071         * Sets up user-defined data for extension
072         * 
073         * @param Type
074         *            user-defined data
075         */
076        public void setData(String Data) {
077            this.Data = Data;
078        }
079    
080        /**
081         * Gets extension data
082         * 
083         * @return extension data
084         */
085        public String getData() {
086            return this.Data;
087        }
088    
089        /**
090         * Builds the packet
091         * 
092         * @return the XML version of the packet
093         */
094        public String toXML() {
095            return "<x xmlns=\"jabber:x:" + this.Type + "\">" + this.Data + "</x>";
096        }
097    
098        /**
099         * Gets extension element name
100         * 
101         * @return element name
102         */
103        public String getElementName() {
104            return "x";
105        }
106    
107        /**
108         * Gets extension element namespace
109         * 
110         * @return element namespace
111         */
112        public String getNamespace() {
113            return "jabber:x:" + this.Type;
114        }
115    }