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 org.jivesoftware.smackx.workgroup.util.ModelUtil; 020import org.jivesoftware.smack.packet.IQ; 021import org.jivesoftware.smack.provider.IQProvider; 022import org.xmlpull.v1.XmlPullParser; 023 024public class SearchSettings extends IQ { 025 private String forumsLocation; 026 private String kbLocation; 027 028 public boolean isSearchEnabled() { 029 return ModelUtil.hasLength(getForumsLocation()) && ModelUtil.hasLength(getKbLocation()); 030 } 031 032 public String getForumsLocation() { 033 return forumsLocation; 034 } 035 036 public void setForumsLocation(String forumsLocation) { 037 this.forumsLocation = forumsLocation; 038 } 039 040 public String getKbLocation() { 041 return kbLocation; 042 } 043 044 public void setKbLocation(String kbLocation) { 045 this.kbLocation = kbLocation; 046 } 047 048 public boolean hasKB(){ 049 return ModelUtil.hasLength(getKbLocation()); 050 } 051 052 public boolean hasForums(){ 053 return ModelUtil.hasLength(getForumsLocation()); 054 } 055 056 057 /** 058 * Element name of the packet extension. 059 */ 060 public static final String ELEMENT_NAME = "search-settings"; 061 062 /** 063 * Namespace of the packet extension. 064 */ 065 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 066 067 public String getChildElementXML() { 068 StringBuilder buf = new StringBuilder(); 069 070 buf.append("<").append(ELEMENT_NAME).append(" xmlns="); 071 buf.append('"'); 072 buf.append(NAMESPACE); 073 buf.append('"'); 074 buf.append("></").append(ELEMENT_NAME).append("> "); 075 return buf.toString(); 076 } 077 078 079 /** 080 * Packet extension provider for AgentStatusRequest packets. 081 */ 082 public static class InternalProvider implements IQProvider { 083 084 public IQ parseIQ(XmlPullParser parser) throws Exception { 085 if (parser.getEventType() != XmlPullParser.START_TAG) { 086 throw new IllegalStateException("Parser not in proper position, or bad XML."); 087 } 088 089 SearchSettings settings = new SearchSettings(); 090 091 boolean done = false; 092 String kb = null; 093 String forums = null; 094 095 while (!done) { 096 int eventType = parser.next(); 097 if ((eventType == XmlPullParser.START_TAG) && ("forums".equals(parser.getName()))) { 098 forums = parser.nextText(); 099 } 100 else if ((eventType == XmlPullParser.START_TAG) && ("kb".equals(parser.getName()))) { 101 kb = parser.nextText(); 102 } 103 else if (eventType == XmlPullParser.END_TAG && "search-settings".equals(parser.getName())) { 104 done = true; 105 } 106 } 107 108 settings.setForumsLocation(forums); 109 settings.setKbLocation(kb); 110 return settings; 111 } 112 } 113}