View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 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  /**
22   * Opera version of IdRefTokenizer (required because Opera
23   * transforms urls into absolute urls).
24   * @author laaglu
25   */
26  public class IdRefTokenizerOpera extends IdRefTokenizer {
27  	protected static final String START2 = "url(";
28  	protected static final String END2 = ")";
29  
30  	public IdRefToken nextToken() {
31  		if (index1 != str.length()) {
32  			if (token.kind == IdRefToken.IDREF) {
33  				boolean notFirst = token.value != null;
34  				token.kind = IdRefToken.DATA;
35  				index2 = str.indexOf(START2, index1);
36  				if (index2 != -1) {
37  					token.value = str.substring(index1, index2 + START2.length()) + "'#";
38  					index1 = index2 + START2.length();
39  				} else {
40  					token.value = str.substring(index1);
41  					index1 = str.length();
42  				}
43  				if (notFirst) {
44  					token.value = "'" + token.value;
45  				}
46  			} else {
47  				index2 = str.indexOf(END2, index1);
48  				if (index2 != -1) {
49  					token.value = str.substring(index1, index2);
50  					int index3 = token.value.indexOf("#");
51  					if (index3 != -1) {
52  						token.value = token.value.substring(1 + index3);
53  					}
54  					if (token.value.endsWith("'")) {
55  						token.value = token.value.substring(0, token.value.length() - 1);
56  					}
57  					if (token.value.endsWith("\"")) {
58  						token.value = token.value.substring(0, token.value.length() - 1);
59  					}
60  					index1 = index2;
61  					token.kind = IdRefToken.IDREF;
62  				} else {
63  					token.value = str.substring(index1);
64  					index1 = str.length();
65  				}
66  			}
67  			return token;
68  		}
69  		return null;
70  	}
71  }