KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > extra > spath > AttributePredicate


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.extra.spath;
18
19
20 /**
21  * <p>Represents a predicate expression concerning a single attribute.</p>
22  *
23  * @author Shawn Bayern
24  */

25 public class AttributePredicate extends Predicate {
26
27     private String JavaDoc attribute, target;
28
29     /**
30      * Constructs a new AttributePredicate, given an attribute name
31      * and a target literal (with which to test equality).
32      */

33     public AttributePredicate(String JavaDoc attribute, String JavaDoc target) {
34     if (attribute == null)
35         throw new IllegalArgumentException JavaDoc("non-null attribute needed");
36     if (attribute.indexOf(":") != -1)
37         throw new IllegalArgumentException JavaDoc(
38         "namespace-qualified attribute names are not currently " +
39         "supported");
40     this.attribute = attribute;
41
42     if (target == null)
43         throw new IllegalArgumentException JavaDoc("non-null target needed");
44     // strip quotation marks from target
45
this.target = target.substring(1, target.length() - 1);
46     }
47
48     /**
49      * Returns true if the given SAX AttributeList is suitable, given our
50      * attribute name and target; returns false otherwise.
51      */

52     public boolean isMatchingAttribute(org.xml.sax.Attributes JavaDoc a) {
53     String JavaDoc attValue = a.getValue("", attribute);
54     return (attValue != null && attValue.equals(target));
55     }
56 }
57
Popular Tags