001/**
002 *
003 * Copyright 2017 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 org.jivesoftware.smack.packet.Message;
020
021/**
022 * A "no store" hint. Messages with this hint should not be stored in stores or archives.
023 *
024 * <a href="https://xmpp.org/extensions/xep-0334.html#no-store">XEP-0334 ยง 4.2 No store</a>
025 */
026public final class NoStoreHint extends MessageProcessingHint {
027
028    public static final NoStoreHint INSTANCE = new NoStoreHint();
029
030    public static final String ELEMENT = "no-store";
031
032    private NoStoreHint() {
033    }
034
035    @Override
036    public String getElementName() {
037        return ELEMENT;
038    }
039
040    @Override
041    public String toXML(String enclosingNamespace) {
042        return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>";
043    }
044
045    @Override
046    public MessageProcessingHintType getHintType() {
047        return MessageProcessingHintType.no_store;
048    }
049
050    public static NoStoreHint from(Message message) {
051        return message.getExtension(ELEMENT, NAMESPACE);
052    }
053
054    public static boolean hasHint(Message message) {
055        return from(message) != null;
056    }
057
058    public static void set(Message message) {
059        message.overrideExtension(INSTANCE);
060    }
061}