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