View Javadoc

1   /**********************************************
2    * Copyright (C) 2010 Lukas Laag
3    * This file is part of lib-gwt-svg.
4    * 
5    * libgwtsvg is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser 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   * libgwtsvg 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 Lesser General Public License for more details.
14   * 
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with libgwtsvg.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package com.google.gwt.uibinder.elementparsers;
19  
20  import org.w3c.dom.Element;
21  
22  import com.google.gwt.core.ext.UnableToCompleteException;
23  import com.google.gwt.uibinder.rebind.UiBinderWriter;
24  import com.google.gwt.uibinder.rebind.XMLElement;
25  import com.google.gwt.uibinder.rebind.XMLElement.Interpreter;
26  
27  public class SvgInterpreter implements XMLElement.Interpreter<String> {
28  	public static SvgInterpreter newInterpreterForUiObject(
29  			UiBinderWriter writer, String uiExpression, Element root) {
30  		String ancestorExpression = uiExpression;
31  		return new SvgInterpreter(writer, ancestorExpression, root,
32  				new HtmlMessageInterpreter(writer, ancestorExpression));
33  	}
34  
35  	private final UiBinderWriter writer;
36  	private final InterpreterPipe<String> pipe;
37  
38  	public SvgInterpreter(UiBinderWriter writer, String ancestorExpression, Element root,
39  			Interpreter<String> messageInterpreter) {
40  		this.writer = writer;
41  		this.pipe = new InterpreterPipe<String>();
42  
43  		pipe.add(new SvgFieldInterpreter(writer, ancestorExpression, root));
44  		pipe.add(new ComputedAttributeInterpreter(writer));
45  		pipe.add(new AttributeMessageInterpreter(writer));
46  		pipe.add(messageInterpreter);
47  	}
48  
49  	public String interpretElement(XMLElement elem)
50  			throws UnableToCompleteException {
51  		if (writer.isWidgetElement(elem)) {
52  			writer.die("Found widget %s in an SVG context", elem);
53  		}
54  		return pipe.interpretElement(elem);
55  	}
56  }