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