KickJava   Java API By Example, From Geeks To Geeks.

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


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

32
33 public class CSSLangCondition
34     implements LangCondition,
35            ExtendedCondition {
36     /**
37      * The language.
38      */

39     protected String JavaDoc lang;
40
41     /**
42      * Creates a new LangCondition object.
43      */

44     public CSSLangCondition(String JavaDoc lang) {
45     this.lang = lang;
46     }
47
48     /**
49      * Indicates whether some other object is "equal to" this one.
50      * @param obj the reference object with which to compare.
51      */

52     public boolean equals(Object JavaDoc obj) {
53     if (obj == null || !(obj.getClass() != getClass())) {
54         return false;
55     }
56     CSSLangCondition c = (CSSLangCondition)obj;
57     return c.lang.equals(lang);
58     }
59
60     /**
61      * <b>SAC</b>: Implements {@link
62      * org.w3c.css.sac.Condition#getConditionType()}.
63      */

64     public short getConditionType() {
65     return SAC_LANG_CONDITION;
66     }
67
68     /**
69      * <b>SAC</b>: Implements {@link org.w3c.css.sac.LangCondition#getLang()}.
70      */

71     public String JavaDoc getLang() {
72     return lang;
73     }
74
75     /**
76      * Returns the specificity of this condition.
77      */

78     public int getSpecificity() {
79     return 1 << 8;
80     }
81
82     /**
83      * Tests whether this condition matches the given element.
84      */

85     public boolean match(Element JavaDoc e, String JavaDoc pseudoE) {
86     return e.getAttribute("lang").startsWith(getLang());
87     }
88
89     /**
90      * Fills the given set with the attribute names found in this selector.
91      */

92     public void fillAttributeSet(Set JavaDoc attrSet) {
93         attrSet.add("lang");
94     }
95
96     /**
97      * Returns a text representation of this object.
98      */

99     public String JavaDoc toString() {
100     return ":lang(" + lang + ")";
101     }
102 }
103
Popular Tags