Example #1
0
  /**
   * Returns the value of the specified attribute.
   *
   * @param attributeName attribute name
   * @param flags IE-specific flags (see the MSDN documentation for more info)
   * @return the value of the specified attribute, <code>null</code> if the attribute is not defined
   * @see <a href="http://msdn.microsoft.com/en-us/library/ms536429.aspx">MSDN Documentation</a>
   * @see <a href="http://reference.sitepoint.com/javascript/Element/getAttribute">IE Bug
   *     Documentation</a>
   */
  @JsxFunction
  public Object getAttribute(String attributeName, final Integer flags) {
    attributeName = fixAttributeName(attributeName);
    final Page page = getDomNodeOrDie().getPage();
    final boolean supportsFlags =
        getBrowserVersion().hasFeature(JS_GET_ATTRIBUTE_SUPPORTS_FLAGS_IN_QUIRKS_MODE)
            && page instanceof HtmlPage
            && ((HtmlPage) page).isQuirksMode();

    Object value;
    if (supportsFlags && flags != null && flags == 2 && "style".equalsIgnoreCase(attributeName)) {
      value = "";
    } else {
      value = getDomNodeOrDie().getAttribute(attributeName);
    }

    if (value == DomElement.ATTRIBUTE_NOT_DEFINED) {
      value = null;
      if (supportsFlags) {
        for (Scriptable object = this; object != null; object = object.getPrototype()) {
          final Object property = object.get(attributeName, this);
          if (property != NOT_FOUND) {
            value = property;
            break;
          }
        }
      }
    }

    return value;
  }
 /** Returns the value of a property on the given script object. */
 private Object getObjectPropertyImpl(Context cx, Object object, Object id) {
   Scriptable scriptable = (Scriptable) object;
   Object result;
   if (id instanceof String) {
     String name = (String) id;
     if (name.equals("this")) {
       result = scriptable;
     } else if (name.equals("__proto__")) {
       result = scriptable.getPrototype();
     } else if (name.equals("__parent__")) {
       result = scriptable.getParentScope();
     } else {
       result = ScriptableObject.getProperty(scriptable, name);
       if (result == ScriptableObject.NOT_FOUND) {
         result = Undefined.instance;
       }
     }
   } else {
     int index = ((Integer) id).intValue();
     result = ScriptableObject.getProperty(scriptable, index);
     if (result == ScriptableObject.NOT_FOUND) {
       result = Undefined.instance;
     }
   }
   return result;
 }
  /** Returns an array of the property names on the given script object. */
  private Object[] getObjectIdsImpl(Context cx, Object object) {
    if (!(object instanceof Scriptable) || object == Undefined.instance) {
      return Context.emptyArgs;
    }

    Object[] ids;
    Scriptable scriptable = (Scriptable) object;
    if (scriptable instanceof DebuggableObject) {
      ids = ((DebuggableObject) scriptable).getAllIds();
    } else {
      ids = scriptable.getIds();
    }

    Scriptable proto = scriptable.getPrototype();
    Scriptable parent = scriptable.getParentScope();
    int extra = 0;
    if (proto != null) {
      ++extra;
    }
    if (parent != null) {
      ++extra;
    }
    if (extra != 0) {
      Object[] tmp = new Object[extra + ids.length];
      System.arraycopy(ids, 0, tmp, extra, ids.length);
      ids = tmp;
      extra = 0;
      if (proto != null) {
        ids[extra++] = "__proto__";
      }
      if (parent != null) {
        ids[extra++] = "__parent__";
      }
    }

    return ids;
  }
Example #4
0
 private boolean isAccepted(final Node node) {
   if (filter_ == null) {
     return true;
   }
   Function function = null;
   if (filter_ instanceof Function) {
     function = (Function) filter_;
   }
   final Object acceptNode = filter_.get("acceptNode", filter_);
   if (acceptNode instanceof Function) {
     function = (Function) acceptNode;
   }
   if (function != null) {
     final double value =
         Context.toNumber(
             function.call(
                 Context.getCurrentContext(), getParentScope(), this, new Object[] {node}));
     return value == NodeFilter.FILTER_ACCEPT;
   }
   return true;
 }