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 org.jivesoftware.smack.packet.Message; 020 021/** 022 * A "no permanent store" hint. Messages with this hint should not be stored in permanent stores or archives. 023 * 024 * @see <a href="https://xmpp.org/extensions/xep-0334.html#no-permanent-store">XEP-0334 ยง 4.1 No permanent store</a> 025 */ 026public final class NoPermanentStoreHint extends MessageProcessingHint { 027 028 public static final NoPermanentStoreHint INSTANCE = new NoPermanentStoreHint(); 029 030 public static final String ELEMENT = "no-permanent-store"; 031 032 private NoPermanentStoreHint() { 033 } 034 035 @Override 036 public String getElementName() { 037 return ELEMENT; 038 } 039 040 @Override 041 public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 042 return '<' + ELEMENT + " xmlns='" + NAMESPACE + "'/>"; 043 } 044 045 @Override 046 public MessageProcessingHintType getHintType() { 047 return MessageProcessingHintType.no_permanent_store; 048 } 049 050 public static NoPermanentStoreHint from(Message message) { 051 return (NoPermanentStoreHint) message.getExtensionElement(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 if (StoreHint.hasHint(message)) { 060 // No need to set the no-permanent-store hint when a no-store hint is already set. 061 return; 062 } 063 message.overrideExtension(INSTANCE); 064 } 065 066 public static void setExplicitly(Message message) { 067 message.addExtension(INSTANCE); 068 } 069}