KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > svg > SpacingManager


1 /*
2
3    Copyright 2002-2003 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 package org.apache.batik.css.engine.value.svg;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.value.LengthManager;
22 import org.apache.batik.css.engine.value.Value;
23 import org.apache.batik.css.engine.value.ValueManager;
24 import org.apache.batik.util.CSSConstants;
25 import org.w3c.css.sac.LexicalUnit;
26 import org.w3c.dom.DOMException JavaDoc;
27 import org.w3c.dom.css.CSSPrimitiveValue;
28
29 /**
30  * This class provides a manager for the '*-spacing' property values.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: SpacingManager.java,v 1.5 2005/03/27 08:58:31 cam Exp $
34  */

35 public class SpacingManager extends LengthManager {
36     
37     /**
38      * The handled property.
39      */

40     protected String JavaDoc property;
41
42     /**
43      * Creates a new SpacingManager.
44      */

45     public SpacingManager(String JavaDoc prop) {
46         property = prop;
47     }
48
49
50     /**
51      * Implements {@link ValueManager#isInheritedProperty()}.
52      */

53     public boolean isInheritedProperty() {
54     return true;
55     }
56
57     /**
58      * Implements {@link ValueManager#getPropertyName()}.
59      */

60     public String JavaDoc getPropertyName() {
61     return property;
62     }
63     
64     /**
65      * Implements {@link ValueManager#getDefaultValue()}.
66      */

67     public Value getDefaultValue() {
68         return SVGValueConstants.NORMAL_VALUE;
69     }
70
71     /**
72      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
73      */

74     public Value createValue(LexicalUnit lu, CSSEngine engine)
75         throws DOMException JavaDoc {
76     switch (lu.getLexicalUnitType()) {
77     case LexicalUnit.SAC_INHERIT:
78             return SVGValueConstants.INHERIT_VALUE;
79
80         case LexicalUnit.SAC_IDENT:
81             if (lu.getStringValue().equalsIgnoreCase
82                 (CSSConstants.CSS_NORMAL_VALUE)) {
83                 return SVGValueConstants.NORMAL_VALUE;
84             }
85             throw createInvalidIdentifierDOMException(lu.getStringValue());
86         }
87         return super.createValue(lu, engine);
88     }
89
90     /**
91      * Implements {@link
92      * ValueManager#createStringValue(short,String,CSSEngine)}.
93      */

94     public Value createStringValue(short type, String JavaDoc value, CSSEngine engine)
95     throws DOMException JavaDoc {
96     if (type != CSSPrimitiveValue.CSS_IDENT) {
97             throw createInvalidStringTypeDOMException(type);
98     }
99     if (value.equalsIgnoreCase(CSSConstants.CSS_NORMAL_VALUE)) {
100             return SVGValueConstants.NORMAL_VALUE;
101         }
102         throw createInvalidIdentifierDOMException(value);
103     }
104
105     /**
106      * Indicates the orientation of the property associated with
107      * this manager.
108      */

109     protected int getOrientation() {
110         return BOTH_ORIENTATION;
111     }
112 }
113
Popular Tags