1 /*
2 
3    Copyright 2002, 2014  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 
19 /* This class copied from org.apache.batik.css.engine.sac */
20 
21 package org.eclipse.e4.ui.css.core.impl.sac;
22 
23 import org.w3c.css.sac.AttributeCondition;
24 import org.w3c.css.sac.CSSException;
25 import org.w3c.css.sac.CombinatorCondition;
26 import org.w3c.css.sac.Condition;
27 import org.w3c.css.sac.ConditionFactory;
28 import org.w3c.css.sac.ContentCondition;
29 import org.w3c.css.sac.LangCondition;
30 import org.w3c.css.sac.NegativeCondition;
31 import org.w3c.css.sac.PositionalCondition;
32 
33 /**
34  * This class provides an implementation of the
35  * {@link org.w3c.css.sac.ConditionFactory} interface.
36  */
37 public class CSSConditionFactoryImpl implements ConditionFactory {
38 
39 	private static final String NOT_IMPLEMENTED_IN_CSS2 = "Not implemented in CSS2"; //$NON-NLS-1$
40 
41 	/**
42 	 * The class attribute namespace URI.
43 	 */
44 	protected String classNamespaceURI;
45 
46 	/**
47 	 * The class attribute local name.
48 	 */
49 	protected String classLocalName;
50 
51 	/**
52 	 * The id attribute namespace URI.
53 	 */
54 	protected String idNamespaceURI;
55 
56 	/**
57 	 * The id attribute local name.
58 	 */
59 	protected String idLocalName;
60 
61 	/**
62 	 * Creates a new condition factory.
63 	 */
CSSConditionFactoryImpl(String cns, String cln, String idns, String idln)64 	public CSSConditionFactoryImpl(String cns, String cln, String idns,
65 			String idln) {
66 		classNamespaceURI = cns;
67 		classLocalName = cln;
68 		idNamespaceURI = idns;
69 		idLocalName = idln;
70 	}
71 
72 	/**
73 	 * <b>SAC</b>: Implements {@link
74 	 * ConditionFactory#createAndCondition(Condition,Condition)}.
75 	 */
76 	@Override
createAndCondition(Condition first, Condition second)77 	public CombinatorCondition createAndCondition(Condition first,
78 			Condition second) throws CSSException {
79 		return new CSSAndConditionImpl(first, second);
80 	}
81 
82 	/**
83 	 * <b>SAC</b>: Implements {@link
84 	 * ConditionFactory#createOrCondition(Condition,Condition)}.
85 	 */
86 	@Override
createOrCondition(Condition first, Condition second)87 	public CombinatorCondition createOrCondition(Condition first,
88 			Condition second) throws CSSException {
89 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
90 	}
91 
92 	/**
93 	 * <b>SAC</b>: Implements {@link
94 	 * org.w3c.css.sac.ConditionFactory#createNegativeCondition(Condition)}.
95 	 */
96 	@Override
createNegativeCondition(Condition condition)97 	public NegativeCondition createNegativeCondition(Condition condition)
98 			throws CSSException {
99 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
100 	}
101 
102 	/**
103 	 * <b>SAC</b>: Implements {@link
104 	 * ConditionFactory#createPositionalCondition(int,boolean,boolean)}.
105 	 */
106 	@Override
createPositionalCondition(int position, boolean typeNode, boolean type)107 	public PositionalCondition createPositionalCondition(int position,
108 			boolean typeNode, boolean type) throws CSSException {
109 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
110 	}
111 
112 	/**
113 	 * <b>SAC</b>: Implements {@link
114 	 * ConditionFactory#createAttributeCondition(String,String,boolean,String)}.
115 	 */
116 	@Override
createAttributeCondition(String localName, String namespaceURI, boolean specified, String value)117 	public AttributeCondition createAttributeCondition(String localName,
118 			String namespaceURI, boolean specified, String value)
119 			throws CSSException {
120 		return new CSSAttributeConditionImpl(localName, namespaceURI, specified,
121 				value);
122 	}
123 
124 	/**
125 	 * <b>SAC</b>: Implements {@link
126 	 * org.w3c.css.sac.ConditionFactory#createIdCondition(String)}.
127 	 */
128 	@Override
createIdCondition(String value)129 	public AttributeCondition createIdCondition(String value)
130 			throws CSSException {
131 		return new CSSIdConditionImpl(idNamespaceURI, idLocalName, value);
132 	}
133 
134 	/**
135 	 * <b>SAC</b>: Implements {@link
136 	 * org.w3c.css.sac.ConditionFactory#createLangCondition(String)}.
137 	 */
138 	@Override
createLangCondition(String lang)139 	public LangCondition createLangCondition(String lang) throws CSSException {
140 		return new CSSLangConditionImpl(lang);
141 	}
142 
143 	/**
144 	 * <b>SAC</b>: Implements {@link
145 	 * ConditionFactory#createOneOfAttributeCondition(String,String,boolean,String)}.
146 	 */
147 	@Override
createOneOfAttributeCondition(String localName, String nsURI, boolean specified, String value)148 	public AttributeCondition createOneOfAttributeCondition(String localName,
149 			String nsURI, boolean specified, String value) throws CSSException {
150 		return new CSSOneOfAttributeConditionImpl(localName, nsURI, specified,
151 				value);
152 	}
153 
154 	/**
155 	 * <b>SAC</b>: Implements {@link
156 	 * ConditionFactory#createBeginHyphenAttributeCondition(String,String,boolean,String)}.
157 	 */
158 	@Override
createBeginHyphenAttributeCondition( String localName, String namespaceURI, boolean specified, String value)159 	public AttributeCondition createBeginHyphenAttributeCondition(
160 			String localName, String namespaceURI, boolean specified,
161 			String value) throws CSSException {
162 		return new CSSBeginHyphenAttributeConditionImpl(localName,
163 				namespaceURI, specified, value);
164 	}
165 
166 	/**
167 	 * <b>SAC</b>: Implements {@link
168 	 * org.w3c.css.sac.ConditionFactory#createClassCondition(String,String)}.
169 	 */
170 	@Override
createClassCondition(String namespaceURI, String value)171 	public AttributeCondition createClassCondition(String namespaceURI,
172 			String value) throws CSSException {
173 		return new CSSClassConditionImpl(classLocalName, classNamespaceURI, value);
174 	}
175 
176 	/**
177 	 * <b>SAC</b>: Implements {@link
178 	 * ConditionFactory#createPseudoClassCondition(String,String)}.
179 	 */
180 	@Override
createPseudoClassCondition(String namespaceURI, String value)181 	public AttributeCondition createPseudoClassCondition(String namespaceURI,
182 			String value) throws CSSException {
183 		return new CSSPseudoClassConditionImpl(namespaceURI, value);
184 	}
185 
186 	/**
187 	 * <b>SAC</b>: Implements {@link
188 	 * org.w3c.css.sac.ConditionFactory#createOnlyChildCondition()}.
189 	 */
190 	@Override
createOnlyChildCondition()191 	public Condition createOnlyChildCondition() throws CSSException {
192 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
193 	}
194 
195 	/**
196 	 * <b>SAC</b>: Implements {@link
197 	 * org.w3c.css.sac.ConditionFactory#createOnlyTypeCondition()}.
198 	 */
199 	@Override
createOnlyTypeCondition()200 	public Condition createOnlyTypeCondition() throws CSSException {
201 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
202 	}
203 
204 	/**
205 	 * <b>SAC</b>: Implements {@link
206 	 * org.w3c.css.sac.ConditionFactory#createContentCondition(String)}.
207 	 */
208 	@Override
createContentCondition(String data)209 	public ContentCondition createContentCondition(String data)
210 			throws CSSException {
211 		throw new CSSException(NOT_IMPLEMENTED_IN_CSS2);
212 	}
213 }
214