001/**
002 *
003 * Copyright © 2016 Fernando Ramirez
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 */
017package org.jivesoftware.smackx.chat_markers.element;
018
019import org.jivesoftware.smack.packet.ExtensionElement;
020import org.jivesoftware.smack.packet.Message;
021import org.jivesoftware.smack.util.XmlStringBuilder;
022
023/**
024 * Chat Markers elements (XEP-0333).
025 *
026 * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
027 *      Markers</a>
028 * @author Fernando Ramirez
029 *
030 */
031public class ChatMarkersElements {
032
033    public static final String NAMESPACE = "urn:xmpp:chat-markers:0";
034
035    /**
036     * Markable extension class.
037     *
038     * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
039     *      Markers</a>
040     * @author Fernando Ramirez
041     *
042     */
043    public static class MarkableExtension implements ExtensionElement {
044
045        /**
046         * markable element.
047         */
048        public static final String ELEMENT = "markable";
049
050        public MarkableExtension() {
051        }
052
053        @Override
054        public String getElementName() {
055            return ELEMENT;
056        }
057
058        @Override
059        public String getNamespace() {
060            return NAMESPACE;
061        }
062
063        @Override
064        public CharSequence toXML(String enclosingNamespace) {
065            XmlStringBuilder xml = new XmlStringBuilder(this);
066            xml.closeEmptyElement();
067            return xml;
068        }
069
070        public static MarkableExtension from(Message message) {
071            return (MarkableExtension) message.getExtension(ELEMENT, NAMESPACE);
072        }
073    }
074
075    /**
076     * Received extension class.
077     *
078     * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
079     *      Markers</a>
080     * @author Fernando Ramirez
081     *
082     */
083    public static class ReceivedExtension implements ExtensionElement {
084
085        /**
086         * received element.
087         */
088        public static final String ELEMENT = "received";
089
090        private final String id;
091
092        public ReceivedExtension(String id) {
093            this.id = id;
094        }
095
096        /**
097         * Get the id.
098         *
099         * @return the id
100         */
101        public String getId() {
102            return id;
103        }
104
105        @Override
106        public String getElementName() {
107            return ELEMENT;
108        }
109
110        @Override
111        public String getNamespace() {
112            return NAMESPACE;
113        }
114
115        @Override
116        public CharSequence toXML(String enclosingNamespace) {
117            XmlStringBuilder xml = new XmlStringBuilder(this);
118            xml.attribute("id", id);
119            xml.closeEmptyElement();
120            return xml;
121        }
122
123        public static ReceivedExtension from(Message message) {
124            return (ReceivedExtension) message.getExtension(ELEMENT, NAMESPACE);
125        }
126    }
127
128    /**
129     * Displayed extension class.
130     *
131     * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
132     *      Markers</a>
133     * @author Fernando Ramirez
134     *
135     */
136    public static class DisplayedExtension implements ExtensionElement {
137
138        /**
139         * displayed element.
140         */
141        public static final String ELEMENT = "displayed";
142
143        private final String id;
144
145        public DisplayedExtension(String id) {
146            this.id = id;
147        }
148
149        /**
150         * Get the id.
151         *
152         * @return the id
153         */
154        public String getId() {
155            return id;
156        }
157
158        @Override
159        public String getElementName() {
160            return ELEMENT;
161        }
162
163        @Override
164        public String getNamespace() {
165            return NAMESPACE;
166        }
167
168        @Override
169        public CharSequence toXML(String enclosingNamespace) {
170            XmlStringBuilder xml = new XmlStringBuilder(this);
171            xml.attribute("id", id);
172            xml.closeEmptyElement();
173            return xml;
174        }
175
176        public static DisplayedExtension from(Message message) {
177            return (DisplayedExtension) message.getExtension(ELEMENT, NAMESPACE);
178        }
179    }
180
181    /**
182     * Acknowledged extension class.
183     *
184     * @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat
185     *      Markers</a>
186     * @author Fernando Ramirez
187     *
188     */
189    public static class AcknowledgedExtension implements ExtensionElement {
190
191        /**
192         * acknowledged element.
193         */
194        public static final String ELEMENT = "acknowledged";
195
196        private final String id;
197
198        public AcknowledgedExtension(String id) {
199            this.id = id;
200        }
201
202        /**
203         * Get the id.
204         *
205         * @return the id
206         */
207        public String getId() {
208            return id;
209        }
210
211        @Override
212        public String getElementName() {
213            return ELEMENT;
214        }
215
216        @Override
217        public String getNamespace() {
218            return NAMESPACE;
219        }
220
221        @Override
222        public CharSequence toXML(String enclosingNamespace) {
223            XmlStringBuilder xml = new XmlStringBuilder(this);
224            xml.attribute("id", id);
225            xml.closeEmptyElement();
226            return xml;
227        }
228
229        public static AcknowledgedExtension from(Message message) {
230            return (AcknowledgedExtension) message.getExtension(ELEMENT, NAMESPACE);
231        }
232    }
233
234}