01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @author Alexey A. Ivanov
19: * @version $Revision$
20: */package javax.swing.text.html;
21:
22: final class Selector {
23: final SimpleSelector[] simpleSelectors;
24: final Specificity specificity;
25:
26: Selector(final String complexSelector) {
27: String[] selectors = complexSelector.split("\\s+");
28: simpleSelectors = new SimpleSelector[selectors.length];
29: for (int i = 0; i < selectors.length; i++) {
30: simpleSelectors[i] = new SimpleSelector(selectors[i]);
31: }
32: specificity = new Specificity(this );
33: }
34:
35: public String toString() {
36: final StringBuffer result = new StringBuffer();
37: result.append(simpleSelectors[0]);
38: for (int i = 1; i < simpleSelectors.length; i++) {
39: result.append(' ').append(simpleSelectors[i]);
40: }
41: return result.toString();
42: }
43:
44: boolean applies(final Selector styleSelector) {
45: int ssIndex = styleSelector.simpleSelectors.length - 1;
46: int index = simpleSelectors.length - 1;
47:
48: boolean result = false;
49: for (; ssIndex >= 0; ssIndex--) {
50: SimpleSelector simple = styleSelector.simpleSelectors[ssIndex];
51: result = false;
52: for (; index >= 0 && !result; index--) {
53: SimpleSelector ss = simpleSelectors[index];
54: if (simple.matches(ss.tag, ss.id, ss.clazz)) {
55: result = true;
56: }
57: }
58: }
59:
60: return result;
61: }
62:
63: SimpleSelector getLastSelector() {
64: return simpleSelectors[simpleSelectors.length - 1];
65: }
66: }
|