SearchSettings.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.SimpleIQ;
  21. import org.jivesoftware.smack.provider.IQProvider;
  22. import org.xmlpull.v1.XmlPullParser;
  23. import org.xmlpull.v1.XmlPullParserException;

  24. public class SearchSettings extends SimpleIQ {
  25.     private String forumsLocation;
  26.     private String kbLocation;

  27.     public boolean isSearchEnabled() {
  28.         return ModelUtil.hasLength(getForumsLocation()) && ModelUtil.hasLength(getKbLocation());
  29.     }

  30.     public String getForumsLocation() {
  31.         return forumsLocation;
  32.     }

  33.     public void setForumsLocation(String forumsLocation) {
  34.         this.forumsLocation = forumsLocation;
  35.     }

  36.     public String getKbLocation() {
  37.         return kbLocation;
  38.     }

  39.     public void setKbLocation(String kbLocation) {
  40.         this.kbLocation = kbLocation;
  41.     }

  42.     public boolean hasKB(){
  43.         return ModelUtil.hasLength(getKbLocation());
  44.     }

  45.     public boolean hasForums(){
  46.         return ModelUtil.hasLength(getForumsLocation());
  47.     }


  48.     /**
  49.      * Element name of the packet extension.
  50.      */
  51.     public static final String ELEMENT_NAME = "search-settings";

  52.     /**
  53.      * Namespace of the packet extension.
  54.      */
  55.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  56.     public SearchSettings() {
  57.         super(ELEMENT_NAME, NAMESPACE);
  58.     }

  59.     /**
  60.      * Packet extension provider for AgentStatusRequest packets.
  61.      */
  62.     public static class InternalProvider extends IQProvider<SearchSettings> {

  63.         @Override
  64.         public SearchSettings parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  65.             SearchSettings settings = new SearchSettings();

  66.             boolean done = false;
  67.             String kb = null;
  68.             String forums = null;

  69.             while (!done) {
  70.                 int eventType = parser.next();
  71.                 if ((eventType == XmlPullParser.START_TAG) && ("forums".equals(parser.getName()))) {
  72.                     forums = parser.nextText();
  73.                 }
  74.                 else if ((eventType == XmlPullParser.START_TAG) && ("kb".equals(parser.getName()))) {
  75.                     kb = parser.nextText();
  76.                 }
  77.                 else if (eventType == XmlPullParser.END_TAG && "search-settings".equals(parser.getName())) {
  78.                     done = true;
  79.                 }
  80.             }

  81.             settings.setForumsLocation(forums);
  82.             settings.setKbLocation(kb);
  83.             return settings;
  84.         }
  85.     }
  86. }