xmlattributesimpl.java
来自「JAVA 所有包」· Java 代码 · 共 1,168 行 · 第 1/3 页
JAVA
1,168 行
} // setType(int,String) /** * Sets the value of the attribute at the specified index. This * method will overwrite the non-normalized value of the attribute. * * @param attrIndex The attribute index. * @param attrValue The new attribute value. * * @see #setNonNormalizedValue */ public void setValue(int attrIndex, String attrValue) { setValue(attrIndex,attrValue,null); } public void setValue(int attrIndex, String attrValue,XMLString value) { Attribute attribute = fAttributes[attrIndex]; attribute.value = attrValue; attribute.nonNormalizedValue = attrValue; attribute.xmlValue = value; } // setValue(int,String) /** * Sets the non-normalized value of the attribute at the specified * index. * * @param attrIndex The attribute index. * @param attrValue The new non-normalized attribute value. */ public void setNonNormalizedValue(int attrIndex, String attrValue) { if (attrValue == null) { attrValue = fAttributes[attrIndex].value; } fAttributes[attrIndex].nonNormalizedValue = attrValue; } // setNonNormalizedValue(int,String) /** * Returns the non-normalized value of the attribute at the specified * index. If no non-normalized value is set, this method will return * the same value as the <code>getValue(int)</code> method. * * @param attrIndex The attribute index. */ public String getNonNormalizedValue(int attrIndex) { String value = fAttributes[attrIndex].nonNormalizedValue; return value; } // getNonNormalizedValue(int):String /** * Sets whether an attribute is specified in the instance document * or not. * * @param attrIndex The attribute index. * @param specified True if the attribute is specified in the instance * document. */ public void setSpecified(int attrIndex, boolean specified) { fAttributes[attrIndex].specified = specified; } // setSpecified(int,boolean) /** * Returns true if the attribute is specified in the instance document. * * @param attrIndex The attribute index. */ public boolean isSpecified(int attrIndex) { return fAttributes[attrIndex].specified; } // isSpecified(int):boolean // // AttributeList and Attributes methods // /** * Return the number of attributes in the list. * * <p>Once you know the number of attributes, you can iterate * through the list.</p> * * @return The number of attributes in the list. */ public int getLength() { return fLength; } // getLength():int /** * Look up an attribute's type by index. * * <p>The attribute type is one of the strings "CDATA", "ID", * "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", * or "NOTATION" (always in upper case).</p> * * <p>If the parser has not read a declaration for the attribute, * or if the parser does not report attribute types, then it must * return the value "CDATA" as stated in the XML 1.0 Recommentation * (clause 3.3.3, "Attribute-Value Normalization").</p> * * <p>For an enumerated attribute that is not a notation, the * parser will report the type as "NMTOKEN".</p> * * @param index The attribute index (zero-based). * @return The attribute's type as a string, or null if the * index is out of range. * @see #getLength */ public String getType(int index) { if (index < 0 || index >= fLength) { return null; } return getReportableType(fAttributes[index].type); } // getType(int):String /** * Look up an attribute's type by XML 1.0 qualified name. * * <p>See {@link #getType(int) getType(int)} for a description * of the possible types.</p> * * @param qname The XML 1.0 qualified name. * @return The attribute type as a string, or null if the * attribute is not in the list or if qualified names * are not available. */ public String getType(String qname) { int index = getIndex(qname); return index != -1 ? getReportableType(fAttributes[index].type) : null; } // getType(String):String /** * Look up an attribute's value by index. * * <p>If the attribute value is a list of tokens (IDREFS, * ENTITIES, or NMTOKENS), the tokens will be concatenated * into a single string with each token separated by a * single space.</p> * * @param index The attribute index (zero-based). * @return The attribute's value as a string, or null if the * index is out of range. * @see #getLength */ public String getValue(int index) { if (index < 0 || index >= fLength) { return null; } if(fAttributes[index].value == null && fAttributes[index].xmlValue != null) fAttributes[index].value = fAttributes[index].xmlValue.toString(); return fAttributes[index].value; } // getValue(int):String /** * Look up an attribute's value by XML 1.0 qualified name. * * <p>See {@link #getValue(int) getValue(int)} for a description * of the possible values.</p> * * @param qname The XML 1.0 qualified name. * @return The attribute value as a string, or null if the * attribute is not in the list or if qualified names * are not available. */ public String getValue(String qname) { int index = getIndex(qname); if(index == -1 ) return null; if(fAttributes[index].value == null) fAttributes[index].value = fAttributes[index].xmlValue.toString(); return fAttributes[index].value; } // getValue(String):String // // AttributeList methods // /** * Return the name of an attribute in this list (by position). * * <p>The names must be unique: the SAX parser shall not include the * same attribute twice. Attributes without values (those declared * #IMPLIED without a value specified in the start tag) will be * omitted from the list.</p> * * <p>If the attribute name has a namespace prefix, the prefix * will still be attached.</p> * * @param i The index of the attribute in the list (starting at 0). * @return The name of the indexed attribute, or null * if the index is out of range. * @see #getLength */ public String getName(int index) { if (index < 0 || index >= fLength) { return null; } return fAttributes[index].name.rawname; } // getName(int):String // // Attributes methods // /** * Look up the index of an attribute by XML 1.0 qualified name. * * @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndex(String qName) { for (int i = 0; i < fLength; i++) { Attribute attribute = fAttributes[i]; if (attribute.name.rawname != null && attribute.name.rawname.equals(qName)) { return i; } } return -1; } // getIndex(String):int /** * Look up the index of an attribute by Namespace name. * * @param uri The Namespace URI, or null if * the name has no Namespace URI. * @param localName The attribute's local name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndex(String uri, String localPart) { for (int i = 0; i < fLength; i++) { Attribute attribute = fAttributes[i]; if (attribute.name.localpart != null && attribute.name.localpart.equals(localPart) && ((uri==attribute.name.uri) || (uri!=null && attribute.name.uri!=null && attribute.name.uri.equals(uri)))) { return i; } } return -1; } // getIndex(String,String):int /** * Look up an attribute's local name by index. * * @param index The attribute index (zero-based). * @return The local name, or the empty string if Namespace * processing is not being performed, or null * if the index is out of range. * @see #getLength */ public String getLocalName(int index) { if (!fNamespaces) { return ""; } if (index < 0 || index >= fLength) { return null; } return fAttributes[index].name.localpart; } // getLocalName(int):String /** * Look up an attribute's XML 1.0 qualified name by index. * * @param index The attribute index (zero-based). * @return The XML 1.0 qualified name, or the empty string * if none is available, or null if the index * is out of range. * @see #getLength */ public String getQName(int index) { if (index < 0 || index >= fLength) { return null; } String rawname = fAttributes[index].name.rawname; return rawname != null ? rawname : ""; } // getQName(int):String public QName getQualifiedName(int index){ if (index < 0 || index >= fLength) { return null; } return fAttributes[index].name; } /** * Look up an attribute's type by Namespace name. * * <p>See {@link #getType(int) getType(int)} for a description * of the possible types.</p> * * @param uri The Namespace URI, or null if the * name has no Namespace URI. * @param localName The local name of the attribute. * @return The attribute type as a string, or null if the * attribute is not in the list or if Namespace * processing is not being performed. */ public String getType(String uri, String localName) { if (!fNamespaces) { return null; } int index = getIndex(uri, localName); return index != -1 ? getType(index) : null; } // getType(String,String):String /** * Look up the index of an attribute by XML 1.0 qualified name. * <p> * <strong>Note:</strong> * This method uses reference comparison, and thus should * only be used internally. We cannot use this method in any * code exposed to users as they may not pass in unique strings. * * @param qName The qualified (prefixed) name. * @return The index of the attribute, or -1 if it does not * appear in the list. */ public int getIndexFast(String qName) { for (int i = 0; i < fLength; ++i) { Attribute attribute = fAttributes[i]; if (attribute.name.rawname == qName) { return i; } } return -1; } // getIndexFast(String):int /** * Adds an attribute. The attribute's non-normalized value of the * attribute will have the same value as the attribute value until * set using the <code>setNonNormalizedValue</code> method. Also, * the added attribute will be marked as specified in the XML instance * document unless set otherwise using the <code>setSpecified</code> * method. * <p> * This method differs from <code>addAttribute</code> in that it * does not check if an attribute of the same name already exists * in the list before adding it. In order to improve performance * of namespace processing, this method allows uniqueness checks * to be deferred until all the namespace information is available * after the entire attribute specification has been read. * <p> * <strong>Caution:</strong> If this method is called it should * not be mixed with calls to <code>addAttribute</code> unless * it has been determined that all the attribute names are unique. * * @param name the attribute name * @param type the attribute type * @param value the attribute value * * @see #setNonNormalizedValue * @see #setSpecified * @see #checkDuplicatesNS */ public void addAttributeNS(QName name, String type, String value) { int index = fLength; if (fLength++ == fAttributes.length) { Attribute[] attributes; if (fLength < SIZE_LIMIT) { attributes = new Attribute[fAttributes.length + 4]; } else { attributes = new Attribute[fAttributes.length << 1]; } System.arraycopy(fAttributes, 0, attributes, 0, fAttributes.length); for (int i = fAttributes.length; i < attributes.length; i++) { attributes[i] = new Attribute(); } fAttributes = attributes; } // set values Attribute attribute = fAttributes[index]; attribute.name.setValues(name); attribute.type = type; attribute.value = value; attribute.nonNormalizedValue = value; attribute.specified = false; // clear augmentations attribute.augs.removeAllItems(); } /** * Checks for duplicate expanded names (local part and namespace name * pairs) in the attribute specification. If a duplicate is found its * name is returned. * <p> * This should be called once all the in-scope namespaces for the element * enclosing these attributes is known, and after all the attributes * have gone through namespace binding.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?