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.smackx.workgroup.util.ModelUtil;
  20. import org.jivesoftware.smack.packet.IQ;
  21. import org.jivesoftware.smack.provider.IQProvider;
  22. import org.xmlpull.v1.XmlPullParser;
  23. import org.xmlpull.v1.XmlPullParserException;

  24. public class WorkgroupProperties extends IQ {

  25.     private boolean authRequired;
  26.     private String email;
  27.     private String fullName;
  28.     private String jid;

  29.     public boolean isAuthRequired() {
  30.         return authRequired;
  31.     }

  32.     public void setAuthRequired(boolean authRequired) {
  33.         this.authRequired = authRequired;
  34.     }

  35.     public String getEmail() {
  36.         return email;
  37.     }

  38.     public void setEmail(String email) {
  39.         this.email = email;
  40.     }

  41.     public String getFullName() {
  42.         return fullName;
  43.     }

  44.     public void setFullName(String fullName) {
  45.         this.fullName = fullName;
  46.     }

  47.     public String getJid() {
  48.         return jid;
  49.     }

  50.     public void setJid(String jid) {
  51.         this.jid = jid;
  52.     }


  53.     /**
  54.      * Element name of the packet extension.
  55.      */
  56.     public static final String ELEMENT_NAME = "workgroup-properties";

  57.     /**
  58.      * Namespace of the packet extension.
  59.      */
  60.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  61.     public WorkgroupProperties() {
  62.         super(ELEMENT_NAME, NAMESPACE);
  63.     }

  64.     @Override
  65.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  66.         if (ModelUtil.hasLength(getJid())) {
  67.             buf.append("jid=\"" + getJid() + "\" ");
  68.         }
  69.         buf.setEmptyElement();
  70.         return buf;
  71.     }

  72.     /**
  73.      * Packet extension provider for SoundSetting Packets.
  74.      */
  75.     public static class InternalProvider extends IQProvider<WorkgroupProperties> {

  76.         @Override
  77.         public WorkgroupProperties parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  78.             WorkgroupProperties props = new WorkgroupProperties();

  79.             boolean done = false;


  80.             while (!done) {
  81.                 int eventType = parser.next();
  82.                 if ((eventType == XmlPullParser.START_TAG) && ("authRequired".equals(parser.getName()))) {
  83.                     props.setAuthRequired(new Boolean(parser.nextText()).booleanValue());
  84.                 }
  85.                 else if ((eventType == XmlPullParser.START_TAG) && ("email".equals(parser.getName()))) {
  86.                     props.setEmail(parser.nextText());
  87.                 }
  88.                 else if ((eventType == XmlPullParser.START_TAG) && ("name".equals(parser.getName()))) {
  89.                     props.setFullName(parser.nextText());
  90.                 }
  91.                 else if (eventType == XmlPullParser.END_TAG && "workgroup-properties".equals(parser.getName())) {
  92.                     done = true;
  93.                 }
  94.             }

  95.             return props;
  96.         }
  97.     }
  98. }