KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Copyright 2000-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 length
24  * list values.
25  *
26  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
27  * @version $Id: LengthListParser.java,v 1.9 2004/08/18 07:14:47 vhardy Exp $
28  */

29 public class LengthListParser extends LengthParser {
30
31     /**
32      * Creates a new LengthListParser.
33      */

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

49     public void setLengthListHandler(LengthListHandler handler) {
50     lengthHandler = handler;
51     }
52
53     /**
54      * Returns the length list handler in use.
55      */

56     public LengthListHandler getLengthListHandler() {
57     return (LengthListHandler)lengthHandler;
58     }
59
60     /**
61      * Parses the given reader.
62      */

63     protected void doParse() throws ParseException, IOException JavaDoc {
64     ((LengthListHandler)lengthHandler).startLengthList();
65
66     current = reader.read();
67     skipSpaces();
68     
69     try {
70         for (;;) {
71         lengthHandler.startLength();
72         parseLength();
73         lengthHandler.endLength();
74         skipCommaSpaces();
75         if (current == -1) {
76             break;
77         }
78         }
79     } catch (NumberFormatException JavaDoc e) {
80         reportError("character.unexpected",
81                     new Object JavaDoc[] { new Integer JavaDoc(current) });
82     }
83     ((LengthListHandler)lengthHandler).endLengthList();
84     }
85 }
86
Popular Tags