📄 pageattribute.java
字号:
/** * Get the value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. * <em>NOTE:</em> This does not include any quotes that may have enclosed * the value when it was read. To get the un-stripped value use * {@link #getRawValue}. * @return The value, or <code>null</code> if it's a stand-alone or * empty attribute, or the text if it's just a whitepace 'attribute'. */ public String getValue () { String ret; ret = super.getValue (); if (null == ret) { if ((null != mPage) && (0 <= mValueEnd)) { ret = mPage.getText (mValueStart, mValueEnd); setValue (ret); // cache the value } } return (ret); } /** * Get the value of the attribute. * @param buffer The buffer to place the value in. * @see #getValue() */ public void getValue (StringBuffer buffer) { String value; value = super.getValue (); if (null == value) { if ((null != mPage) && (0 <= mValueEnd)) mPage.getText (buffer, mNameStart, mNameEnd); } else buffer.append (value); } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @return The value, or <code>null</code> if it's a stand-alone attribute, * or the text if it's just a whitepace 'attribute'. */ public String getRawValue () { char quote; StringBuffer buffer; String ret; ret = getValue (); if (null != ret && (0 != (quote = getQuote ()))) { buffer = new StringBuffer (ret.length() + 2); buffer.append (quote); buffer.append (ret); buffer.append (quote); ret = buffer.toString (); } return (ret); } /** * Get the raw value of the attribute. * The part after the equals sign, or the text if it's just a whitepace * 'attribute'. This includes the quotes around the value if any. * @param buffer The string buffer to append the attribute value to. * @see #getRawValue() */ public void getRawValue (StringBuffer buffer) { char quote; if (null == mValue) { if (0 <= mValueEnd) { if (0 != (quote = getQuote ())) buffer.append (quote); if (mValueStart != mValueEnd) mPage.getText (buffer, mValueStart, mValueEnd); if (0 != quote) buffer.append (quote); } } else { if (0 != (quote = getQuote ())) buffer.append (quote); buffer.append (mValue); if (0 != quote) buffer.append (quote); } } /** * Get the page this attribute is anchored to, if any. * @return The page used to construct this attribute, or null if this * is just a regular attribute. */ public Page getPage () { return (mPage); } /** * Set the page this attribute is anchored to. * @param page The page to be used to construct this attribute. * Note: If you set this you probably also want to uncache the property * values by setting them to null. */ public void setPage (Page page) { mPage = page; } /** * Get the starting position of the attribute name. * @return The offset into the page at which the name begins. */ public int getNameStartPosition () { return (mNameStart); } /** * Set the starting position of the attribute name. * @param start The new offset into the page at which the name begins. */ public void setNameStartPosition (int start) { mNameStart = start; setName (null); // uncache value } /** * Get the ending position of the attribute name. * @return The offset into the page at which the name ends. */ public int getNameEndPosition () { return (mNameEnd); } /** * Set the ending position of the attribute name. * @param end The new offset into the page at which the name ends. */ public void setNameEndPosition (int end) { mNameEnd = end; setName (null); // uncache value setAssignment (null); // uncache value } /** * Get the starting position of the attribute value. * @return The offset into the page at which the value begins. */ public int getValueStartPosition () { return (mValueStart); } /** * Set the starting position of the attribute value. * @param start The new offset into the page at which the value begins. */ public void setValueStartPosition (int start) { mValueStart = start; setAssignment (null); // uncache value setValue (null); // uncache value } /** * Get the ending position of the attribute value. * @return The offset into the page at which the value ends. */ public int getValueEndPosition () { return (mValueEnd); } /** * Set the ending position of the attribute value. * @param end The new offset into the page at which the value ends. */ public void setValueEndPosition (int end) { mValueEnd = end; setValue (null); // uncache value } /** * Predicate to determine if this attribute is whitespace. * @return <code>true</code> if this attribute is whitespace, * <code>false</code> if it is a real attribute. */ public boolean isWhitespace () { return (((null == super.getName ()) && (null == mPage)) || ((null != mPage) && (0 > mNameStart))); } /** * Predicate to determine if this attribute has no equals sign (or value). * @return <code>true</code> if this attribute is a standalone attribute. * <code>false</code> if has an equals sign. */ public boolean isStandAlone () { return (!isWhitespace () // not whitespace && (null == super.getAssignment ()) // and no explicit assignment provided && !isValued () // and has no value && ((null == mPage) // and either its not coming from a page // or it is coming from a page and it doesn't have an assignment part || ((null != mPage) && (0 <= mNameEnd) && (0 > mValueStart)))); } /** * Predicate to determine if this attribute has an equals sign but no value. * @return <code>true</code> if this attribute is an empty attribute. * <code>false</code> if has an equals sign and a value. */ public boolean isEmpty () { return (!isWhitespace () // not whitespace && !isStandAlone () // and not standalone && (null == super.getValue ()) // and no explicit value provided && ((null == mPage) // and either its not coming from a page // or it is coming from a page and has no value || ((null != mPage) && (0 > mValueEnd)))); } /** * Predicate to determine if this attribute has a value. * @return <code>true</code> if this attribute has a value. * <code>false</code> if it is empty or standalone. */ public boolean isValued () { return ((null != super.getValue ()) // an explicit value provided // or it is coming from a page and has a non-empty value || ((null != mPage) && ((0 <= mValueStart) && (0 <= mValueEnd)) && (mValueStart != mValueEnd))); } /** * Get the length of the string value of this attribute. * @return The number of characters required to express this attribute. */ public int getLength () { String name; String assignment; String value; char quote; int ret; ret = 0; name = super.getName (); if (null != name) ret += name.length (); else if ((null != mPage) && (0 <= mNameStart) && (0 <= mNameEnd)) ret += mNameEnd - mNameStart; assignment = super.getAssignment (); if (null != assignment) ret += assignment.length (); else if ((null != mPage) && (0 <= mNameEnd) && (0 <= mValueStart)) ret += mValueStart - mNameEnd; value = super.getValue (); if (null != value) ret += value.length (); else if ((null != mPage) && (0 <= mValueStart) && (0 <= mValueEnd)) ret += mValueEnd - mValueStart; quote = getQuote (); if (0 != quote) ret += 2; return (ret); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -