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 java.io.IOException; 021 022import org.jivesoftware.smack.packet.IQ; 023import org.jivesoftware.smack.packet.IqData; 024import org.jivesoftware.smack.packet.XmlEnvironment; 025import org.jivesoftware.smack.provider.IqProvider; 026import org.jivesoftware.smack.util.StringUtils; 027import org.jivesoftware.smack.xml.XmlPullParser; 028import org.jivesoftware.smack.xml.XmlPullParserException; 029 030import org.jxmpp.JxmppContext; 031 032public class WorkgroupProperties extends IQ { 033 034 private boolean authRequired; 035 private String email; 036 private String fullName; 037 private String jid; 038 039 public boolean isAuthRequired() { 040 return authRequired; 041 } 042 043 public void setAuthRequired(boolean authRequired) { 044 this.authRequired = authRequired; 045 } 046 047 public String getEmail() { 048 return email; 049 } 050 051 public void setEmail(String email) { 052 this.email = email; 053 } 054 055 public String getFullName() { 056 return fullName; 057 } 058 059 public void setFullName(String fullName) { 060 this.fullName = fullName; 061 } 062 063 public String getJid() { 064 return jid; 065 } 066 067 public void setJid(String jid) { 068 this.jid = jid; 069 } 070 071 072 /** 073 * Element name of the stanza extension. 074 */ 075 public static final String ELEMENT_NAME = "workgroup-properties"; 076 077 /** 078 * Namespace of the stanza extension. 079 */ 080 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 081 082 public WorkgroupProperties() { 083 super(ELEMENT_NAME, NAMESPACE); 084 } 085 086 @Override 087 protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) { 088 if (StringUtils.isNotEmpty(getJid())) { 089 buf.append("jid=\"" + getJid() + "\" "); 090 } 091 buf.setEmptyElement(); 092 return buf; 093 } 094 095 /** 096 * Stanza extension provider for SoundSetting Packets. 097 */ 098 public static class InternalProvider extends IqProvider<WorkgroupProperties> { 099 100 @Override 101 public WorkgroupProperties parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) throws XmlPullParserException, IOException { 102 WorkgroupProperties props = new WorkgroupProperties(); 103 104 boolean done = false; 105 106 107 while (!done) { 108 XmlPullParser.Event eventType = parser.next(); 109 if (eventType == XmlPullParser.Event.START_ELEMENT && "authRequired".equals(parser.getName())) { 110 // CHECKSTYLE:OFF 111 props.setAuthRequired(Boolean.valueOf(parser.nextText()).booleanValue()); 112 // CHECKSTYLE:ON 113 } 114 else if (eventType == XmlPullParser.Event.START_ELEMENT && "email".equals(parser.getName())) { 115 props.setEmail(parser.nextText()); 116 } 117 else if (eventType == XmlPullParser.Event.START_ELEMENT && "name".equals(parser.getName())) { 118 props.setFullName(parser.nextText()); 119 } 120 else if (eventType == XmlPullParser.Event.END_ELEMENT && "workgroup-properties".equals(parser.getName())) { 121 done = true; 122 } 123 } 124 125 return props; 126 } 127 } 128}