KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > xml > client > impl > XMLParserImplStandard


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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   protected native JavaScriptObject createDocumentImpl() /*-{
33     return document.implementation.createDocument("", "", null);
34   }-*/
;
35
36   protected native JavaScriptObject getElementByIdImpl(
37       JavaScriptObject document, String JavaDoc id) /*-{
38     return document.getElementById(id);
39   }-*/
;
40
41   protected native JavaScriptObject getElementsByTagNameImpl(
42       JavaScriptObject o, String JavaDoc tagName) /*-{
43     return o.getElementsByTagNameNS("*",tagName);
44   }-*/
;
45
46   protected String JavaDoc getPrefixImpl(JavaScriptObject jsObject) {
47     String JavaDoc fullName = XMLParserImpl.getNodeName(jsObject);
48     if (fullName != null && fullName.indexOf(":") != -1) {
49       return fullName.split(":", 2)[0];
50     }
51     return null;
52   }
53
54   protected native JavaScriptObject importNodeImpl(JavaScriptObject jsObject,
55       JavaScriptObject importedNode, boolean deep) /*-{
56     var out = jsObject.importNode(importedNode, deep);
57     return (out == null) ? null : out;
58   }-*/
;
59
60   protected native JavaScriptObject parseImpl(String JavaDoc contents) /*-{
61     var domParser = this.@com.google.gwt.xml.client.impl.XMLParserImplStandard::domParser;
62     var result = domParser.parseFromString(contents,"text/xml");
63     var roottag = result.documentElement;
64     if ((roottag.tagName == "parsererror") &&
65         (roottag.namespaceURI ==
66         "http://www.mozilla.org/newlayout/xml/parsererror.xml")) {
67       throw new Error(roottag.firstChild.data);
68     }
69     return result;
70   }-*/
;
71
72 }
73
Popular Tags