3
Copyright 2002-2003 The Apache Software Foundation
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
3
Licensed to the Apache Software Foundation (ASF) under one or more
4
contributor license agreements. See the NOTICE file distributed with
5
this work for additional information regarding copyright ownership.
6
The ASF licenses this file to You under the Apache License, Version 2.0
7
(the "License"); you may not use this file except in compliance with
8
the License. You may obtain a copy of the License at
9
10
http://www.apache.org/licenses/LICENSE-2.0
25
26
* {@link org.w3c.css.sac.AttributeCondition} interface.
27
28
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
28
* @version $Id: CSSClassCondition.java,v 1.6 2004/08/18 07:12:51 vhardy Exp $
29
* @version $Id: CSSClassCondition.java 602579 2007-12-08 23:43:32Z cam $
30
31
public class CSSClassCondition extends CSSAttributeCondition {
35
36
public CSSClassCondition(String localName,
36
37
String namespaceURI,
38
super(localName, namespaceURI, true, value);
39
super(localName, namespaceURI, true, value);
42
43
* <b>SAC</b>: Implements {@link
43
44
* org.w3c.css.sac.Condition#getConditionType()}.
45
46
public short getConditionType() {
46
return SAC_CLASS_CONDITION;
47
return SAC_CLASS_CONDITION;
50
51
* Tests whether this condition matches the given element.
52
53
public boolean match(Element e, String pseudoE) {
53
54
if (!(e instanceof CSSStylableElement))
54
55
return false; // Can't match an unstylable element.
55
String attr = ((CSSStylableElement)e).getCSSClass();
56
String val = getValue();
57
int i = attr.indexOf(val);
61
if (i != 0 && !Character.isSpaceChar(attr.charAt(i - 1))) {
64
int j = i + val.length();
65
return (j == attr.length() ||
66
(j < attr.length() && Character.isSpaceChar(attr.charAt(j))));
56
String attr = ((CSSStylableElement)e).getCSSClass();
57
String val = getValue();
58
int attrLen = attr.length();
59
int valLen = val.length();
61
int i = attr.indexOf(val);
63
if (i == 0 || Character.isSpaceChar(attr.charAt(i - 1))) {
64
if (i + valLen == attrLen ||
65
Character.isSpaceChar(attr.charAt(i + valLen))) {
69
i = attr.indexOf(val, i + valLen);
70
75
* Returns a text representation of this object.
72
77
public String toString() {
73
return "." + getValue();
78
return '.' + getValue();