1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.dom.svg.impl;
19
20 import org.vectomatic.dom.svg.utils.DOMHelper;
21 import org.vectomatic.dom.svg.utils.ParserException;
22 import org.vectomatic.dom.svg.utils.XPathPrefixResolver;
23
24 import com.google.gwt.dom.client.Element;
25 import com.google.gwt.dom.client.Text;
26
27
28
29
30
31 public class SVGParserImplWebkit extends SVGParserImpl {
32
33
34
35
36
37
38
39 public final SVGSVGElement parse(String rawSvg) throws ParserException {
40 SVGDocument doc = parseFromString(rawSvg, "text/xml").cast();
41 Element elt = doc.getDocumentElement();
42 if ("parsererror".equals(DOMHelper.getLocalName(elt))) {
43 String message = "Parsing error";
44 if (elt.getFirstChild() != null) {
45 message = elt.getFirstChild().<Text>cast().getData();
46 }
47 throw new ParserException(ParserException.Type.NotWellFormed, message);
48 } else if ("html".equals(DOMHelper.getLocalName(elt))) {
49 String message = DOMHelper.evaluateStringXPath(elt, "./x:body/x:parsererror/x:div/text()", new XPathPrefixResolver() {
50 @Override
51 public String resolvePrefix(String prefix) {
52 if ("x".equals(prefix)) {
53 return "http://www.w3.org/1999/xhtml";
54 }
55 return null;
56 }
57 });
58 throw new ParserException(ParserException.Type.NotWellFormed, message);
59 }
60 SVGSVGElement svg = DOMHelper.importNode(DOMHelper.getCurrentDocument(), elt, true).cast();
61
62
63
64 return svg.cloneNode(true).<SVGSVGElement>cast();
65 }
66
67 }