All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.gwt.xml.client.impl.XMLParserImplSafari Maven / Gradle / Ivy

There is a newer version: 2.7.0.vaadin7
Show newest version
/*
 * Copyright 2008 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.xml.client.impl;

import com.google.gwt.core.client.JavaScriptObject;

/**
 * This class is Safari implementation of the XMLParser interface.
 */
public class XMLParserImplSafari extends XMLParserImplStandard {

  private static boolean safari2LevelWebKit = (getWebKitVersion() <= 420);

  public static boolean isSafari2LevelWebKit() {
    return safari2LevelWebKit;
  }
  
  private static native int getWebKitVersion() /*-{
    var result = / AppleWebKit\/([\d]+)/.exec(navigator.userAgent);
    return ((result) ? parseInt(result[1]) : 0) || 0;
  }-*/;
  
  private static void throwDOMParseException(String message) {
    throw new DOMParseException(message);
  }
  
  @Override
  protected native JavaScriptObject getElementsByTagNameImpl(JavaScriptObject o,
      String tagName) /*-{
    return o.getElementsByTagName(tagName);
  }-*/;
  
  @Override
  protected native JavaScriptObject importNodeImpl(JavaScriptObject jsObject,
      JavaScriptObject importedNode, boolean deep) /*-{
    // Works around a Safari2 issue where importing a node will steal attributes
    // from the original.
    if (@com.google.gwt.xml.client.impl.XMLParserImplSafari::isSafari2LevelWebKit()()) {
      importedNode = importedNode.cloneNode(deep);
    }
    return jsObject.importNode(importedNode, deep);
  }-*/;
  
  /**
   * 
   * 

This page contains the following errors:

*
error on line 1 at * column 2: xmlParseStartTag: invalid element name
*

Below is a rendering of the page up to the first error.

*
is all you get from Safari. Hope that nobody * wants to send one of those error reports over the wire to be parsed by * safari... * * @param contents contents * @return parsed JavaScript object * @see com.google.gwt.xml.client.impl.XMLParserImpl#parseImpl(java.lang.String) */ @Override protected native JavaScriptObject parseImpl(String contents) /*-{ var domParser = [email protected]::domParser; var result = domParser.parseFromString(contents,"text/xml"); var parseerrors = result.getElementsByTagName("parsererror"); if (parseerrors.length > 0) { var err = parseerrors.item(0); if (err.parentNode.tagName == 'body') { @com.google.gwt.xml.client.impl.XMLParserImplSafari::throwDOMParseException(Ljava/lang/String;)(err.childNodes[1].innerHTML); } } return result; }-*/; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy