1 /*
2
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
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 */
19 package org.apache.batik.css.parser;
20
21 import org.w3c.css.sac.CSSException;
22 import org.w3c.css.sac.CharacterDataSelector;
23 import org.w3c.css.sac.Condition;
24 import org.w3c.css.sac.ConditionalSelector;
25 import org.w3c.css.sac.DescendantSelector;
26 import org.w3c.css.sac.ElementSelector;
27 import org.w3c.css.sac.NegativeSelector;
28 import org.w3c.css.sac.ProcessingInstructionSelector;
29 import org.w3c.css.sac.Selector;
30 import org.w3c.css.sac.SelectorFactory;
31 import org.w3c.css.sac.SiblingSelector;
32 import org.w3c.css.sac.SimpleSelector;
33
34 /**
35 * This class implements the {@link org.w3c.css.sac.SelectorFactory} interface.
36 *
37 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
38 * @version $Id: DefaultSelectorFactory.java 1733416 2016-03-03 07:07:13Z gadams $
39 */
40
41 public class DefaultSelectorFactory implements SelectorFactory {
42
43 /**
44 * The instance of this class.
45 */
46 public static final SelectorFactory INSTANCE =
47 new DefaultSelectorFactory();
48
49 /**
50 * This class does not need to be instantiated.
51 */
52 protected DefaultSelectorFactory() {
53 }
54
55 /**
56 * <b>SAC</b>: Implements {@link
57 * SelectorFactory#createConditionalSelector(SimpleSelector,Condition)}.
58 */
59 public ConditionalSelector createConditionalSelector
60 (SimpleSelector selector,
61 Condition condition)
62 throws CSSException {
63 return new DefaultConditionalSelector(selector, condition);
64 }
65
66 /**
67 * <b>SAC</b>: Implements {@link
68 * org.w3c.css.sac.SelectorFactory#createAnyNodeSelector()}.
69 */
70 public SimpleSelector createAnyNodeSelector() throws CSSException {
71 throw new CSSException("Not implemented in CSS2");
72 }
73
74 /**
75 * <b>SAC</b>: Implements {@link
76 * org.w3c.css.sac.SelectorFactory#createRootNodeSelector()}.
77 */
78 public SimpleSelector createRootNodeSelector() throws CSSException {
79 throw new CSSException("Not implemented in CSS2");
80 }
81
82 /**
83 * <b>SAC</b>: Implements {@link
84 * org.w3c.css.sac.SelectorFactory#createNegativeSelector(SimpleSelector)}.
85 */
86 public NegativeSelector createNegativeSelector(SimpleSelector selector)
87 throws CSSException {
88 throw new CSSException("Not implemented in CSS2");
89 }
90
91 /**
92 * <b>SAC</b>: Implements {@link
93 * org.w3c.css.sac.SelectorFactory#createElementSelector(String,String)}.
94 */
95 public ElementSelector createElementSelector(String namespaceURI,
96 String tagName)
97 throws CSSException {
98 return new DefaultElementSelector(namespaceURI, tagName);
99 }
100
101 /**
102 * <b>SAC</b>: Implements {@link
103 * org.w3c.css.sac.SelectorFactory#createTextNodeSelector(String)}.
104 */
105 public CharacterDataSelector createTextNodeSelector(String data)
106 throws CSSException {
107 throw new CSSException("Not implemented in CSS2");
108 }
109
110 /**
111 * <b>SAC</b>: Implements {@link
112 * org.w3c.css.sac.SelectorFactory#createCDataSectionSelector(String)}.
113 */
114 public CharacterDataSelector createCDataSectionSelector(String data)
115 throws CSSException {
116 throw new CSSException("Not implemented in CSS2");
117 }
118
119 /**
120 * <b>SAC</b>: Implements {@link
121 * SelectorFactory#createProcessingInstructionSelector(String,String)}.
122 */
123 public ProcessingInstructionSelector createProcessingInstructionSelector
124 (String target,
125 String data) throws CSSException {
126 throw new CSSException("Not implemented in CSS2");
127 }
128
129 /**
130 * <b>SAC</b>: Implements {@link
131 * org.w3c.css.sac.SelectorFactory#createCommentSelector(String)}.
132 */
133 public CharacterDataSelector createCommentSelector(String data)
134 throws CSSException {
135 throw new CSSException("Not implemented in CSS2");
136 }
137
138 /**
139 * <b>SAC</b>: Implements {@link
140 * SelectorFactory#createPseudoElementSelector(String,String)}.
141 */
142 public ElementSelector createPseudoElementSelector(String namespaceURI,
143 String pseudoName)
144 throws CSSException {
145 return new DefaultPseudoElementSelector(namespaceURI, pseudoName);
146 }
147
148 /**
149 * <b>SAC</b>: Implements {@link
150 * SelectorFactory#createDescendantSelector(Selector,SimpleSelector)}.
151 */
152 public DescendantSelector createDescendantSelector
153 (Selector parent,
154 SimpleSelector descendant)
155 throws CSSException {
156 return new DefaultDescendantSelector(parent, descendant);
157 }
158
159 /**
160 * <b>SAC</b>: Implements {@link
161 * SelectorFactory#createChildSelector(Selector,SimpleSelector)}.
162 */
163 public DescendantSelector createChildSelector(Selector parent,
164 SimpleSelector child)
165 throws CSSException {
166 return new DefaultChildSelector(parent, child);
167 }
168
169 /**
170 * <b>SAC</b>: Implements {@link
171 * SelectorFactory#createDirectAdjacentSelector(short,Selector,SimpleSelector)}.
172 */
173 public SiblingSelector createDirectAdjacentSelector
174 (short nodeType,
175 Selector child,
176 SimpleSelector directAdjacent)
177 throws CSSException {
178 return new DefaultDirectAdjacentSelector(nodeType, child,
179 directAdjacent);
180 }
181 }
182