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 */
017
018package org.jivesoftware.smackx.workgroup.settings;
019
020import java.io.IOException;
021
022import org.jivesoftware.smack.packet.SimpleIQ;
023import org.jivesoftware.smack.provider.IQProvider;
024import org.jivesoftware.smack.util.StringUtils;
025
026import org.xmlpull.v1.XmlPullParser;
027import org.xmlpull.v1.XmlPullParserException;
028
029public class OfflineSettings extends SimpleIQ {
030    private String redirectURL;
031
032    private String offlineText;
033    private String emailAddress;
034    private String subject;
035
036    public String getRedirectURL() {
037        if (!StringUtils.isNotEmpty(redirectURL)) {
038            return "";
039        }
040        return redirectURL;
041    }
042
043    public void setRedirectURL(String redirectURL) {
044        this.redirectURL = redirectURL;
045    }
046
047    public String getOfflineText() {
048        if (!StringUtils.isNotEmpty(offlineText)) {
049            return "";
050        }
051        return offlineText;
052    }
053
054    public void setOfflineText(String offlineText) {
055        this.offlineText = offlineText;
056    }
057
058    public String getEmailAddress() {
059        if (!StringUtils.isNotEmpty(emailAddress)) {
060            return "";
061        }
062        return emailAddress;
063    }
064
065    public void setEmailAddress(String emailAddress) {
066        this.emailAddress = emailAddress;
067    }
068
069    public String getSubject() {
070        if (!StringUtils.isNotEmpty(subject)) {
071            return "";
072        }
073        return subject;
074    }
075
076    public void setSubject(String subject) {
077        this.subject = subject;
078    }
079
080    public boolean redirects() {
081        return (StringUtils.isNotEmpty(getRedirectURL()));
082    }
083
084    public boolean isConfigured() {
085        return StringUtils.isNotEmpty(getEmailAddress()) &&
086               StringUtils.isNotEmpty(getSubject()) &&
087               StringUtils.isNotEmpty(getOfflineText());
088    }
089
090    /**
091     * Element name of the stanza extension.
092     */
093    public static final String ELEMENT_NAME = "offline-settings";
094
095    /**
096     * Namespace of the stanza extension.
097     */
098    public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
099
100    public OfflineSettings() {
101        super(ELEMENT_NAME, NAMESPACE);
102    }
103
104    /**
105     * Stanza extension provider for AgentStatusRequest packets.
106     */
107    public static class InternalProvider extends IQProvider<OfflineSettings> {
108
109        @Override
110        public OfflineSettings parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
111            OfflineSettings offlineSettings = new OfflineSettings();
112
113            boolean done = false;
114            String redirectPage = null;
115            String subject = null;
116            String offlineText = null;
117            String emailAddress = null;
118
119            while (!done) {
120                int eventType = parser.next();
121                if ((eventType == XmlPullParser.START_TAG) && ("redirectPage".equals(parser.getName()))) {
122                    redirectPage = parser.nextText();
123                }
124                else if ((eventType == XmlPullParser.START_TAG) && ("subject".equals(parser.getName()))) {
125                    subject = parser.nextText();
126                }
127                else if ((eventType == XmlPullParser.START_TAG) && ("offlineText".equals(parser.getName()))) {
128                    offlineText = parser.nextText();
129                }
130                else if ((eventType == XmlPullParser.START_TAG) && ("emailAddress".equals(parser.getName()))) {
131                    emailAddress = parser.nextText();
132                }
133                else if (eventType == XmlPullParser.END_TAG && "offline-settings".equals(parser.getName())) {
134                    done = true;
135                }
136            }
137
138            offlineSettings.setEmailAddress(emailAddress);
139            offlineSettings.setRedirectURL(redirectPage);
140            offlineSettings.setSubject(subject);
141            offlineSettings.setOfflineText(offlineText);
142            return offlineSettings;
143        }
144    }
145}
146