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.IQ; 022 023 import java.util.*; 024 025 /** 026 * IQ packet for representing jabber:iq:version 027 * 028 * @author Adam Olsen 029 * @version 1.0 030 */ 031 public class Version extends IQ 032 { 033 private String name = null; 034 private String os = null; 035 private String version = null; 036 037 /** 038 * Default constructor - sets up the packet with no 039 * information 040 */ 041 public Version() 042 { 043 this( "", "", "" ); 044 } 045 046 /** 047 * Sets up the packet with information 048 * @param name the client name 049 * @param version the client version 050 * @param os the client os 051 */ 052 public Version( String name, String version, String os ) 053 { 054 this.name = name; 055 this.version = version; 056 this.os = os; 057 } 058 059 /** 060 * @return the client name 061 */ 062 public String getName() { return name; } 063 064 /** 065 * @return the client version 066 */ 067 public String getVersion() { return version; } 068 069 /** 070 * @return the client os 071 */ 072 public String getOs() { return os; } 073 074 /** 075 * @param name the client name 076 */ 077 public void setName( String name ) { this.name = name; } 078 079 /** 080 * @param version the client version 081 */ 082 public void setVersion( String version ) { this.version = version; } 083 084 /** 085 * @param os the client operating system 086 */ 087 public void setOs( String os ) { this.os = os; } 088 089 /** 090 * Builds the packet 091 * @return the XML version of the packet 092 */ 093 public String getChildElementXML() 094 { 095 StringBuffer buf = new StringBuffer(); 096 buf.append("<query xmlns=\"jabber:iq:version\">"); 097 098 if( name != null ) 099 { 100 buf.append( "<name>" ).append(name).append("</name>"); 101 } 102 if( version != null ) 103 { 104 buf.append("<version>").append(version).append("</version>"); 105 } 106 if( os != null ) 107 { 108 buf.append("<os>").append(os).append("</os>"); 109 } 110 111 buf.append("</query>"); 112 return buf.toString(); 113 } 114 }