KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > sac > CSSElementSelector


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

18 package org.apache.batik.css.engine.sac;
19
20 import org.w3c.dom.Element JavaDoc;
21
22 /**
23  * This class implements the {@link org.w3c.css.sac.ElementSelector} interface.
24  *
25  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
26  * @version $Id: CSSElementSelector.java,v 1.4 2005/03/29 10:48:02 deweese Exp $
27  */

28 public class CSSElementSelector extends AbstractElementSelector {
29
30     /**
31      * Creates a new ElementSelector object.
32      */

33     public CSSElementSelector(String JavaDoc uri, String JavaDoc name) {
34     super(uri, name);
35     }
36
37     /**
38      * <b>SAC</b>: Implements {@link
39      * org.w3c.css.sac.Selector#getSelectorType()}.
40      */

41     public short getSelectorType() {
42     return SAC_ELEMENT_NODE_SELECTOR;
43     }
44
45     /**
46      * Tests whether this selector matches the given element.
47      */

48     public boolean match(Element JavaDoc e, String JavaDoc pseudoE) {
49     String JavaDoc name = getLocalName();
50     if (name == null) {
51         return true;
52     }
53         String JavaDoc eName;
54         if (e.getPrefix() == null) eName = e.getNodeName();
55         else eName = e.getLocalName();
56         // According to CSS 2 section 5.1 element
57
// names in selectors are case-sensitive for XML.
58
return eName.equals(name);
59         // For HTML
60
// return eName.equalsIgnoreCase(name);
61
}
62
63     /**
64      * Returns the specificity of this selector.
65      */

66     public int getSpecificity() {
67     return (getLocalName() == null) ? 0 : 1;
68     }
69
70     /**
71      * Returns a representation of the selector.
72      */

73     public String JavaDoc toString() {
74     String JavaDoc name = getLocalName();
75     if (name == null) {
76         return "*";
77     }
78     return name;
79     }
80 }
81
Popular Tags