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

📄 xmlname.java

📁 這是一個javascript 的 interpreter是了解 web browser的好材料
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        }    }    XMLList matchDescendantAttributes(XMLList rv, XML target) {        rv.setTargets(target, null);        addDescendantAttributes(rv, target);        return rv;    }    XMLList matchDescendantChildren(XMLList rv, XML target) {        rv.setTargets(target, null);        addDescendantChildren(rv, target);        return rv;    }    void addDescendants(XMLList rv, XML target) {        XMLName xmlName = this;        if (xmlName.isAttributeName()) {            matchDescendantAttributes(rv, target);        } else {            matchDescendantChildren(rv, target);        }    }    private void addAttributes(XMLList rv, XML target) {        addMatchingAttributes(rv, target);    }    void addMatches(XMLList rv, XML target) {        if (isDescendants()) {            addDescendants(rv, target);        } else if (isAttributeName()) {            addAttributes(rv, target);        } else {            XML[] children = target.getChildren();            if (children != null) {                for (int i=0; i<children.length; i++) {                    if (this.matches(children[i])) {                        rv.addToList( children[i] );                    }                }            }            rv.setTargets(target, this.toQname());        }    }    XMLList getMyValueOn(XML target) {        XMLList rv = target.newXMLList();        addMatches(rv, target);        return rv;    }    void setMyValueOn(XML target, Object value) {        // Special-case checks for undefined and null        if (value == null) {            value = "null";        } else if (value instanceof Undefined) {            value = "undefined";        }        XMLName xmlName = this;        // Get the named property        if (xmlName.isAttributeName()) {            target.setAttribute(xmlName, value);        } else if (xmlName.uri() == null && xmlName.localName().equals("*")) {            target.setChildren(value);        } else {            // Convert text into XML if needed.            XMLObjectImpl xmlValue = null;            if (value instanceof XMLObjectImpl) {                xmlValue = (XMLObjectImpl)value;                // Check for attribute type and convert to textNode                if (xmlValue instanceof XML) {                    if (((XML)xmlValue).isAttribute()) {                        xmlValue = target.makeXmlFromString(xmlName, xmlValue.toString());                    }                }                if (xmlValue instanceof XMLList) {                    for (int i = 0; i < xmlValue.length(); i++) {                        XML xml = ((XMLList) xmlValue).item(i);                        if (xml.isAttribute()) {                            ((XMLList)xmlValue).replace(i, target.makeXmlFromString(xmlName, xml.toString()));                        }                    }                }            } else {                xmlValue = target.makeXmlFromString(xmlName, ScriptRuntime.toString(value));            }            XMLList matches = target.getPropertyList(xmlName);            if (matches.length() == 0) {                target.appendChild(xmlValue);            } else {                // Remove all other matches                for (int i = 1; i < matches.length(); i++) {                    target.removeChild(matches.item(i).childIndex());                }                // Replace first match with new value.                XML firstMatch = matches.item(0);                target.replace(firstMatch.childIndex(), xmlValue);            }        }    }    public boolean has(Context cx) {        if (xmlObject == null) {            return false;        }        return xmlObject.hasXMLProperty(this);    }    public Object get(Context cx) {        if (xmlObject == null) {            throw ScriptRuntime.undefReadError(Undefined.instance,                toString());        }        return xmlObject.getXMLProperty(this);    }    public Object set(Context cx, Object value) {        if (xmlObject == null) {            throw ScriptRuntime.undefWriteError(Undefined.instance,                toString(),                value);        }        // Assignment to descendants causes parse error on bad reference        // and this should not be called        if (isDescendants) throw Kit.codeBug();        xmlObject.putXMLProperty(this, value);        return value;    }    public boolean delete(Context cx) {        if (xmlObject == null) {            return true;        }        xmlObject.deleteXMLProperty(this);        return !xmlObject.hasXMLProperty(this);    }    public String toString() {        //return qname.localName();        StringBuffer buff = new StringBuffer();        if (isDescendants) buff.append("..");        if (isAttributeName) buff.append('@');        if (uri() == null) {            buff.append('*');            if(localName().equals("*")) {                return buff.toString();            }        } else {            buff.append('"').append(uri()).append('"');        }        buff.append(':').append(localName());        return buff.toString();    }    final XmlNode.QName toQname() {        return this.qname;    }    final boolean matchesLocalName(String localName) {        return localName().equals("*") || localName().equals(localName);    }    final boolean matchesElement(XmlNode.QName qname) {        if (this.uri() == null || this.uri().equals(qname.getNamespace().getUri())) {            if (this.localName().equals("*") || this.localName().equals(qname.getLocalName())) {                return true;            }        }        return false;    }    final boolean matches(XML node) {        XmlNode.QName qname = node.getNodeQname();        String nodeUri = null;        if (qname.getNamespace() != null) {            nodeUri = qname.getNamespace().getUri();        }        if (isAttributeName) {            if (node.isAttribute()) {                if (this.uri() == null || this.uri().equals(nodeUri)) {                    if (this.localName().equals("*") || this.localName().equals(qname.getLocalName())) {                        return true;                    }                }                return false;            } else {                //    TODO    Could throw exception maybe, should not call this method on attribute name with arbitrary node type                //            unless we traverse all attributes and children habitually                return false;            }        } else {            if ( this.uri() == null || ((node.isElement()) && this.uri().equals(nodeUri)) ) {                if (localName().equals("*")) return true;                if (node.isElement()) {                    if (localName().equals(qname.getLocalName())) return true;                }            }            return false;        }    }    /**    @deprecated */    boolean isAttributeName() {        return isAttributeName;    }    //    TODO    Fix whether this is an attribute XMLName at construction?    /** @deprecated */    void setAttributeName() {//        if (isAttributeName) throw new IllegalStateException();        isAttributeName = true;    }    /**    @deprecated */    boolean isDescendants() {        return isDescendants;    }    //    TODO    Fix whether this is an descendant XMLName at construction?    /** @deprecated */    void setIsDescendants() {//        if (isDescendants) throw new IllegalStateException();        isDescendants = true;    }}

⌨️ 快捷键说明

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