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