⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmllist.java

📁 這是一個javascript 的 interpreter是了解 web browser的好材料
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            result.addToList(getXmlFromAnnotation(i).child(index));        }        return result;    }    XMLList child(XMLName xmlName) {        XMLList result = newXMLList();        for (int i = 0; i < length(); i++) {            result.addToList(getXmlFromAnnotation(i).child(xmlName));        }        return result;    }    void addMatches(XMLList rv, XMLName name) {        for (int i=0; i<length(); i++) {            getXmlFromAnnotation(i).addMatches(rv, name);        }    }    XMLList children() {        java.util.Vector v = new java.util.Vector();        for (int i = 0; i < length(); i++) {            XML xml = getXmlFromAnnotation(i);            if (xml != null) {                Object o = xml.children();                if (o instanceof XMLList) {                    XMLList childList = (XMLList)o;                    int cChildren = childList.length();                    for (int j = 0; j < cChildren; j++) {                        v.addElement(childList.item(j));                    }                }            }        }        XMLList allChildren = newXMLList();        int sz = v.size();        for (int i = 0; i < sz; i++) {            allChildren.addToList(v.get(i));        }        return allChildren;    }    XMLList comments() {        XMLList result = newXMLList();        for (int i = 0; i < length(); i++) {            XML xml = getXmlFromAnnotation(i);            result.addToList(xml.comments());        }        return result;    }    XMLList elements(XMLName name) {        XMLList rv = newXMLList();        for (int i=0; i<length(); i++) {            XML xml = getXmlFromAnnotation(i);            rv.addToList(xml.elements(name));        }        return rv;    }    boolean contains(Object xml) {        boolean result = false;        for (int i = 0; i < length(); i++) {            XML member = getXmlFromAnnotation(i);            if (member.equivalentXml(xml)) {                result = true;                break;            }        }        return result;    }    XMLObjectImpl copy() {        XMLList result = newXMLList();        for (int i = 0; i < length(); i++) {            XML xml = getXmlFromAnnotation(i);            result.addToList(xml.copy());        }        return result;    }    boolean hasOwnProperty(XMLName xmlName) {        if (isPrototype()) {            String property = xmlName.localName();            return (findPrototypeId(property) != 0);        } else {            return (getPropertyList(xmlName).length() > 0);        }    }    boolean hasComplexContent() {        boolean complexContent;        int length = length();        if (length == 0) {            complexContent = false;        } else if (length == 1) {            complexContent = getXmlFromAnnotation(0).hasComplexContent();        } else {            complexContent = false;            for (int i = 0; i < length; i++) {                XML nextElement = getXmlFromAnnotation(i);                if (nextElement.isElement()) {                    complexContent = true;                    break;                }            }        }        return complexContent;    }    boolean hasSimpleContent() {        if (length() == 0) {            return true;        } else if (length() == 1) {            return getXmlFromAnnotation(0).hasSimpleContent();        } else {            for (int i=0; i<length(); i++) {                XML nextElement = getXmlFromAnnotation(i);                if (nextElement.isElement()) {                    return false;                }            }            return true;        }    }    int length() {        int result = 0;        if (_annos != null) {            result = _annos.length();        }        return result;    }    void normalize() {        for (int i = 0; i < length(); i++) {            getXmlFromAnnotation(i).normalize();        }    }    /**     * If list is empty, return undefined, if elements have different parents return undefined,     * If they all have the same parent, return that parent     */    Object parent() {        if (length() == 0) return Undefined.instance;        XML candidateParent = null;        for (int i = 0; i < length(); i++) {            Object currParent = getXmlFromAnnotation(i).parent();            if (!(currParent instanceof XML)) return Undefined.instance;            XML xml = (XML)currParent;            if (i == 0) {                // Set the first for the rest to compare to.                candidateParent = xml;            } else {                if (candidateParent.is(xml)) {                    //    keep looking                } else {                    return Undefined.instance;                }            }        }        return candidateParent;    }    XMLList processingInstructions(XMLName xmlName) {        XMLList result = newXMLList();        for (int i = 0; i < length(); i++) {            XML xml = getXmlFromAnnotation(i);            result.addToList(xml.processingInstructions(xmlName));        }        return result;    }    boolean propertyIsEnumerable(Object name) {        long index;        if (name instanceof Integer) {            index = ((Integer)name).intValue();        } else if (name instanceof Number) {            double x = ((Number)name).doubleValue();            index = (long)x;            if (index != x) {                return false;            }            if (index == 0 && 1.0 / x < 0) {                // Negative 0                return false;            }        } else {            String s = ScriptRuntime.toString(name);            index = ScriptRuntime.testUint32String(s);        }        return (0 <= index && index < length());    }    XMLList text() {        XMLList result = newXMLList();        for (int i = 0; i < length(); i++) {            result.addToList(getXmlFromAnnotation(i).text());        }        return result;    }    public String toString() {        //    ECMA357 10.1.2        if (hasSimpleContent()) {            StringBuffer sb = new StringBuffer();            for(int i = 0; i < length(); i++) {                XML next = getXmlFromAnnotation(i);                if (next.isComment() || next.isProcessingInstruction()) {                    //    do nothing                } else {                    sb.append(next.toString());                }            }            return sb.toString();        } else {            return toXMLString();        }    }    String toXMLString() {        //    See ECMA 10.2.1        StringBuffer sb = new StringBuffer();        for (int i=0; i<length(); i++) {            if (getProcessor().isPrettyPrinting() && i != 0) {                sb.append('\n');            }            sb.append(getXmlFromAnnotation(i).toXMLString());        }        return sb.toString();    }    Object valueOf() {        return this;    }    //    // Other public Functions from XMLObject    //    boolean equivalentXml(Object target) {        boolean result = false;        // Zero length list should equate to undefined        if (target instanceof Undefined && length() == 0) {            result = true;        } else if (length() == 1) {            result = getXmlFromAnnotation(0).equivalentXml(target);        } else if (target instanceof XMLList) {            XMLList otherList = (XMLList) target;            if (otherList.length() == length()) {                result = true;                for (int i = 0; i < length(); i++) {                    if (!getXmlFromAnnotation(i).equivalentXml(otherList.getXmlFromAnnotation(i))) {                        result = false;                        break;                    }                }            }        }        return result;    }    private XMLList getPropertyList(XMLName name) {        XMLList propertyList = newXMLList();        XmlNode.QName qname = null;        if (!name.isDescendants() && !name.isAttributeName()) {            // Only set the targetProperty if this is a regular child get            // and not a descendant or attribute get            qname = name.toQname();        }        propertyList.setTargets(this, qname);        for (int i = 0; i < length(); i++) {            propertyList.addToList(                getXmlFromAnnotation(i).getPropertyList(name));        }        return propertyList;    }    private Object applyOrCall(boolean isApply,        Context cx, Scriptable scope,        Scriptable thisObj, Object[] args) {        String methodName = isApply ? "apply" : "call";        if(!(thisObj instanceof XMLList) ||            ((XMLList)thisObj).targetProperty == null)            throw ScriptRuntime.typeError1("msg.isnt.function",                methodName);        return ScriptRuntime.applyOrCall(isApply, cx, scope, thisObj, args);    }    protected Object jsConstructor(Context cx, boolean inNewExpr,        Object[] args) {        if (args.length == 0) {            return newXMLList();        } else {            Object arg0 = args[0];            if (!inNewExpr && arg0 instanceof XMLList) {                // XMLList(XMLList) returns the same object.                return arg0;            }            return newXMLListFrom(arg0);        }    }    /**     * See ECMA 357, 11_2_2_1, Semantics, 3_e.     */    public Scriptable getExtraMethodSource(Context cx) {        if (length() == 1) {            return getXmlFromAnnotation(0);        }        return null;    }    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);        Callable method = ScriptRuntime.getElemFunctionAndThis(            this, methodName, cx);        // Call lastStoredScriptable to clear stored thisObj        // but ignore the result as the method should use the supplied        // thisObj, not one from redirected call        ScriptRuntime.lastStoredScriptable(cx);        return method.call(cx, scope, thisObj, args);    }    public Scriptable construct(Context cx, Scriptable scope, Object[] args) {        throw ScriptRuntime.typeError1("msg.not.ctor", "XMLList");    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -