![]() |
Hubiquitus Android
0.3
Android client for hubiquitus protocol
|
00001 /* 00002 * Copyright (c) Novedia Group 2012. 00003 * 00004 * This file is part of Hubiquitus. 00005 * 00006 * Hubiquitus is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Hubiquitus is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with Hubiquitus. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 package org.hubiquitus.hapi.transport.xmpp; 00021 00022 import org.jivesoftware.smack.packet.PacketExtension; 00023 import org.jivesoftware.smack.provider.PacketExtensionProvider; 00024 import org.xmlpull.v1.XmlPullParser; 00025 00033 public class HMessageXMPP implements PacketExtension{ 00034 00035 public static final String NAMESPACE = ""; 00036 public static final String ELEMENT_NAME = "hbody"; 00037 private String type = null; 00038 private String body = null; 00039 00040 public HMessageXMPP() { 00041 } 00042 00043 public HMessageXMPP(String type, String body) { 00044 this.type = type; 00045 this.body = body; 00046 } 00047 00048 /* Getters & Setters */ 00049 00050 public String getType() { 00051 return this.type; 00052 } 00053 00054 public void setType(String type) { 00055 this.type = type; 00056 } 00057 00058 00059 public String getContent(){ 00060 return this.body; 00061 } 00062 00063 public void setContent(String content) { 00064 this.body = content; 00065 } 00066 00067 @Override 00068 public String getElementName() { 00069 return HMessageXMPP.ELEMENT_NAME; 00070 } 00071 00072 @Override 00073 public String getNamespace() { 00074 return HMessageXMPP.NAMESPACE; 00075 } 00076 00077 @Override 00078 public String toXML() { 00079 StringBuilder localStringBuilder = new StringBuilder(); 00080 00081 if( type != null) { 00082 localStringBuilder.append("<hbody type=\"").append(getType()).append("\">"); 00083 localStringBuilder.append(getContent()); 00084 localStringBuilder.append("</hbody>"); 00085 } else { 00086 System.out.println("Should define a type for Message's body"); 00087 } 00088 00089 return localStringBuilder.toString(); 00090 } 00091 00092 public static class Provider implements PacketExtensionProvider { 00093 public PacketExtension parseExtension(XmlPullParser paramXmlPullParser) throws Exception 00094 { 00095 String type = paramXmlPullParser.getAttributeValue("", "type"); 00096 paramXmlPullParser.next(); 00097 String content = paramXmlPullParser.getText(); 00098 while (paramXmlPullParser.getEventType() != XmlPullParser.END_TAG) { 00099 paramXmlPullParser.next(); 00100 } 00101 return new HMessageXMPP(type, content); 00102 } 00103 } 00104 } 00105