1 18 package org.apache.batik.css.parser; 19 20 import org.w3c.css.sac.LexicalUnit; 21 22 28 public abstract class CSSLexicalUnit implements LexicalUnit { 29 30 public static final String UNIT_TEXT_CENTIMETER = "cm"; 31 public static final String UNIT_TEXT_DEGREE = "deg"; 32 public static final String UNIT_TEXT_EM = "em"; 33 public static final String UNIT_TEXT_EX = "ex"; 34 public static final String UNIT_TEXT_GRADIAN = "grad"; 35 public static final String UNIT_TEXT_HERTZ = "Hz"; 36 public static final String UNIT_TEXT_INCH = "in"; 37 public static final String UNIT_TEXT_KILOHERTZ = "kHz"; 38 public static final String UNIT_TEXT_MILLIMETER = "mm"; 39 public static final String UNIT_TEXT_MILLISECOND = "ms"; 40 public static final String UNIT_TEXT_PERCENTAGE = "%"; 41 public static final String UNIT_TEXT_PICA = "pc"; 42 public static final String UNIT_TEXT_PIXEL = "px"; 43 public static final String UNIT_TEXT_POINT = "pt"; 44 public static final String UNIT_TEXT_RADIAN = "rad"; 45 public static final String UNIT_TEXT_REAL = ""; 46 public static final String UNIT_TEXT_SECOND = "s"; 47 48 49 52 protected short lexicalUnitType; 53 54 57 protected LexicalUnit nextLexicalUnit; 58 59 62 protected LexicalUnit previousLexicalUnit; 63 64 67 protected CSSLexicalUnit(short t, LexicalUnit prev) { 68 lexicalUnitType = t; 69 previousLexicalUnit = prev; 70 if (prev != null) { 71 ((CSSLexicalUnit)prev).nextLexicalUnit = this; 72 } 73 } 74 75 78 public short getLexicalUnitType() { 79 return lexicalUnitType; 80 } 81 82 85 public LexicalUnit getNextLexicalUnit() { 86 return nextLexicalUnit; 87 } 88 89 92 public void setNextLexicalUnit(LexicalUnit lu) { 93 nextLexicalUnit = lu; 94 } 95 96 99 public LexicalUnit getPreviousLexicalUnit() { 100 return previousLexicalUnit; 101 } 102 103 106 public void setPreviousLexicalUnit(LexicalUnit lu) { 107 previousLexicalUnit = lu; 108 } 109 110 113 public int getIntegerValue() { 114 throw new IllegalStateException (); 115 } 116 117 120 public float getFloatValue() { 121 throw new IllegalStateException (); 122 } 123 124 127 public String getDimensionUnitText() { 128 switch (lexicalUnitType) { 129 case LexicalUnit.SAC_CENTIMETER: return UNIT_TEXT_CENTIMETER; 130 case LexicalUnit.SAC_DEGREE: return UNIT_TEXT_DEGREE; 131 case LexicalUnit.SAC_EM: return UNIT_TEXT_EM; 132 case LexicalUnit.SAC_EX: return UNIT_TEXT_EX; 133 case LexicalUnit.SAC_GRADIAN: return UNIT_TEXT_GRADIAN; 134 case LexicalUnit.SAC_HERTZ: return UNIT_TEXT_HERTZ; 135 case LexicalUnit.SAC_INCH: return UNIT_TEXT_INCH; 136 case LexicalUnit.SAC_KILOHERTZ: return UNIT_TEXT_KILOHERTZ; 137 case LexicalUnit.SAC_MILLIMETER: return UNIT_TEXT_MILLIMETER; 138 case LexicalUnit.SAC_MILLISECOND: return UNIT_TEXT_MILLISECOND; 139 case LexicalUnit.SAC_PERCENTAGE: return UNIT_TEXT_PERCENTAGE; 140 case LexicalUnit.SAC_PICA: return UNIT_TEXT_PICA; 141 case LexicalUnit.SAC_PIXEL: return UNIT_TEXT_PIXEL; 142 case LexicalUnit.SAC_POINT: return UNIT_TEXT_POINT; 143 case LexicalUnit.SAC_RADIAN: return UNIT_TEXT_RADIAN; 144 case LexicalUnit.SAC_REAL: return UNIT_TEXT_REAL; 145 case LexicalUnit.SAC_SECOND: return UNIT_TEXT_SECOND; 146 default: 147 throw new IllegalStateException ("No Unit Text for type: " + 148 lexicalUnitType); 149 } 150 } 151 152 155 public String getFunctionName() { 156 throw new IllegalStateException (); 157 } 158 159 162 public LexicalUnit getParameters() { 163 throw new IllegalStateException (); 164 } 165 166 169 public String getStringValue() { 170 throw new IllegalStateException (); 171 } 172 173 176 public LexicalUnit getSubValues() { 177 throw new IllegalStateException (); 178 } 179 180 183 public static CSSLexicalUnit createSimple(short t, LexicalUnit prev) { 184 return new SimpleLexicalUnit(t, prev); 185 } 186 187 190 protected static class SimpleLexicalUnit extends CSSLexicalUnit { 191 192 195 public SimpleLexicalUnit(short t, LexicalUnit prev) { 196 super(t, prev); 197 } 198 } 199 200 203 public static CSSLexicalUnit createInteger(int val, LexicalUnit prev) { 204 return new IntegerLexicalUnit(val, prev); 205 } 206 207 210 protected static class IntegerLexicalUnit extends CSSLexicalUnit { 211 212 215 protected int value; 216 217 220 public IntegerLexicalUnit(int val, LexicalUnit prev) { 221 super(LexicalUnit.SAC_INTEGER, prev); 222 value = val; 223 } 224 225 228 public int getIntegerValue() { 229 return value; 230 } 231 } 232 233 236 public static CSSLexicalUnit createFloat(short t, float val, LexicalUnit prev) { 237 return new FloatLexicalUnit(t, val, prev); 238 } 239 240 243 protected static class FloatLexicalUnit extends CSSLexicalUnit { 244 245 248 protected float value; 249 250 253 public FloatLexicalUnit(short t, float val, LexicalUnit prev) { 254 super(t, prev); 255 value = val; 256 } 257 258 261 public float getFloatValue() { 262 return value; 263 } 264 } 265 266 269 public static CSSLexicalUnit createDimension(float val, String dim, 270 LexicalUnit prev) { 271 return new DimensionLexicalUnit(val, dim, prev); 272 } 273 274 277 protected static class DimensionLexicalUnit extends CSSLexicalUnit { 278 279 282 protected float value; 283 284 287 protected String dimension; 288 289 292 public DimensionLexicalUnit(float val, String dim, LexicalUnit prev) { 293 super(SAC_DIMENSION, prev); 294 value = val; 295 dimension = dim; 296 } 297 298 301 public float getFloatValue() { 302 return value; 303 } 304 305 308 public String getDimensionUnitText() { 309 return dimension; 310 } 311 } 312 313 316 public static CSSLexicalUnit createFunction(String f, LexicalUnit params, 317 LexicalUnit prev) { 318 return new FunctionLexicalUnit(f, params, prev); 319 } 320 321 324 protected static class FunctionLexicalUnit extends CSSLexicalUnit { 325 326 329 protected String name; 330 331 334 protected LexicalUnit parameters; 335 336 339 public FunctionLexicalUnit(String f, LexicalUnit params, LexicalUnit prev) { 340 super(SAC_FUNCTION, prev); 341 name = f; 342 parameters = params; 343 } 344 345 348 public String getFunctionName() { 349 return name; 350 } 351 352 355 public LexicalUnit getParameters() { 356 return parameters; 357 } 358 359 } 360 361 364 public static CSSLexicalUnit createPredefinedFunction(short t, LexicalUnit params, 365 LexicalUnit prev) { 366 return new PredefinedFunctionLexicalUnit(t, params, prev); 367 } 368 369 372 protected static class PredefinedFunctionLexicalUnit extends CSSLexicalUnit { 373 374 377 protected LexicalUnit parameters; 378 379 382 public PredefinedFunctionLexicalUnit(short t, LexicalUnit params, 383 LexicalUnit prev) { 384 super(t, prev); 385 parameters = params; 386 } 387 388 391 public LexicalUnit getParameters() { 392 return parameters; 393 } 394 } 395 396 399 public static CSSLexicalUnit createString(short t, String val, LexicalUnit prev) { 400 return new StringLexicalUnit(t, val, prev); 401 } 402 403 406 protected static class StringLexicalUnit extends CSSLexicalUnit { 407 408 411 protected String value; 412 413 416 public StringLexicalUnit(short t, String val, LexicalUnit prev) { 417 super(t, prev); 418 value = val; 419 } 420 421 424 public String getStringValue() { 425 return value; 426 } 427 } 428 } 429 | Popular Tags |