View Javadoc

1   /**********************************************
2    * Copyright (C) 2010 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.engine;
19  
20  /**
21   * FF version of IdRefTokenizer (required because FF does
22   * inconsistently add quotes around id refs).
23   * @author laaglu
24   */
25  public class IdRefTokenizerMozilla extends IdRefTokenizer {
26  	protected static final String START2 = "url(\"#";
27  	protected static final String END2 = "\")";
28  	private boolean hasQuotes;
29  
30  	public IdRefToken nextToken() {
31  		if (index1 != str.length()) {
32  			if (token.kind == IdRefToken.IDREF) {
33  				token.kind = IdRefToken.DATA;
34  				index2 = str.indexOf(START2, index1);
35  				if (index2 != -1) {
36  					hasQuotes = true;
37  					token.value = str.substring(index1, index2 + START2.length());
38  					index1 = index2 + START2.length();
39  				} else {
40  					index2 = str.indexOf(START, index1);
41  					if (index2 != -1) {
42  						hasQuotes = false;
43  						token.value = str.substring(index1, index2 + START.length());
44  						index1 = index2 + START.length();
45  					} else {
46  						token.value = str.substring(index1);
47  						index1 = str.length();
48  					}
49  				}
50  			} else {
51  				if (hasQuotes) {
52  					index2 = str.indexOf(END2, index1);
53  				} else {
54  					index2 = str.indexOf(END, index1);
55  				}
56  				if (index2 != -1) {
57  					token.value = str.substring(index1, index2);
58  					index1 = index2;
59  					token.kind = IdRefToken.IDREF;
60  				} else {
61  					token.value = str.substring(index1);
62  					index1 = str.length();
63  				}
64  			}
65  			return token;
66  		}
67  		return null;
68  	}
69  }