001/* 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.workgroup.settings; 018 019import java.io.IOException; 020 021import org.jivesoftware.smack.packet.IqData; 022import org.jivesoftware.smack.packet.SimpleIQ; 023import org.jivesoftware.smack.packet.XmlEnvironment; 024import org.jivesoftware.smack.provider.IqProvider; 025import org.jivesoftware.smack.util.StringUtils; 026import org.jivesoftware.smack.xml.XmlPullParser; 027import org.jivesoftware.smack.xml.XmlPullParserException; 028 029import org.jxmpp.JxmppContext; 030 031public class SearchSettings extends SimpleIQ { 032 private String forumsLocation; 033 private String kbLocation; 034 035 public boolean isSearchEnabled() { 036 return StringUtils.isNotEmpty(getForumsLocation()) && StringUtils.isNotEmpty(getKbLocation()); 037 } 038 039 public String getForumsLocation() { 040 return forumsLocation; 041 } 042 043 public void setForumsLocation(String forumsLocation) { 044 this.forumsLocation = forumsLocation; 045 } 046 047 public String getKbLocation() { 048 return kbLocation; 049 } 050 051 public void setKbLocation(String kbLocation) { 052 this.kbLocation = kbLocation; 053 } 054 055 public boolean hasKB() { 056 return StringUtils.isNotEmpty(getKbLocation()); 057 } 058 059 public boolean hasForums() { 060 return StringUtils.isNotEmpty(getForumsLocation()); 061 } 062 063 064 /** 065 * Element name of the stanza extension. 066 */ 067 public static final String ELEMENT_NAME = "search-settings"; 068 069 /** 070 * Namespace of the stanza extension. 071 */ 072 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 073 074 public SearchSettings() { 075 super(ELEMENT_NAME, NAMESPACE); 076 } 077 078 /** 079 * Stanza extension provider for AgentStatusRequest packets. 080 */ 081 public static class InternalProvider extends IqProvider<SearchSettings> { 082 083 @Override 084 public SearchSettings parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) throws XmlPullParserException, IOException { 085 SearchSettings settings = new SearchSettings(); 086 087 boolean done = false; 088 String kb = null; 089 String forums = null; 090 091 while (!done) { 092 XmlPullParser.Event eventType = parser.next(); 093 if (eventType == XmlPullParser.Event.START_ELEMENT && "forums".equals(parser.getName())) { 094 forums = parser.nextText(); 095 } 096 else if ((eventType == XmlPullParser.Event.START_ELEMENT) && "kb".equals(parser.getName())) { 097 kb = parser.nextText(); 098 } 099 else if (eventType == XmlPullParser.Event.END_ELEMENT && "search-settings".equals(parser.getName())) { 100 done = true; 101 } 102 } 103 104 settings.setForumsLocation(forums); 105 settings.setKbLocation(kb); 106 return settings; 107 } 108 } 109}