KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > parser > NumberListParser


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.parser;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * This class implements an event-based parser for the SVG Number
24  * list values.
25  *
26  * @author tonny@kiyut.com
27  */

28 public class NumberListParser extends NumberParser {
29     /**
30      * The number list handler used to report parse events.
31      */

32     protected NumberListHandler numberListHandler;
33     
34     
35     /** Creates a new instance of NumberListParser */
36     public NumberListParser() {
37         numberListHandler = DefaultNumberListHandler.INSTANCE;
38     }
39     
40     /**
41      * Allows an application to register a number list handler.
42      *
43      * <p>If the application does not register a handler, all
44      * events reported by the parser will be silently ignored.
45      *
46      * <p>Applications may register a new or different handler in the
47      * middle of a parse, and the parser must begin using the new
48      * handler immediately.</p>
49      * @param handler The number list handler.
50      */

51     public void setNumberListHandler(NumberListHandler handler) {
52     numberListHandler = handler;
53     }
54     
55     /**
56      * Returns the number list handler in use.
57      */

58     public NumberListHandler getNumberListHandler() {
59     return (NumberListHandler)numberListHandler;
60     }
61     
62     /**
63      * Parses the given reader.
64      */

65     protected void doParse() throws ParseException, IOException JavaDoc {
66     numberListHandler.startNumberList();
67
68     current = reader.read();
69     skipSpaces();
70     
71     try {
72         for (;;) {
73                 numberListHandler.startNumber();
74         float f = parseFloat();
75                 numberListHandler.numberValue(f);
76                 numberListHandler.endNumber();
77         skipCommaSpaces();
78         if (current == -1) {
79             break;
80         }
81         }
82     } catch (NumberFormatException JavaDoc e) {
83         reportError("character.unexpected",
84                     new Object JavaDoc[] { new Integer JavaDoc(current) });
85     }
86     numberListHandler.endNumberList();
87     }
88 }
89
Popular Tags