01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
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.value;
20:
21: import org.apache.batik.css.engine.CSSEngine;
22: import org.w3c.css.sac.LexicalUnit;
23: import org.w3c.dom.DOMException;
24: import org.w3c.dom.css.CSSPrimitiveValue;
25:
26: /**
27: * This class provides a manager for the property with support for
28: * identifier values.
29: *
30: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
31: * @version $Id: IdentifierManager.java 475685 2006-11-16 11:16:05Z cam $
32: */
33: public abstract class IdentifierManager extends AbstractValueManager {
34:
35: /**
36: * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
37: */
38: public Value createValue(LexicalUnit lu, CSSEngine engine)
39: throws DOMException {
40: switch (lu.getLexicalUnitType()) {
41: case LexicalUnit.SAC_INHERIT:
42: return ValueConstants.INHERIT_VALUE;
43:
44: case LexicalUnit.SAC_IDENT:
45: String s = lu.getStringValue().toLowerCase().intern();
46: Object v = getIdentifiers().get(s);
47: if (v == null) {
48: throw createInvalidIdentifierDOMException(lu
49: .getStringValue());
50: }
51: return (Value) v;
52:
53: default:
54: throw createInvalidLexicalUnitDOMException(lu
55: .getLexicalUnitType());
56: }
57: }
58:
59: /**
60: * Implements {@link
61: * ValueManager#createStringValue(short,String,CSSEngine)}.
62: */
63: public Value createStringValue(short type, String value,
64: CSSEngine engine) throws DOMException {
65: if (type != CSSPrimitiveValue.CSS_IDENT) {
66: throw createInvalidStringTypeDOMException(type);
67: }
68: Object v = getIdentifiers().get(value.toLowerCase().intern());
69: if (v == null) {
70: throw createInvalidIdentifierDOMException(value);
71: }
72: return (Value) v;
73: }
74:
75: /**
76: * Returns the map that contains the name/value mappings for each
77: * possible identifiers.
78: */
79: public abstract StringMap getIdentifiers();
80: }
|