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