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 is Safari implementation of the XMLParser interface.
22: */
23: class XMLParserImplSafari extends XMLParserImplStandard {
24:
25: @Override
26: protected native JavaScriptObject getElementsByTagNameImpl(
27: JavaScriptObject o, String tagName) /*-{
28: return o.getElementsByTagName(tagName);
29: }-*/;
30:
31: /**
32: * <html><body><parsererror style="white-space: pre; border: 2px solid #c77;
33: * padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black" >
34: * <h3>This page contains the following errors:</h3>
35: * <div style="font-family:monospace;font-size:12px" >error on line 1 at
36: * column 2: xmlParseStartTag: invalid element name </div>
37: * <h3>Below is a rendering of the page up to the first error.</h3>
38: * </parsererror></body></html> is all you get from Safari. Hope that nobody
39: * wants to send one of those error reports over the wire to be parsed by
40: * safari...
41: *
42: * @param contents contents
43: * @return parsed JavaScript object
44: * @see com.google.gwt.xml.client.impl.XMLParserImpl#parseImpl(java.lang.String)
45: */
46: @Override
47: protected native JavaScriptObject parseImpl(String contents) /*-{
48: var domParser =
49: this.@com.google.gwt.xml.client.impl.XMLParserImplStandard::domParser;
50: var result = domParser.parseFromString(contents,"text/xml");
51: var parseerrors = result.getElementsByTagName("parsererror");
52: if (parseerrors.length > 0) {
53: var err = parseerrors.item(0);
54: var safariErrStyle = "white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black";
55: if(err.getAttribute("style") == safariErrStyle) {
56: throw new Error(err.item(1).innerHTML);
57: }
58: }
59: return result;
60: }-*/;
61: }
|