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.smackx.workgroup.util.ModelUtil;
  20. import org.jivesoftware.smack.packet.SimpleIQ;
  21. import org.jivesoftware.smack.provider.IQProvider;
  22. import org.xmlpull.v1.XmlPullParser;
  23. import org.xmlpull.v1.XmlPullParserException;

  24. public class OfflineSettings extends SimpleIQ {
  25.     private String redirectURL;

  26.     private String offlineText;
  27.     private String emailAddress;
  28.     private String subject;

  29.     public String getRedirectURL() {
  30.         if (!ModelUtil.hasLength(redirectURL)) {
  31.             return "";
  32.         }
  33.         return redirectURL;
  34.     }

  35.     public void setRedirectURL(String redirectURL) {
  36.         this.redirectURL = redirectURL;
  37.     }

  38.     public String getOfflineText() {
  39.         if (!ModelUtil.hasLength(offlineText)) {
  40.             return "";
  41.         }
  42.         return offlineText;
  43.     }

  44.     public void setOfflineText(String offlineText) {
  45.         this.offlineText = offlineText;
  46.     }

  47.     public String getEmailAddress() {
  48.         if (!ModelUtil.hasLength(emailAddress)) {
  49.             return "";
  50.         }
  51.         return emailAddress;
  52.     }

  53.     public void setEmailAddress(String emailAddress) {
  54.         this.emailAddress = emailAddress;
  55.     }

  56.     public String getSubject() {
  57.         if (!ModelUtil.hasLength(subject)) {
  58.             return "";
  59.         }
  60.         return subject;
  61.     }

  62.     public void setSubject(String subject) {
  63.         this.subject = subject;
  64.     }

  65.     public boolean redirects() {
  66.         return (ModelUtil.hasLength(getRedirectURL()));
  67.     }

  68.     public boolean isConfigured(){
  69.         return ModelUtil.hasLength(getEmailAddress()) &&
  70.                ModelUtil.hasLength(getSubject()) &&
  71.                ModelUtil.hasLength(getOfflineText());
  72.     }

  73.     /**
  74.      * Element name of the packet extension.
  75.      */
  76.     public static final String ELEMENT_NAME = "offline-settings";

  77.     /**
  78.      * Namespace of the packet extension.
  79.      */
  80.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  81.     public OfflineSettings() {
  82.         super(ELEMENT_NAME, NAMESPACE);
  83.     }

  84.     /**
  85.      * Packet extension provider for AgentStatusRequest packets.
  86.      */
  87.     public static class InternalProvider extends IQProvider<OfflineSettings> {

  88.         @Override
  89.         public OfflineSettings parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
  90.             OfflineSettings offlineSettings = new OfflineSettings();

  91.             boolean done = false;
  92.             String redirectPage = null;
  93.             String subject = null;
  94.             String offlineText = null;
  95.             String emailAddress = null;

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

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