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