KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Set JavaDoc;
21
22 import org.w3c.dom.Element JavaDoc;
23
24 /**
25  * This class provides an implementation of the
26  * {@link org.w3c.css.sac.AttributeCondition} interface.
27  *
28  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
29  * @version $Id: CSSAttributeCondition.java,v 1.4 2004/08/18 07:12:51 vhardy Exp $
30  */

31 public class CSSAttributeCondition extends AbstractAttributeCondition {
32     /**
33      * The attribute's local name.
34      */

35     protected String JavaDoc localName;
36
37     /**
38      * The attribute's namespace URI.
39      */

40     protected String JavaDoc namespaceURI;
41
42     /**
43      * Whether this condition applies to specified attributes.
44      */

45     protected boolean specified;
46
47     /**
48      * Creates a new CSSAttributeCondition object.
49      */

50     public CSSAttributeCondition(String JavaDoc localName,
51                                  String JavaDoc namespaceURI,
52                                  boolean specified,
53                                  String JavaDoc value) {
54     super(value);
55     this.localName = localName;
56     this.namespaceURI = namespaceURI;
57     this.specified = specified;
58     }
59
60     /**
61      * Indicates whether some other object is "equal to" this one.
62      * @param obj the reference object with which to compare.
63      */

64     public boolean equals(Object JavaDoc obj) {
65     if (!super.equals(obj)) {
66         return false;
67     }
68     CSSAttributeCondition c = (CSSAttributeCondition)obj;
69     return c.namespaceURI.equals(namespaceURI) &&
70            c.localName.equals(localName) &&
71            c.specified == specified;
72     }
73
74     /**
75      * <b>SAC</b>: Implements {@link
76      * org.w3c.css.sac.Condition#getConditionType()}.
77      */

78     public short getConditionType() {
79     return SAC_ATTRIBUTE_CONDITION;
80     }
81     
82     /**
83      * <b>SAC</b>: Implements {@link
84      * org.w3c.css.sac.AttributeCondition#getNamespaceURI()}.
85      */

86     public String JavaDoc getNamespaceURI() {
87     return namespaceURI;
88     }
89
90     /**
91      * <b>SAC</b>: Implements {@link
92      * org.w3c.css.sac.AttributeCondition#getLocalName()}.
93      */

94     public String JavaDoc getLocalName() {
95     return localName;
96     }
97
98     /**
99      * <b>SAC</b>: Implements {@link
100      * org.w3c.css.sac.AttributeCondition#getSpecified()}.
101      */

102     public boolean getSpecified() {
103     return specified;
104     }
105
106     /**
107      * Tests whether this condition matches the given element.
108      */

109     public boolean match(Element JavaDoc e, String JavaDoc pseudoE) {
110     String JavaDoc val = getValue();
111     if (val == null) {
112         return !e.getAttribute(getLocalName()).equals("");
113     }
114     return e.getAttribute(getLocalName()).equals(val);
115     }
116
117     /**
118      * Fills the given set with the attribute names found in this selector.
119      */

120     public void fillAttributeSet(Set JavaDoc attrSet) {
121         attrSet.add(localName);
122     }
123
124     /**
125      * Returns a text representation of this object.
126      */

127     public String JavaDoc toString() {
128     if (value == null) {
129         return "[" + localName + "]";
130     }
131     return "[" + localName + "=\"" + value + "\"]";
132     }
133 }
134
Popular Tags