| package org.apache.xpath.objects; | |
| import org.apache.xml.utils.FastStringBuffer; | |
| import org.apache.xml.utils.XMLString; | |
| import org.apache.xml.utils.XMLStringFactory; | |
| import org.apache.xml.utils.XMLCharacterRecognizer; | |
| import org.apache.xalan.res.XSLMessages; | |
| import org.apache.xpath.res.XPATHErrorResources; | |
| import java.util.Locale; | |
| /** | |
| * This class will wrap a FastStringBuffer and allow for | |
| */ | |
| public class XStringForChars extends XString | |
| { | |
| /** Pointer to the block containing this string */ | |
| char[] m_chars; | |
| /** The start position in the character array. */ | |
| int m_start; | |
| /** The length of the string. */ | |
| int m_length; | |
| /** | |
| * Construct a XNodeSet object. | |
| * | |
| * @param val FastStringBuffer object this will wrap, must be non-null. | |
| * @param start The start position in the array. | |
| * @param length The number of characters to read from the array. | |
| */ | |
| public XStringForChars(char[] val, int start, int length) | |
| { | |
| if(null == val) | |
| throw new IllegalArgumentException( | |
| XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null)); //"The FastStringBuffer argument can not be null!!"); | |
| m_chars=val; | |
| m_start = start; | |
| m_length = length; | |
| } | |
| /** | |
| * Block inherited constructor. (DO ctors inherit?) | |
| * | |
| * @param val String object this will wrap. | |
| */ | |
| /* | |
| private XStringForChars(String val) | |
| { | |
| super(val); | |
| throw new IllegalArgumentException( | |
| XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XSTRINGFORCHARS_CANNOT_TAKE_STRING, null)); //"XStringForChars can not take a string for an argument!"); | |
| } | |
| */ | |
| /** | |
| * Cast result object to a string. | |
| * | |
| * @return The string this wraps or the empty string if null | |
| */ | |
| public FastStringBuffer fsb() | |
| { | |
| throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FSB_NOT_SUPPORTED_XSTRINGFORCHARS, null)); //"fsb() not supported for XStringForChars!"); | |
| } | |
| /** | |
| * Cast result object to a string. | |
| * | |
| * @return The string this wraps or the empty string if null | |
| */ | |
| public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb) | |
| { | |
| fsb.append(m_chars, m_start, m_length); | |
| } | |
| /** | |
| * Tell if this object contains a java String object. | |
| * | |
| * @return true if this XMLString can return a string without creating one. | |
| */ | |
| public boolean hasString() | |
| { | |
| return (null != m_stringValue); | |
| } | |
| /** | |
| * Cast result object to a string. | |
| * | |
| * @return The string this wraps or the empty string if null | |
| */ | |
| public String str() | |
| { | |
| if(null == m_stringValue) | |
| m_stringValue = new String(m_chars, m_start, m_length); | |
| return m_stringValue; | |
| } | |
| /** Yield result object's string value as a sequence of Character Blocks | |
| * @return a CharacterBlockEnumeration displaying the contents of | |
| * this object's string value (as in str()). May be empty. | |
| * */ | |
| public org.apache.xml.utils.CharacterBlockEnumeration enumerateCharacterBlocks() | |
| { | |
| return new org.apache.xml.utils.CharacterBlockEnumeration( | |
| m_chars, m_start, m_length); | |
| } | |
| /** | |
| * Since this object is incomplete without the length and the offset, we | |
| * have to convert to a string when this function is called. | |
| * | |
| * @return The java String representation of this object. | |
| */ | |
| public Object object() | |
| { | |
| return str(); | |
| } | |
| /** | |
| * Directly call the | |
| * characters method on the passed ContentHandler for the | |
| * string-value. Multiple calls to the | |
| * ContentHandler's characters methods may well occur for a single call to | |
| * this method. | |
| * | |
| * @param ch A non-null reference to a ContentHandler. | |
| * | |
| * @throws org.xml.sax.SAXException | |
| */ | |
| public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch) | |
| throws org.xml.sax.SAXException | |
| { | |
| ch.characters(m_chars, m_start, m_length); | |
| } | |
| /** | |
| * Directly call the | |
| * comment method on the passed LexicalHandler for the | |
| * string-value. | |
| * | |
| * @param lh A non-null reference to a LexicalHandler. | |
| * | |
| * @throws org.xml.sax.SAXException | |
| */ | |
| public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh) | |
| throws org.xml.sax.SAXException | |
| { | |
| lh.comment(m_chars, m_start, m_length); | |
| } | |
| /** | |
| * Returns the length of this string. | |
| * | |
| * @return the length of the sequence of characters represented by this | |
| * object. | |
| */ | |
| public int length() | |
| { | |
| return m_length; | |
| } | |
| /** | |
| * Returns the character at the specified index. An index ranges | |
| * from <code>0</code> to <code>length() - 1</code>. The first character | |
| * of the sequence is at index <code>0</code>, the next at index | |
| * <code>1</code>, and so on, as for array indexing. | |
| * | |
| * @param index the index of the character. | |
| * @return the character at the specified index of this string. | |
| * The first character is at index <code>0</code>. | |
| * @exception IndexOutOfBoundsException if the <code>index</code> | |
| * argument is negative or not less than the length of this | |
| * string. | |
| */ | |
| public char charAt(int index) | |
| { | |
| return (m_chars)[index+m_start]; | |
| } | |
| /** | |
| * Copies characters from this string into the destination character | |
| * array. | |
| * | |
| * @param srcBegin index of the first character in the string | |
| * to copy. | |
| * @param srcEnd index after the last character in the string | |
| * to copy. | |
| * @param dst the destination array. | |
| * @param dstBegin the start offset in the destination array. | |
| * @exception IndexOutOfBoundsException If any of the following | |
| * is true: | |
| * <ul><li><code>srcBegin</code> is negative. | |
| * <li><code>srcBegin</code> is greater than <code>srcEnd</code> | |
| * <li><code>srcEnd</code> is greater than the length of this | |
| * string | |
| * <li><code>dstBegin</code> is negative | |
| * <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than | |
| * <code>dst.length</code></ul> | |
| * @exception NullPointerException if <code>dst</code> is <code>null</code> | |
| */ | |
| public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) | |
| { | |
| System.arraycopy(m_chars, m_start+srcBegin, dst, dstBegin, srcEnd); | |
| } | |
| } |