01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.xml.client.impl;
17:
18: import com.google.gwt.core.client.JavaScriptObject;
19:
20: /**
21: * This class implements the methods for standard browsers that use the
22: * DOMParser model of XML parsing.
23: */
24: class XMLParserImplStandard extends XMLParserImpl {
25:
26: protected static native JavaScriptObject createDOMParser() /*-{
27: return new DOMParser();
28: }-*/;
29:
30: protected final JavaScriptObject domParser = createDOMParser();
31:
32: @Override
33: protected native JavaScriptObject createDocumentImpl() /*-{
34: return document.implementation.createDocument("", "", null);
35: }-*/;
36:
37: @Override
38: protected native JavaScriptObject getElementByIdImpl(
39: JavaScriptObject document, String id) /*-{
40: return document.getElementById(id);
41: }-*/;
42:
43: @Override
44: protected native JavaScriptObject getElementsByTagNameImpl(
45: JavaScriptObject o, String tagName) /*-{
46: return o.getElementsByTagNameNS("*",tagName);
47: }-*/;
48:
49: @Override
50: protected String getPrefixImpl(JavaScriptObject jsObject) {
51: String fullName = XMLParserImpl.getNodeName(jsObject);
52: if (fullName != null && fullName.indexOf(":") != -1) {
53: return fullName.split(":", 2)[0];
54: }
55: return null;
56: }
57:
58: @Override
59: protected native JavaScriptObject importNodeImpl(
60: JavaScriptObject jsObject, JavaScriptObject importedNode,
61: boolean deep) /*-{
62: var out = jsObject.importNode(importedNode, deep);
63: return (out == null) ? null : out;
64: }-*/;
65:
66: @Override
67: protected native JavaScriptObject parseImpl(String contents) /*-{
68: var domParser = this.@com.google.gwt.xml.client.impl.XMLParserImplStandard::domParser;
69: var result = domParser.parseFromString(contents,"text/xml");
70: var roottag = result.documentElement;
71: if ((roottag.tagName == "parsererror") &&
72: (roottag.namespaceURI ==
73: "http://www.mozilla.org/newlayout/xml/parsererror.xml")) {
74: throw new Error(roottag.firstChild.data);
75: }
76: return result;
77: }-*/;
78:
79: }
|