001    /*
002     * The MIT License
003     * Copyright (c) 2012 Microsoft Corporation
004     *
005     * Permission is hereby granted, free of charge, to any person obtaining a copy
006     * of this software and associated documentation files (the "Software"), to deal
007     * in the Software without restriction, including without limitation the rights
008     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009     * copies of the Software, and to permit persons to whom the Software is
010     * furnished to do so, subject to the following conditions:
011     *
012     * The above copyright notice and this permission notice shall be included in
013     * all copies or substantial portions of the Software.
014     *
015     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021     * THE SOFTWARE.
022     */
023    
024    package microsoft.exchange.webservices.data.misc.availability;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028    import microsoft.exchange.webservices.data.core.EwsUtilities;
029    import microsoft.exchange.webservices.data.core.XmlElementNames;
030    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
031    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
032    
033    import javax.xml.stream.XMLStreamException;
034    
035    /**
036     * Represents an Out of Office response.
037     */
038    public final class OofReply {
039    
040      /**
041       * The culture.
042       */
043      private String culture = "en-US";
044    
045      /**
046       * The message.
047       */
048      private String message;
049    
050      /**
051       * Writes an empty OofReply to XML.
052       *
053       * @param writer         the writer
054       * @param xmlElementName the xml element name
055       * @throws XMLStreamException the XML stream exception
056       */
057      public static void writeEmptyReplyToXml(EwsServiceXmlWriter writer, String xmlElementName) throws XMLStreamException {
058        writer.writeStartElement(XmlNamespace.Types, xmlElementName);
059        writer.writeEndElement(); // xmlElementName
060      }
061    
062      /**
063       * Initializes a new instance of the class.
064       */
065      public OofReply() {
066      }
067    
068      /**
069       * Initializes a new instance of the class.
070       *
071       * @param message the message
072       */
073      public OofReply(String message) {
074        this.message = message;
075      }
076    
077      /**
078       * Initializes a new instance of the class.
079       *
080       * @param message the message
081       * @return the oof reply from string
082       */
083      public static OofReply getOofReplyFromString(String message) {
084        return new OofReply(message);
085      }
086    
087      /**
088       * Gets the string from oof reply.
089       *
090       * @param oofReply the oof reply
091       * @return the string from oof reply
092       * @throws Exception the exception
093       */
094      public static String getStringFromOofReply(OofReply oofReply)
095          throws Exception {
096        EwsUtilities.validateParam(oofReply, "oofReply");
097        return oofReply.message;
098      }
099    
100      /**
101       * Loads from XML.
102       *
103       * @param reader         the reader
104       * @param xmlElementName the xml element name
105       * @throws Exception the exception
106       */
107      public void loadFromXml(EwsServiceXmlReader reader, String xmlElementName)
108          throws Exception {
109        reader.ensureCurrentNodeIsStartElement(XmlNamespace.Types,
110            xmlElementName);
111    
112        if (reader.hasAttributes()) {
113          this.setCulture(reader.readAttributeValue("xml:lang"));
114        }
115    
116        this.message = reader.readElementValue(XmlNamespace.Types,
117            XmlElementNames.Message);
118    
119        reader.readEndElement(XmlNamespace.Types, xmlElementName);
120      }
121    
122      /**
123       * Writes to XML.
124       *
125       * @param writer         the writer
126       * @param xmlElementName the xml element name
127       * @throws XMLStreamException the XML stream exception
128       * @throws ServiceXmlSerializationException the service xml serialization exception
129       */
130      public void writeToXml(EwsServiceXmlWriter writer, String xmlElementName)
131          throws XMLStreamException, ServiceXmlSerializationException {
132        writer.writeStartElement(XmlNamespace.Types, xmlElementName);
133    
134        if (this.culture != null) {
135          writer.writeAttributeValue("xml", "lang", this.culture);
136        }
137    
138        writer.writeElementValue(XmlNamespace.Types, XmlElementNames.Message,
139            this.message);
140    
141        writer.writeEndElement(); // xmlElementName
142      }
143    
144      /**
145       * Obtains a string representation of the reply.
146       *
147       * @return A string containing the reply message.
148       */
149      public String toString() {
150        return this.message;
151      }
152    
153      /**
154       * Gets the culture of the reply.
155       *
156       * @return the culture
157       */
158      public String getCulture() {
159        return this.culture;
160    
161      }
162    
163      /**
164       * Sets the culture.
165       *
166       * @param culture the new culture
167       */
168      public void setCulture(String culture) {
169        this.culture = culture;
170      }
171    
172      /**
173       * Gets  the the reply message.
174       *
175       * @return the message
176       */
177      public String getMessage() {
178        return this.message;
179      }
180    
181      /**
182       * Sets the message.
183       *
184       * @param message the new message
185       */
186      public void setMessage(String message) {
187        this.message = message;
188      }
189    
190    }