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.provider.IQProvider;
024import org.jivesoftware.smack.util.StringUtils;
025
026import org.xmlpull.v1.XmlPullParser;
027import org.xmlpull.v1.XmlPullParserException;
028
029public class WorkgroupProperties extends IQ {
030
031    private boolean authRequired;
032    private String email;
033    private String fullName;
034    private String jid;
035
036    public boolean isAuthRequired() {
037        return authRequired;
038    }
039
040    public void setAuthRequired(boolean authRequired) {
041        this.authRequired = authRequired;
042    }
043
044    public String getEmail() {
045        return email;
046    }
047
048    public void setEmail(String email) {
049        this.email = email;
050    }
051
052    public String getFullName() {
053        return fullName;
054    }
055
056    public void setFullName(String fullName) {
057        this.fullName = fullName;
058    }
059
060    public String getJid() {
061        return jid;
062    }
063
064    public void setJid(String jid) {
065        this.jid = jid;
066    }
067
068
069    /**
070     * Element name of the stanza extension.
071     */
072    public static final String ELEMENT_NAME = "workgroup-properties";
073
074    /**
075     * Namespace of the stanza extension.
076     */
077    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
078
079    public WorkgroupProperties() {
080        super(ELEMENT_NAME, NAMESPACE);
081    }
082
083    @Override
084    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
085        if (StringUtils.isNotEmpty(getJid())) {
086            buf.append("jid=\"" + getJid() + "\" ");
087        }
088        buf.setEmptyElement();
089        return buf;
090    }
091
092    /**
093     * Stanza extension provider for SoundSetting Packets.
094     */
095    public static class InternalProvider extends IQProvider<WorkgroupProperties> {
096
097        @Override
098        public WorkgroupProperties parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
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(Boolean.valueOf(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}