OfflineSettings.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.smack.packet.IqData;
  20. import org.jivesoftware.smack.packet.SimpleIQ;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.provider.IqProvider;
  23. import org.jivesoftware.smack.util.StringUtils;
  24. import org.jivesoftware.smack.xml.XmlPullParser;
  25. import org.jivesoftware.smack.xml.XmlPullParserException;

  26. public class OfflineSettings extends SimpleIQ {
  27.     private String redirectURL;

  28.     private String offlineText;
  29.     private String emailAddress;
  30.     private String subject;

  31.     public String getRedirectURL() {
  32.         if (!StringUtils.isNotEmpty(redirectURL)) {
  33.             return "";
  34.         }
  35.         return redirectURL;
  36.     }

  37.     public void setRedirectURL(String redirectURL) {
  38.         this.redirectURL = redirectURL;
  39.     }

  40.     public String getOfflineText() {
  41.         if (!StringUtils.isNotEmpty(offlineText)) {
  42.             return "";
  43.         }
  44.         return offlineText;
  45.     }

  46.     public void setOfflineText(String offlineText) {
  47.         this.offlineText = offlineText;
  48.     }

  49.     public String getEmailAddress() {
  50.         if (!StringUtils.isNotEmpty(emailAddress)) {
  51.             return "";
  52.         }
  53.         return emailAddress;
  54.     }

  55.     public void setEmailAddress(String emailAddress) {
  56.         this.emailAddress = emailAddress;
  57.     }

  58.     public String getSubject() {
  59.         if (!StringUtils.isNotEmpty(subject)) {
  60.             return "";
  61.         }
  62.         return subject;
  63.     }

  64.     public void setSubject(String subject) {
  65.         this.subject = subject;
  66.     }

  67.     public boolean redirects() {
  68.         return StringUtils.isNotEmpty(getRedirectURL());
  69.     }

  70.     public boolean isConfigured() {
  71.         return StringUtils.isNotEmpty(getEmailAddress()) &&
  72.                StringUtils.isNotEmpty(getSubject()) &&
  73.                StringUtils.isNotEmpty(getOfflineText());
  74.     }

  75.     /**
  76.      * Element name of the stanza extension.
  77.      */
  78.     public static final String ELEMENT_NAME = "offline-settings";

  79.     /**
  80.      * Namespace of the stanza extension.
  81.      */
  82.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  83.     public OfflineSettings() {
  84.         super(ELEMENT_NAME, NAMESPACE);
  85.     }

  86.     /**
  87.      * Stanza extension provider for AgentStatusRequest packets.
  88.      */
  89.     public static class InternalProvider extends IqProvider<OfflineSettings> {

  90.         @Override
  91.         public OfflineSettings parse(XmlPullParser parser, int initialDepth, IqData iqData, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException {
  92.             OfflineSettings offlineSettings = new OfflineSettings();

  93.             boolean done = false;
  94.             String redirectPage = null;
  95.             String subject = null;
  96.             String offlineText = null;
  97.             String emailAddress = null;

  98.             while (!done) {
  99.                 XmlPullParser.Event eventType = parser.next();
  100.                 if (eventType == XmlPullParser.Event.START_ELEMENT && "redirectPage".equals(parser.getName())) {
  101.                     redirectPage = parser.nextText();
  102.                 }
  103.                 else if (eventType == XmlPullParser.Event.START_ELEMENT && "subject".equals(parser.getName())) {
  104.                     subject = parser.nextText();
  105.                 }
  106.                 else if (eventType == XmlPullParser.Event.START_ELEMENT && "offlineText".equals(parser.getName())) {
  107.                     offlineText = parser.nextText();
  108.                 }
  109.                 else if (eventType == XmlPullParser.Event.START_ELEMENT && "emailAddress".equals(parser.getName())) {
  110.                     emailAddress = parser.nextText();
  111.                 }
  112.                 else if (eventType == XmlPullParser.Event.END_ELEMENT && "offline-settings".equals(parser.getName())) {
  113.                     done = true;
  114.                 }
  115.             }

  116.             offlineSettings.setEmailAddress(emailAddress);
  117.             offlineSettings.setRedirectURL(redirectPage);
  118.             offlineSettings.setSubject(subject);
  119.             offlineSettings.setOfflineText(offlineText);
  120.             return offlineSettings;
  121.         }
  122.     }
  123. }