01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
10: http://www.apache.org/licenses/LICENSE-2.0
11:
12: Unless required by applicable law or agreed to in writing, software
13: distributed under the License is distributed on an "AS IS" BASIS,
14: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: See the License for the specific language governing permissions and
16: limitations under the License.
17:
18: */
19: package org.apache.batik.parser;
20:
21: import java.io.IOException;
22:
23: /**
24: * This class implements an event-based parser for the SVG Number
25: * list values.
26: *
27: * @author tonny@kiyut.com
28: * @version $Id: NumberListParser.java 502167 2007-02-01 09:26:51Z dvholten $
29: */
30: public class NumberListParser extends NumberParser {
31: /**
32: * The number list handler used to report parse events.
33: */
34: protected NumberListHandler numberListHandler;
35:
36: /** Creates a new instance of NumberListParser */
37: public NumberListParser() {
38: numberListHandler = DefaultNumberListHandler.INSTANCE;
39: }
40:
41: /**
42: * Allows an application to register a number list handler.
43: *
44: * <p>If the application does not register a handler, all
45: * events reported by the parser will be silently ignored.
46: *
47: * <p>Applications may register a new or different handler in the
48: * middle of a parse, and the parser must begin using the new
49: * handler immediately.</p>
50: * @param handler The number list handler.
51: */
52: public void setNumberListHandler(NumberListHandler handler) {
53: numberListHandler = handler;
54: }
55:
56: /**
57: * Returns the number list handler in use.
58: */
59: public NumberListHandler getNumberListHandler() {
60: return numberListHandler;
61: }
62:
63: /**
64: * Parses the given reader.
65: */
66: protected void doParse() throws ParseException, IOException {
67: numberListHandler.startNumberList();
68:
69: current = reader.read();
70: skipSpaces();
71:
72: try {
73: for (;;) {
74: numberListHandler.startNumber();
75: float f = parseFloat();
76: numberListHandler.numberValue(f);
77: numberListHandler.endNumber();
78: skipCommaSpaces();
79: if (current == -1) {
80: break;
81: }
82: }
83: } catch (NumberFormatException e) {
84: reportUnexpectedCharacterError(current);
85: }
86: numberListHandler.endNumberList();
87: }
88: }
|