Home | History | Annotate | Download | only in settings
      1 /**
      2  * $Revision$
      3  * $Date$
      4  *
      5  * Copyright 2003-2007 Jive Software.
      6  *
      7  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *     http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 package org.jivesoftware.smackx.workgroup.settings;
     21 
     22 import org.jivesoftware.smackx.workgroup.util.ModelUtil;
     23 import org.jivesoftware.smack.packet.IQ;
     24 import org.jivesoftware.smack.provider.IQProvider;
     25 import org.xmlpull.v1.XmlPullParser;
     26 
     27 public class WorkgroupProperties extends IQ {
     28 
     29     private boolean authRequired;
     30     private String email;
     31     private String fullName;
     32     private String jid;
     33 
     34     public boolean isAuthRequired() {
     35         return authRequired;
     36     }
     37 
     38     public void setAuthRequired(boolean authRequired) {
     39         this.authRequired = authRequired;
     40     }
     41 
     42     public String getEmail() {
     43         return email;
     44     }
     45 
     46     public void setEmail(String email) {
     47         this.email = email;
     48     }
     49 
     50     public String getFullName() {
     51         return fullName;
     52     }
     53 
     54     public void setFullName(String fullName) {
     55         this.fullName = fullName;
     56     }
     57 
     58     public String getJid() {
     59         return jid;
     60     }
     61 
     62     public void setJid(String jid) {
     63         this.jid = jid;
     64     }
     65 
     66 
     67     /**
     68      * Element name of the packet extension.
     69      */
     70     public static final String ELEMENT_NAME = "workgroup-properties";
     71 
     72     /**
     73      * Namespace of the packet extension.
     74      */
     75     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
     76 
     77     public String getChildElementXML() {
     78         StringBuilder buf = new StringBuilder();
     79 
     80         buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
     81         buf.append('"');
     82         buf.append(NAMESPACE);
     83         buf.append('"');
     84         if (ModelUtil.hasLength(getJid())) {
     85             buf.append("jid=\"" + getJid() + "\" ");
     86         }
     87         buf.append("></").append(ELEMENT_NAME).append("> ");
     88         return buf.toString();
     89     }
     90 
     91     /**
     92      * Packet extension provider for SoundSetting Packets.
     93      */
     94     public static class InternalProvider implements IQProvider {
     95 
     96         public IQ parseIQ(XmlPullParser parser) throws Exception {
     97             if (parser.getEventType() != XmlPullParser.START_TAG) {
     98                 throw new IllegalStateException("Parser not in proper position, or bad XML.");
     99             }
    100 
    101             WorkgroupProperties props = new WorkgroupProperties();
    102 
    103             boolean done = false;
    104 
    105 
    106             while (!done) {
    107                 int eventType = parser.next();
    108                 if ((eventType == XmlPullParser.START_TAG) && ("authRequired".equals(parser.getName()))) {
    109                     props.setAuthRequired(new Boolean(parser.nextText()).booleanValue());
    110                 }
    111                 else if ((eventType == XmlPullParser.START_TAG) && ("email".equals(parser.getName()))) {
    112                     props.setEmail(parser.nextText());
    113                 }
    114                 else if ((eventType == XmlPullParser.START_TAG) && ("name".equals(parser.getName()))) {
    115                     props.setFullName(parser.nextText());
    116                 }
    117                 else if (eventType == XmlPullParser.END_TAG && "workgroup-properties".equals(parser.getName())) {
    118                     done = true;
    119                 }
    120             }
    121 
    122             return props;
    123         }
    124     }
    125 }
    126