1 11 package org.eclipse.help.internal; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.help.internal.util.StringUtil; 17 import org.w3c.dom.Element ; 18 import org.w3c.dom.Node ; 19 import org.w3c.dom.NodeList ; 20 import org.xml.sax.Attributes ; 21 22 41 public abstract class FilterableUAElement { 42 43 private Map filters; 44 45 51 public void addFilters(Attributes attrs) { 52 if (attrs != null) { 54 String filterAttribute = attrs.getValue("filter"); if (filterAttribute != null) { 56 addFilter(filterAttribute); 57 } 58 } 59 } 60 61 69 public void addFilters(Element element) { 70 String filterAttribute = element.getAttribute("filter"); if (filterAttribute.length() > 0) { 73 addFilter(filterAttribute); 74 } 75 NodeList list = element.getChildNodes(); 77 for (int i=0;i<list.getLength();++i) { 78 Node node = list.item(i); 79 if (node.getNodeType() == Node.ELEMENT_NODE && "filter".equals(node.getNodeName())) { Element elementNode = (Element )node; 81 addFilter(elementNode.getAttribute("name"), elementNode.getAttribute("value")); } 83 } 84 } 85 86 92 public void addFilter(String nameAndValue) { 93 boolean isPositive = (nameAndValue.indexOf("!=") == -1); String [] tokens = StringUtil.split(nameAndValue, "!?="); String name = tokens[0]; 97 String value = tokens[1]; 98 if (!isPositive) { 99 value = '!' + value; 100 } 101 addFilter(name, value); 102 } 103 104 110 public void addFilter(String name, String value) { 111 if (filters == null) { 112 filters = new HashMap (); 113 } 114 filters.put(name, value); 115 } 116 117 123 public Map getFilters() { 124 return filters; 125 } 126 } 127 | Popular Tags |