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