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.engine.sac;
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: CSSSelectorFactory.java 1733416 2016-03-03 07:07:13Z gadams $
39  */

40 public class CSSSelectorFactory implements SelectorFactory {
41
42     /**
43      * The instance of this class.
44      */

45     public static final SelectorFactory INSTANCE = new CSSSelectorFactory();
46
47     /**
48      * This class does not need to be instantiated.
49      */

50     protected CSSSelectorFactory() {
51     }
52
53     /**
54      * <b>SAC</b>: Implements {@link
55      * SelectorFactory#createConditionalSelector(SimpleSelector,Condition)}.
56      */

57     public ConditionalSelector createConditionalSelector
58         (SimpleSelector selector,
59          Condition condition)
60         throws CSSException {
61         return new CSSConditionalSelector(selector, condition);
62     }
63
64     /**
65      * <b>SAC</b>: Implements {@link
66      * org.w3c.css.sac.SelectorFactory#createAnyNodeSelector()}.
67      */

68     public SimpleSelector createAnyNodeSelector() throws CSSException {
69         throw new CSSException("Not implemented in CSS2");
70     }
71
72     /**
73      * <b>SAC</b>: Implements {@link
74      * org.w3c.css.sac.SelectorFactory#createRootNodeSelector()}.
75      */

76     public SimpleSelector createRootNodeSelector() throws CSSException {
77         throw new CSSException("Not implemented in CSS2");
78     }
79
80     /**
81      * <b>SAC</b>: Implements {@link
82      * org.w3c.css.sac.SelectorFactory#createNegativeSelector(SimpleSelector)}.
83      */

84     public NegativeSelector createNegativeSelector(SimpleSelector selector)
85         throws CSSException {
86         throw new CSSException("Not implemented in CSS2");
87     }
88
89     /**
90      * <b>SAC</b>: Implements {@link
91      * org.w3c.css.sac.SelectorFactory#createElementSelector(String,String)}.
92      */

93     public ElementSelector createElementSelector(String namespaceURI,
94                                                  String tagName)
95         throws CSSException {
96         return new CSSElementSelector(namespaceURI, tagName);
97     }
98
99     /**
100      * <b>SAC</b>: Implements {@link
101      * org.w3c.css.sac.SelectorFactory#createTextNodeSelector(String)}.
102      */

103     public CharacterDataSelector createTextNodeSelector(String data)
104         throws CSSException {
105         throw new CSSException("Not implemented in CSS2");
106     }
107
108     /**
109      * <b>SAC</b>: Implements {@link
110      * org.w3c.css.sac.SelectorFactory#createCDataSectionSelector(String)}.
111      */

112     public CharacterDataSelector createCDataSectionSelector(String data)
113         throws CSSException {
114         throw new CSSException("Not implemented in CSS2");
115     }
116
117     /**
118      * <b>SAC</b>: Implements {@link
119      * SelectorFactory#createProcessingInstructionSelector(String,String)}.
120      */

121     public ProcessingInstructionSelector createProcessingInstructionSelector
122         (String target,
123          String data) throws CSSException {
124         throw new CSSException("Not implemented in CSS2");
125     }
126
127     /**
128      * <b>SAC</b>: Implements {@link
129      * org.w3c.css.sac.SelectorFactory#createCommentSelector(String)}.
130      */

131     public CharacterDataSelector createCommentSelector(String data)
132         throws CSSException {
133         throw new CSSException("Not implemented in CSS2");
134     }
135
136     /**
137      * <b>SAC</b>: Implements {@link
138      * SelectorFactory#createPseudoElementSelector(String,String)}.
139      */

140     public ElementSelector createPseudoElementSelector(String namespaceURI,
141                                                        String pseudoName)
142         throws CSSException {
143         return new CSSPseudoElementSelector(namespaceURI, pseudoName);
144     }
145
146     /**
147      * <b>SAC</b>: Implements {@link
148      * SelectorFactory#createDescendantSelector(Selector,SimpleSelector)}.
149      */

150     public DescendantSelector createDescendantSelector
151         (Selector parent,
152          SimpleSelector descendant)
153         throws CSSException {
154         return new CSSDescendantSelector(parent, descendant);
155     }
156
157     /**
158      * <b>SAC</b>: Implements {@link
159      * SelectorFactory#createChildSelector(Selector,SimpleSelector)}.
160      */

161     public DescendantSelector createChildSelector(Selector parent,
162                                                   SimpleSelector child)
163         throws CSSException {
164         return new CSSChildSelector(parent, child);
165     }
166
167     /**
168      * <b>SAC</b>: Implements {@link
169      * SelectorFactory#createDirectAdjacentSelector(short,Selector,SimpleSelector)}.
170      */

171     public SiblingSelector createDirectAdjacentSelector
172         (short          nodeType,
173          Selector       child,
174          SimpleSelector directAdjacent)
175         throws CSSException {
176         return new CSSDirectAdjacentSelector(nodeType, child,
177                                                directAdjacent);
178     }
179 }
180