Exemplo n.º 1
0
  @Override
  void putXMLProperty(XMLName xmlName, Object value) {
    // Log("put property: " + name);

    // Special-case checks for undefined and null
    if (value == null) {
      value = "null";
    } else if (value instanceof Undefined) {
      value = "undefined";
    }

    if (length() > 1) {
      throw ScriptRuntime.typeError("Assignment to lists with more than one item is not supported");
    } else if (length() == 0) {
      // Secret sauce for super-expandos.
      // We set an element here, and then add ourselves to our target.
      if (targetObject != null
          && targetProperty != null
          && targetProperty.getLocalName() != null
          && targetProperty.getLocalName().length() > 0) {
        // Add an empty element with our targetProperty name and
        // then set it.
        XML xmlValue = newTextElementXML(null, targetProperty, null);
        addToList(xmlValue);

        if (xmlName.isAttributeName()) {
          setAttribute(xmlName, value);
        } else {
          XML xml = item(0);
          xml.putXMLProperty(xmlName, value);

          // Update the list with the new item at location 0.
          replace(0, item(0));
        }

        // Now add us to our parent
        XMLName name2 =
            XMLName.formProperty(
                targetProperty.getNamespace().getUri(), targetProperty.getLocalName());
        targetObject.putXMLProperty(name2, this);
        replace(0, targetObject.getXML().getLastXmlChild());
      } else {
        throw ScriptRuntime.typeError("Assignment to empty XMLList without targets not supported");
      }
    } else if (xmlName.isAttributeName()) {
      setAttribute(xmlName, value);
    } else {
      XML xml = item(0);
      xml.putXMLProperty(xmlName, value);

      // Update the list with the new item at location 0.
      replace(0, item(0));
    }
  }
Exemplo n.º 2
0
 XmlNode.QName toNodeQName(Context cx, String name, boolean attribute) {
   XmlNode.Namespace defaultNamespace = getDefaultNamespace(cx).getDelegate();
   if (name != null && name.equals("*")) {
     return XmlNode.QName.create(null, null);
   } else {
     if (attribute) {
       return XmlNode.QName.create(XmlNode.Namespace.GLOBAL, name);
     } else {
       return XmlNode.QName.create(defaultNamespace, name);
     }
   }
 }
Exemplo n.º 3
0
  XmlNode.QName toNodeQName(Context cx, Object namespaceValue, Object nameValue) {
    // This is duplication of constructQName(cx, namespaceValue, nameValue)
    // but for XMLName

    String localName;

    if (nameValue instanceof QName) {
      QName qname = (QName) nameValue;
      localName = qname.localName();
    } else {
      localName = ScriptRuntime.toString(nameValue);
    }

    XmlNode.Namespace ns;
    if (namespaceValue == Undefined.instance) {
      if ("*".equals(localName)) {
        ns = null;
      } else {
        ns = getDefaultNamespace(cx).getDelegate();
      }
    } else if (namespaceValue == null) {
      ns = null;
    } else if (namespaceValue instanceof Namespace) {
      ns = ((Namespace) namespaceValue).getDelegate();
    } else {
      ns = this.namespacePrototype.constructNamespace(namespaceValue).getDelegate();
    }

    if (localName != null && localName.equals("*")) localName = null;
    return XmlNode.QName.create(ns, localName);
  }
Exemplo n.º 4
0
  private void exportToScope(boolean sealed) {
    xmlPrototype = newXML(XmlNode.createText(options, ""));
    xmlListPrototype = newXMLList();
    namespacePrototype = Namespace.create(this.globalScope, null, XmlNode.Namespace.GLOBAL);
    qnamePrototype =
        QName.create(
            this, this.globalScope, null, XmlNode.QName.create(XmlNode.Namespace.create(""), ""));

    xmlPrototype.exportAsJSClass(sealed);
    xmlListPrototype.exportAsJSClass(sealed);
    namespacePrototype.exportAsJSClass(sealed);
    qnamePrototype.exportAsJSClass(sealed);
  }
Exemplo n.º 5
0
 /** @deprecated */
 XMLName toAttributeName(Context cx, Object nameValue) {
   if (nameValue instanceof XMLName) {
     //    TODO    Will this always be an XMLName of type attribute name?
     return (XMLName) nameValue;
   } else if (nameValue instanceof QName) {
     return XMLName.create(((QName) nameValue).getDelegate(), true, false);
   } else if (nameValue instanceof Boolean
       || nameValue instanceof Number
       || nameValue == Undefined.instance
       || nameValue == null) {
     throw badXMLName(nameValue);
   } else {
     //    TODO    Not 100% sure that putting these in global namespace is the right thing to do
     String localName = null;
     if (nameValue instanceof String) {
       localName = (String) nameValue;
     } else {
       localName = ScriptRuntime.toString(nameValue);
     }
     if (localName != null && localName.equals("*")) localName = null;
     return XMLName.create(
         XmlNode.QName.create(XmlNode.Namespace.create(""), localName), true, false);
   }
 }
Exemplo n.º 6
0
  public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    // This XMLList is being called as a Function.
    // Let's find the real Function object.
    if (targetProperty == null) throw ScriptRuntime.notFunctionError(this);

    String methodName = targetProperty.getLocalName();

    boolean isApply = methodName.equals("apply");
    if (isApply || methodName.equals("call")) return applyOrCall(isApply, cx, scope, thisObj, args);

    if (!(thisObj instanceof XMLObject)) {
      throw ScriptRuntime.typeError1("msg.incompat.call", methodName);
    }
    Object func = null;
    Scriptable sobj = thisObj;

    while (sobj instanceof XMLObject) {
      XMLObject xmlObject = (XMLObject) sobj;
      func = xmlObject.getFunctionProperty(cx, methodName);
      if (func != Scriptable.NOT_FOUND) {
        break;
      }
      sobj = xmlObject.getExtraMethodSource(cx);
      if (sobj != null) {
        thisObj = sobj;
        if (!(sobj instanceof XMLObject)) {
          func = ScriptableObject.getProperty(sobj, methodName);
        }
      }
    }

    if (!(func instanceof Callable)) {
      throw ScriptRuntime.notFunctionError(thisObj, func, methodName);
    }
    return ((Callable) func).call(cx, scope, thisObj, args);
  }