KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > css2 > SrcManager


1 /*
2
3    Copyright 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.css2;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.value.IdentifierManager;
22 import org.apache.batik.css.engine.value.ListValue;
23 import org.apache.batik.css.engine.value.StringMap;
24 import org.apache.batik.css.engine.value.StringValue;
25 import org.apache.batik.css.engine.value.URIValue;
26 import org.apache.batik.css.engine.value.Value;
27 import org.apache.batik.css.engine.value.ValueConstants;
28 import org.apache.batik.css.engine.value.ValueManager;
29 import org.apache.batik.util.CSSConstants;
30
31 import org.w3c.dom.css.CSSPrimitiveValue;
32 import org.w3c.dom.DOMException JavaDoc;
33 import org.w3c.css.sac.LexicalUnit;
34
35 /**
36  * One line Class Desc
37  *
38  * Complete Class Desc
39  *
40  * @author <a HREF="mailto:deweese@apache.org">l449433</a>
41  * @version $Id: SrcManager.java,v 1.8 2005/03/27 08:58:31 cam Exp $
42  */

43 public class SrcManager extends IdentifierManager {
44
45     /**
46      * The identifier values.
47      */

48     protected final static StringMap values = new StringMap();
49     static {
50     values.put(CSSConstants.CSS_NONE_VALUE,
51                    ValueConstants.NONE_VALUE);
52     }
53
54     public SrcManager() {
55     }
56
57     /**
58      * Implements {@link
59      * org.apache.batik.css.engine.value.ValueManager#isInheritedProperty()}.
60      */

61     public boolean isInheritedProperty() {
62     return false;
63     }
64
65     /**
66      * Implements {@link
67      * org.apache.batik.css.engine.value.ValueManager#getPropertyName()}.
68      */

69     public String JavaDoc getPropertyName() {
70     return CSSConstants.CSS_SRC_PROPERTY;
71     }
72     
73     /**
74      * Implements {@link
75      * org.apache.batik.css.engine.value.ValueManager#getDefaultValue()}.
76      */

77     public Value getDefaultValue() {
78         return ValueConstants.NONE_VALUE;
79     }
80
81
82     /**
83      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
84      */

85     public Value createValue(LexicalUnit lu, CSSEngine engine)
86         throws DOMException JavaDoc {
87         
88         switch (lu.getLexicalUnitType()) {
89         case LexicalUnit.SAC_INHERIT:
90             return ValueConstants.INHERIT_VALUE;
91
92         default:
93             throw createInvalidLexicalUnitDOMException
94                 (lu.getLexicalUnitType());
95
96         case LexicalUnit.SAC_IDENT:
97         case LexicalUnit.SAC_STRING_VALUE:
98         case LexicalUnit.SAC_URI:
99         }
100
101         ListValue result = new ListValue();
102         for (;;) {
103             switch (lu.getLexicalUnitType()) {
104             case LexicalUnit.SAC_STRING_VALUE:
105                 result.append(new StringValue(CSSPrimitiveValue.CSS_STRING,
106                                               lu.getStringValue()));
107                 lu = lu.getNextLexicalUnit();
108                 break;
109
110             case LexicalUnit.SAC_URI:
111                 String JavaDoc uri = resolveURI(engine.getCSSBaseURI(),
112                                         lu.getStringValue());
113                 
114                 result.append(new URIValue(lu.getStringValue(), uri));
115                 lu = lu.getNextLexicalUnit();
116                 if ((lu != null) &&
117                     (lu.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION)) {
118                     if (!lu.getFunctionName().equalsIgnoreCase("format")) {
119                         break;
120                     }
121                     // Format really does us no good so just ignore it.
122

123                     // TODO: Should probably turn this into a ListValue
124
// and append the format function CSS Value.
125
lu = lu.getNextLexicalUnit();
126                 }
127                 break;
128                 
129             case LexicalUnit.SAC_IDENT:
130                 StringBuffer JavaDoc sb = new StringBuffer JavaDoc(lu.getStringValue());
131                 lu = lu.getNextLexicalUnit();
132                 if (lu != null &&
133                     lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
134                     do {
135                         sb.append(' ');
136                         sb.append(lu.getStringValue());
137                         lu = lu.getNextLexicalUnit();
138                     } while (lu != null &&
139                              lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT);
140                     result.append(new StringValue(CSSPrimitiveValue.CSS_STRING,
141                                                   sb.toString()));
142                 } else {
143                     String JavaDoc id = sb.toString();
144                     String JavaDoc s = id.toLowerCase().intern();
145                     Value v = (Value)values.get(s);
146                     result.append((v != null)
147                                   ? v
148                                   : new StringValue
149                                         (CSSPrimitiveValue.CSS_STRING, id));
150                 }
151                 break;
152             }
153             if (lu == null) {
154                 return result;
155             }
156             if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
157                 throw createInvalidLexicalUnitDOMException
158                     (lu.getLexicalUnitType());
159             }
160             lu = lu.getNextLexicalUnit();
161             if (lu == null) {
162                 throw createMalformedLexicalUnitDOMException();
163             }
164         }
165     }
166
167     /**
168      * Implements {@link IdentifierManager#getIdentifiers()}.
169      */

170     public StringMap getIdentifiers() {
171         return values;
172     }
173 }
174
Popular Tags