001/** 002 * 003 * Copyright 2003-2007 Jive Software. 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 */ 017 018package org.jivesoftware.smack.filter; 019 020import org.jivesoftware.smack.packet.ExtensionElement; 021import org.jivesoftware.smack.packet.Stanza; 022import org.jivesoftware.smack.util.StringUtils; 023 024/** 025 * Filters for packets with a particular type of stanza(/packet) extension. 026 * 027 * @author Matt Tucker 028 * @deprecated use {@link StanzaExtensionFilter} instead. 029 */ 030@Deprecated 031public class PacketExtensionFilter implements StanzaFilter { 032 033 private final String elementName; 034 private final String namespace; 035 036 /** 037 * Creates a new stanza(/packet) extension filter. Packets will pass the filter if 038 * they have a stanza(/packet) extension that matches the specified element name 039 * and namespace. 040 * 041 * @param elementName the XML element name of the stanza(/packet) extension. 042 * @param namespace the XML namespace of the stanza(/packet) extension. 043 */ 044 public PacketExtensionFilter(String elementName, String namespace) { 045 StringUtils.requireNotNullOrEmpty(namespace, "namespace must not be null or empty"); 046 047 this.elementName = elementName; 048 this.namespace = namespace; 049 } 050 051 /** 052 * Creates a new stanza(/packet) extension filter. Packets will pass the filter if they have a packet 053 * extension that matches the specified namespace. 054 * 055 * @param namespace the XML namespace of the stanza(/packet) extension. 056 */ 057 public PacketExtensionFilter(String namespace) { 058 this(null, namespace); 059 } 060 061 /** 062 * Creates a new stanza(/packet) extension filter for the given stanza(/packet) extension. 063 * 064 * @param packetExtension 065 */ 066 public PacketExtensionFilter(ExtensionElement packetExtension) { 067 this(packetExtension.getElementName(), packetExtension.getNamespace()); 068 } 069 070 @Override 071 public boolean accept(Stanza packet) { 072 return packet.hasExtension(elementName, namespace); 073 } 074 075 @Override 076 public String toString() { 077 return getClass().getSimpleName() + ": element=" + elementName + " namespace=" + namespace; 078 } 079}