1 27 package org.htmlparser.filters; 28 29 import java.util.Locale ; 30 31 import org.htmlparser.Attribute; 32 import org.htmlparser.Node; 33 import org.htmlparser.NodeFilter; 34 import org.htmlparser.Tag; 35 36 39 public class HasAttributeFilter implements NodeFilter 40 { 41 44 protected String mAttribute; 45 46 49 protected String mValue; 50 51 56 public HasAttributeFilter () 57 { 58 this ("", null); 59 } 60 61 65 public HasAttributeFilter (String attribute) 66 { 67 this (attribute, null); 68 } 69 70 75 public HasAttributeFilter (String attribute, String value) 76 { 77 mAttribute = attribute.toUpperCase (Locale.ENGLISH); 78 mValue = value; 79 } 80 81 85 public String getAttributeName () 86 { 87 return (mAttribute); 88 } 89 90 94 public void setAttributeName (String name) 95 { 96 mAttribute = name; 97 } 98 99 103 public String getAttributeValue () 104 { 105 return (mValue); 106 } 107 108 113 public void setAttributeValue (String value) 114 { 115 mValue = value; 116 } 117 118 122 public boolean accept (Node node) 123 { 124 Tag tag; 125 Attribute attribute; 126 boolean ret; 127 128 ret = false; 129 if (node instanceof Tag) 130 { 131 tag = (Tag)node; 132 attribute = tag.getAttributeEx (mAttribute); 133 ret = null != attribute; 134 if (ret && (null != mValue)) 135 ret = mValue.equals (attribute.getValue ()); 136 } 137 138 return (ret); 139 } 140 } 141 | Popular Tags |