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.settings; 019 020import org.jivesoftware.smackx.workgroup.util.ModelUtil; 021import org.jivesoftware.smack.packet.IQ; 022import org.jivesoftware.smack.provider.IQProvider; 023import org.xmlpull.v1.XmlPullParser; 024 025public class WorkgroupProperties extends IQ { 026 027 private boolean authRequired; 028 private String email; 029 private String fullName; 030 private String jid; 031 032 public boolean isAuthRequired() { 033 return authRequired; 034 } 035 036 public void setAuthRequired(boolean authRequired) { 037 this.authRequired = authRequired; 038 } 039 040 public String getEmail() { 041 return email; 042 } 043 044 public void setEmail(String email) { 045 this.email = email; 046 } 047 048 public String getFullName() { 049 return fullName; 050 } 051 052 public void setFullName(String fullName) { 053 this.fullName = fullName; 054 } 055 056 public String getJid() { 057 return jid; 058 } 059 060 public void setJid(String jid) { 061 this.jid = jid; 062 } 063 064 065 /** 066 * Element name of the packet extension. 067 */ 068 public static final String ELEMENT_NAME = "workgroup-properties"; 069 070 /** 071 * Namespace of the packet extension. 072 */ 073 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 074 075 public String getChildElementXML() { 076 StringBuilder buf = new StringBuilder(); 077 078 buf.append("<").append(ELEMENT_NAME).append(" xmlns="); 079 buf.append('"'); 080 buf.append(NAMESPACE); 081 buf.append('"'); 082 if (ModelUtil.hasLength(getJid())) { 083 buf.append("jid=\"" + getJid() + "\" "); 084 } 085 buf.append("></").append(ELEMENT_NAME).append("> "); 086 return buf.toString(); 087 } 088 089 /** 090 * Packet extension provider for SoundSetting Packets. 091 */ 092 public static class InternalProvider implements IQProvider { 093 094 public IQ parseIQ(XmlPullParser parser) throws Exception { 095 if (parser.getEventType() != XmlPullParser.START_TAG) { 096 throw new IllegalStateException("Parser not in proper position, or bad XML."); 097 } 098 099 WorkgroupProperties props = new WorkgroupProperties(); 100 101 boolean done = false; 102 103 104 while (!done) { 105 int eventType = parser.next(); 106 if ((eventType == XmlPullParser.START_TAG) && ("authRequired".equals(parser.getName()))) { 107 props.setAuthRequired(new Boolean(parser.nextText()).booleanValue()); 108 } 109 else if ((eventType == XmlPullParser.START_TAG) && ("email".equals(parser.getName()))) { 110 props.setEmail(parser.nextText()); 111 } 112 else if ((eventType == XmlPullParser.START_TAG) && ("name".equals(parser.getName()))) { 113 props.setFullName(parser.nextText()); 114 } 115 else if (eventType == XmlPullParser.END_TAG && "workgroup-properties".equals(parser.getName())) { 116 done = true; 117 } 118 } 119 120 return props; 121 } 122 } 123}