WorkgroupProperties.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.settings;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.packet.IQ;
  20. import org.jivesoftware.smack.packet.IqData;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.provider.IqProvider;
  23. import org.jivesoftware.smack.util.StringUtils;
  24. import org.jivesoftware.smack.xml.XmlPullParser;
  25. import org.jivesoftware.smack.xml.XmlPullParserException;

  26. public class WorkgroupProperties extends IQ {

  27.     private boolean authRequired;
  28.     private String email;
  29.     private String fullName;
  30.     private String jid;

  31.     public boolean isAuthRequired() {
  32.         return authRequired;
  33.     }

  34.     public void setAuthRequired(boolean authRequired) {
  35.         this.authRequired = authRequired;
  36.     }

  37.     public String getEmail() {
  38.         return email;
  39.     }

  40.     public void setEmail(String email) {
  41.         this.email = email;
  42.     }

  43.     public String getFullName() {
  44.         return fullName;
  45.     }

  46.     public void setFullName(String fullName) {
  47.         this.fullName = fullName;
  48.     }

  49.     public String getJid() {
  50.         return jid;
  51.     }

  52.     public void setJid(String jid) {
  53.         this.jid = jid;
  54.     }


  55.     /**
  56.      * Element name of the stanza extension.
  57.      */
  58.     public static final String ELEMENT_NAME = "workgroup-properties";

  59.     /**
  60.      * Namespace of the stanza extension.
  61.      */
  62.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  63.     public WorkgroupProperties() {
  64.         super(ELEMENT_NAME, NAMESPACE);
  65.     }

  66.     @Override
  67.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  68.         if (StringUtils.isNotEmpty(getJid())) {
  69.             buf.append("jid=\"" + getJid() + "\" ");
  70.         }
  71.         buf.setEmptyElement();
  72.         return buf;
  73.     }

  74.     /**
  75.      * Stanza extension provider for SoundSetting Packets.
  76.      */
  77.     public static class InternalProvider extends IqProvider<WorkgroupProperties> {

  78.         @Override
  79.         public WorkgroupProperties parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
  80.             WorkgroupProperties props = new WorkgroupProperties();

  81.             boolean done = false;


  82.             while (!done) {
  83.                 XmlPullParser.Event eventType = parser.next();
  84.                 if (eventType == XmlPullParser.Event.START_ELEMENT && "authRequired".equals(parser.getName())) {
  85.                     // CHECKSTYLE:OFF
  86.                     props.setAuthRequired(Boolean.valueOf(parser.nextText()).booleanValue());
  87.                     // CHECKSTYLE:ON
  88.                 }
  89.                 else if (eventType == XmlPullParser.Event.START_ELEMENT && "email".equals(parser.getName())) {
  90.                     props.setEmail(parser.nextText());
  91.                 }
  92.                 else if (eventType == XmlPullParser.Event.START_ELEMENT && "name".equals(parser.getName())) {
  93.                     props.setFullName(parser.nextText());
  94.                 }
  95.                 else if (eventType == XmlPullParser.Event.END_ELEMENT && "workgroup-properties".equals(parser.getName())) {
  96.                     done = true;
  97.                 }
  98.             }

  99.             return props;
  100.         }
  101.     }
  102. }