001/** 002 * 003 * Copyright 2003-2007 Jive Software. 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 */ 017 018package org.jivesoftware.smackx.workgroup.ext.forms; 019 020import org.jivesoftware.smack.packet.IQ; 021import org.jivesoftware.smack.provider.IQProvider; 022import org.jivesoftware.smack.util.PacketParserUtils; 023import org.xmlpull.v1.XmlPullParser; 024 025public class WorkgroupForm extends IQ { 026 027 /** 028 * Element name of the packet extension. 029 */ 030 public static final String ELEMENT_NAME = "workgroup-form"; 031 032 /** 033 * Namespace of the packet extension. 034 */ 035 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 036 037 public String getChildElementXML() { 038 StringBuilder buf = new StringBuilder(); 039 040 buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">"); 041 // Add packet extensions, if any are defined. 042 buf.append(getExtensionsXML()); 043 buf.append("</").append(ELEMENT_NAME).append("> "); 044 045 return buf.toString(); 046 } 047 048 /** 049 * An IQProvider for WebForm packets. 050 * 051 * @author Derek DeMoro 052 */ 053 public static class InternalProvider implements IQProvider { 054 055 public InternalProvider() { 056 super(); 057 } 058 059 public IQ parseIQ(XmlPullParser parser) throws Exception { 060 WorkgroupForm answer = new WorkgroupForm(); 061 062 boolean done = false; 063 while (!done) { 064 int eventType = parser.next(); 065 if (eventType == XmlPullParser.START_TAG) { 066 // Parse the packet extension 067 answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), 068 parser.getNamespace(), parser)); 069 } 070 else if (eventType == XmlPullParser.END_TAG) { 071 if (parser.getName().equals(ELEMENT_NAME)) { 072 done = true; 073 } 074 } 075 } 076 077 return answer; 078 } 079 } 080}