/*
 * ElementAttributeFilter.java
 *
 * Copyright 2011 John W Dawson
 *
 * This code is distributed under the terms of the GNU General Public License, version 3
 *
 * A filter to find elements with given name and a particular attribute
 */

import org.jdom2.filter.*;
import org.jdom2.*;
public class ElementAttributeFilter extends ElementFilter
{
  private String attributeName;
  private String attributeValue;
  
  public ElementAttributeFilter (String name, String attributeName, String attributeValue)
  {
    super (name);
    this.attributeName = attributeName;
    this.attributeValue = attributeValue;
  }
  
  public Element filter (java.lang.Object obj)
  {
    // First check that object is an element with required name
    Element element = super.filter (obj);
    if (element != null)
    {
      // Now check if it has required attribute value
      return attributeValue.equals (element.getAttributeValue (attributeName)) ? element : null;
    }
    else
    {
      return null;
    }
  }
}
    