1 18 package org.apache.batik.parser; 19 20 import java.io.IOException ; 21 22 29 public class PreserveAspectRatioParser extends AbstractParser { 30 31 34 protected PreserveAspectRatioHandler preserveAspectRatioHandler; 35 36 39 public PreserveAspectRatioParser() { 40 preserveAspectRatioHandler = 41 DefaultPreserveAspectRatioHandler.INSTANCE; 42 } 43 44 55 public void 56 setPreserveAspectRatioHandler(PreserveAspectRatioHandler handler) { 57 preserveAspectRatioHandler = handler; 58 } 59 60 63 public PreserveAspectRatioHandler getPreserveAspectRatioHandler() { 64 return preserveAspectRatioHandler; 65 } 66 67 70 protected void doParse() throws ParseException, IOException { 71 current = reader.read(); 72 skipSpaces(); 73 74 parsePreserveAspectRatio(); 75 } 76 77 80 protected void parsePreserveAspectRatio() 81 throws ParseException, IOException { 82 preserveAspectRatioHandler.startPreserveAspectRatio(); 83 84 align: switch (current) { 85 case 'n': 86 current = reader.read(); 87 if (current != 'o') { 88 reportError("character.expected", 89 new Object [] { new Character ('o'), 90 new Integer (current) }); 91 skipIdentifier(); 92 break align; 93 } 94 current = reader.read(); 95 if (current != 'n') { 96 reportError("character.expected", 97 new Object [] { new Character ('n'), 98 new Integer (current) }); 99 skipIdentifier(); 100 break align; 101 } 102 current = reader.read(); 103 if (current != 'e') { 104 reportError("character.expected", 105 new Object [] { new Character ('e'), 106 new Integer (current) }); 107 skipIdentifier(); 108 break align; 109 } 110 current = reader.read(); 111 skipSpaces(); 112 preserveAspectRatioHandler.none(); 113 break; 114 115 case 'x': 116 current = reader.read(); 117 if (current != 'M') { 118 reportError("character.expected", 119 new Object [] { new Character ('M'), 120 new Integer (current) }); 121 skipIdentifier(); 122 break; 123 } 124 current = reader.read(); 125 switch (current) { 126 case 'a': 127 current = reader.read(); 128 if (current != 'x') { 129 reportError("character.expected", 130 new Object [] { new Character ('x'), 131 new Integer (current) }); 132 skipIdentifier(); 133 break align; 134 } 135 current = reader.read(); 136 if (current != 'Y') { 137 reportError("character.expected", 138 new Object [] { new Character ('Y'), 139 new Integer (current) }); 140 skipIdentifier(); 141 break align; 142 } 143 current = reader.read(); 144 if (current != 'M') { 145 reportError("character.expected", 146 new Object [] { new Character ('M'), 147 new Integer (current) }); 148 skipIdentifier(); 149 break align; 150 } 151 current = reader.read(); 152 switch (current) { 153 case 'a': 154 current = reader.read(); 155 if (current != 'x') { 156 reportError("character.expected", 157 new Object [] { new Character ('x'), 158 new Integer (current) }); 159 skipIdentifier(); 160 break align; 161 } 162 preserveAspectRatioHandler.xMaxYMax(); 163 current = reader.read(); 164 break; 165 case 'i': 166 current = reader.read(); 167 switch (current) { 168 case 'd': 169 preserveAspectRatioHandler.xMaxYMid(); 170 current = reader.read(); 171 break; 172 case 'n': 173 preserveAspectRatioHandler.xMaxYMin(); 174 current = reader.read(); 175 break; 176 default: 177 reportError("character.unexpected", 178 new Object [] { new Integer (current) }); 179 skipIdentifier(); 180 break align; 181 } 182 } 183 break; 184 case 'i': 185 current = reader.read(); 186 switch (current) { 187 case 'd': 188 current = reader.read(); 189 if (current != 'Y') { 190 reportError("character.expected", 191 new Object [] { new Character ('Y'), 192 new Integer (current) }); 193 skipIdentifier(); 194 break align; 195 } 196 current = reader.read(); 197 if (current != 'M') { 198 reportError("character.expected", 199 new Object [] { new Character ('M'), 200 new Integer (current) }); 201 skipIdentifier(); 202 break align; 203 } 204 current = reader.read(); 205 switch (current) { 206 case 'a': 207 current = reader.read(); 208 if (current != 'x') { 209 reportError 210 ("character.expected", 211 new Object [] { new Character ('x'), 212 new Integer (current) }); 213 skipIdentifier(); 214 break align; 215 } 216 preserveAspectRatioHandler.xMidYMax(); 217 current = reader.read(); 218 break; 219 case 'i': 220 current = reader.read(); 221 switch (current) { 222 case 'd': 223 preserveAspectRatioHandler.xMidYMid(); 224 current = reader.read(); 225 break; 226 case 'n': 227 preserveAspectRatioHandler.xMidYMin(); 228 current = reader.read(); 229 break; 230 default: 231 reportError("character.unexpected", 232 new Object [] { new Integer (current) }); 233 skipIdentifier(); 234 break align; 235 } 236 } 237 break; 238 case 'n': 239 current = reader.read(); 240 if (current != 'Y') { 241 reportError("character.expected", 242 new Object [] { new Character ('Y'), 243 new Integer (current) }); 244 skipIdentifier(); 245 break align; 246 } 247 current = reader.read(); 248 if (current != 'M') { 249 reportError("character.expected", 250 new Object [] { new Character ('M'), 251 new Integer (current) }); 252 skipIdentifier(); 253 break align; 254 } 255 current = reader.read(); 256 switch (current) { 257 case 'a': 258 current = reader.read(); 259 if (current != 'x') { 260 reportError 261 ("character.expected", 262 new Object [] { new Character ('x'), 263 new Integer (current) }); 264 skipIdentifier(); 265 break align; 266 } 267 preserveAspectRatioHandler.xMinYMax(); 268 current = reader.read(); 269 break; 270 case 'i': 271 current = reader.read(); 272 switch (current) { 273 case 'd': 274 preserveAspectRatioHandler.xMinYMid(); 275 current = reader.read(); 276 break; 277 case 'n': 278 preserveAspectRatioHandler.xMinYMin(); 279 current = reader.read(); 280 break; 281 default: 282 reportError 283 ("character.unexpected", 284 new Object [] { new Integer (current) }); 285 skipIdentifier(); 286 break align; 287 } 288 } 289 break; 290 default: 291 reportError("character.unexpected", 292 new Object [] { new Integer (current) }); 293 skipIdentifier(); 294 break align; 295 } 296 break; 297 default: 298 reportError("character.unexpected", 299 new Object [] { new Integer (current) }); 300 skipIdentifier(); 301 } 302 break; 303 default: 304 if (current != -1) { 305 reportError("character.unexpected", 306 new Object [] { new Integer (current) }); 307 skipIdentifier(); 308 } 309 } 310 311 skipCommaSpaces(); 312 313 switch (current) { 314 case 'm': 315 current = reader.read(); 316 if (current != 'e') { 317 reportError("character.expected", 318 new Object [] { new Character ('e'), 319 new Integer (current) }); 320 skipIdentifier(); 321 break; 322 } 323 current = reader.read(); 324 if (current != 'e') { 325 reportError("character.expected", 326 new Object [] { new Character ('e'), 327 new Integer (current) }); 328 skipIdentifier(); 329 break; 330 } 331 current = reader.read(); 332 if (current != 't') { 333 reportError("character.expected", 334 new Object [] { new Character ('t'), 335 new Integer (current) }); 336 skipIdentifier(); 337 break; 338 } 339 preserveAspectRatioHandler.meet(); 340 current = reader.read(); 341 break; 342 case 's': 343 current = reader.read(); 344 if (current != 'l') { 345 reportError("character.expected", 346 new Object [] { new Character ('l'), 347 new Integer (current) }); 348 skipIdentifier(); 349 break; 350 } 351 current = reader.read(); 352 if (current != 'i') { 353 reportError("character.expected", 354 new Object [] { new Character ('i'), 355 new Integer (current) }); 356 skipIdentifier(); 357 break; 358 } 359 current = reader.read(); 360 if (current != 'c') { 361 reportError("character.expected", 362 new Object [] { new Character ('c'), 363 new Integer (current) }); 364 skipIdentifier(); 365 break; 366 } 367 current = reader.read(); 368 if (current != 'e') { 369 reportError("character.expected", 370 new Object [] { new Character ('e'), 371 new Integer (current) }); 372 skipIdentifier(); 373 break; 374 } 375 preserveAspectRatioHandler.slice(); 376 current = reader.read(); 377 break; 378 default: 379 if (current != -1) { 380 reportError("character.unexpected", 381 new Object [] { new Integer (current) }); 382 skipIdentifier(); 383 } 384 } 385 386 skipSpaces(); 387 if (current != -1) { 388 reportError("end.of.stream.expected", 389 new Object [] { new Integer (current) }); 390 } 391 392 preserveAspectRatioHandler.endPreserveAspectRatio(); 393 } 394 395 399 protected void skipIdentifier() throws IOException { 400 loop: for (;;) { 401 current = reader.read(); 402 switch(current) { 403 case 0xD: case 0xA: case 0x20: case 0x9: 404 current = reader.read(); 405 break loop; 406 default: 407 if (current == -1) { 408 break loop; 409 } 410 } 411 } 412 } 413 } 414 | Popular Tags |