• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * $Revision$
3  * $Date$
4  *
5  * Copyright 2003-2007 Jive Software.
6  *
7  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 package org.jivesoftware.smackx.workgroup.settings;
21 
22 import org.jivesoftware.smackx.workgroup.util.ModelUtil;
23 import org.jivesoftware.smack.packet.IQ;
24 import org.jivesoftware.smack.provider.IQProvider;
25 import org.xmlpull.v1.XmlPullParser;
26 
27 public class OfflineSettings extends IQ {
28     private String redirectURL;
29 
30     private String offlineText;
31     private String emailAddress;
32     private String subject;
33 
getRedirectURL()34     public String getRedirectURL() {
35         if (!ModelUtil.hasLength(redirectURL)) {
36             return "";
37         }
38         return redirectURL;
39     }
40 
setRedirectURL(String redirectURL)41     public void setRedirectURL(String redirectURL) {
42         this.redirectURL = redirectURL;
43     }
44 
getOfflineText()45     public String getOfflineText() {
46         if (!ModelUtil.hasLength(offlineText)) {
47             return "";
48         }
49         return offlineText;
50     }
51 
setOfflineText(String offlineText)52     public void setOfflineText(String offlineText) {
53         this.offlineText = offlineText;
54     }
55 
getEmailAddress()56     public String getEmailAddress() {
57         if (!ModelUtil.hasLength(emailAddress)) {
58             return "";
59         }
60         return emailAddress;
61     }
62 
setEmailAddress(String emailAddress)63     public void setEmailAddress(String emailAddress) {
64         this.emailAddress = emailAddress;
65     }
66 
getSubject()67     public String getSubject() {
68         if (!ModelUtil.hasLength(subject)) {
69             return "";
70         }
71         return subject;
72     }
73 
setSubject(String subject)74     public void setSubject(String subject) {
75         this.subject = subject;
76     }
77 
redirects()78     public boolean redirects() {
79         return (ModelUtil.hasLength(getRedirectURL()));
80     }
81 
isConfigured()82     public boolean isConfigured(){
83         return ModelUtil.hasLength(getEmailAddress()) &&
84                ModelUtil.hasLength(getSubject()) &&
85                ModelUtil.hasLength(getOfflineText());
86     }
87 
88     /**
89      * Element name of the packet extension.
90      */
91     public static final String ELEMENT_NAME = "offline-settings";
92 
93     /**
94      * Namespace of the packet extension.
95      */
96     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
97 
getChildElementXML()98     public String getChildElementXML() {
99         StringBuilder buf = new StringBuilder();
100 
101         buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
102         buf.append('"');
103         buf.append(NAMESPACE);
104         buf.append('"');
105         buf.append("></").append(ELEMENT_NAME).append("> ");
106         return buf.toString();
107     }
108 
109 
110     /**
111      * Packet extension provider for AgentStatusRequest packets.
112      */
113     public static class InternalProvider implements IQProvider {
114 
parseIQ(XmlPullParser parser)115         public IQ parseIQ(XmlPullParser parser) throws Exception {
116             if (parser.getEventType() != XmlPullParser.START_TAG) {
117                 throw new IllegalStateException("Parser not in proper position, or bad XML.");
118             }
119 
120             OfflineSettings offlineSettings = new OfflineSettings();
121 
122             boolean done = false;
123             String redirectPage = null;
124             String subject = null;
125             String offlineText = null;
126             String emailAddress = null;
127 
128             while (!done) {
129                 int eventType = parser.next();
130                 if ((eventType == XmlPullParser.START_TAG) && ("redirectPage".equals(parser.getName()))) {
131                     redirectPage = parser.nextText();
132                 }
133                 else if ((eventType == XmlPullParser.START_TAG) && ("subject".equals(parser.getName()))) {
134                     subject = parser.nextText();
135                 }
136                 else if ((eventType == XmlPullParser.START_TAG) && ("offlineText".equals(parser.getName()))) {
137                     offlineText = parser.nextText();
138                 }
139                 else if ((eventType == XmlPullParser.START_TAG) && ("emailAddress".equals(parser.getName()))) {
140                     emailAddress = parser.nextText();
141                 }
142                 else if (eventType == XmlPullParser.END_TAG && "offline-settings".equals(parser.getName())) {
143                     done = true;
144                 }
145             }
146 
147             offlineSettings.setEmailAddress(emailAddress);
148             offlineSettings.setRedirectURL(redirectPage);
149             offlineSettings.setSubject(subject);
150             offlineSettings.setOfflineText(offlineText);
151             return offlineSettings;
152         }
153     }
154 }
155 
156