001/**
002 *
003 * Copyright 2017-2020 Florian Schmaus
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.hints.element;
018
019import javax.xml.namespace.QName;
020
021import org.jivesoftware.smack.packet.MessageBuilder;
022import org.jivesoftware.smack.packet.MessageView;
023
024/**
025 * A "store" hint. Messages with this hint should be stored in permanent stores or archives.
026 *
027 * @see <a href="https://xmpp.org/extensions/xep-0334.html#sect-idm140684698220992">XEP-0334 ยง 4.4 Store</a>
028 */
029public final class StoreHint extends MessageProcessingHint {
030
031    public static final StoreHint INSTANCE = new StoreHint();
032
033    public static final String ELEMENT = "store";
034
035    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
036
037    private StoreHint() {
038    }
039
040    @Override
041    public String getElementName() {
042        return ELEMENT;
043    }
044
045    @Override
046    public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
047        return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
048    }
049
050    @Override
051    public MessageProcessingHintType getHintType() {
052        return MessageProcessingHintType.store;
053    }
054
055    public static StoreHint from(MessageView message) {
056        return message.getExtension(StoreHint.class);
057    }
058
059    public static boolean hasHint(MessageView message) {
060        return from(message) != null;
061    }
062
063    public static void set(MessageBuilder message) {
064        message.overrideExtension(INSTANCE);
065    }
066}