1 16 19 package org.apache.xpath.objects; 20 21 import org.apache.xalan.res.XSLMessages; 22 import org.apache.xml.utils.FastStringBuffer; 23 import org.apache.xpath.res.XPATHErrorResources; 24 25 26 29 public class XStringForChars extends XString 30 { 31 32 int m_start; 33 34 35 int m_length; 36 37 protected String m_strCache = null; 38 39 46 public XStringForChars(char[] val, int start, int length) 47 { 48 super(val); 49 m_start = start; 50 m_length = length; 51 if(null == val) 52 throw new IllegalArgumentException ( 53 XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FASTSTRINGBUFFER_CANNOT_BE_NULL, null)); } 55 56 57 62 private XStringForChars(String val) 63 { 64 super(val); 65 throw new IllegalArgumentException ( 66 XSLMessages.createXPATHMessage(XPATHErrorResources.ER_XSTRINGFORCHARS_CANNOT_TAKE_STRING, null)); } 68 69 74 public FastStringBuffer fsb() 75 { 76 throw new RuntimeException (XSLMessages.createXPATHMessage(XPATHErrorResources.ER_FSB_NOT_SUPPORTED_XSTRINGFORCHARS, null)); } 78 79 84 public void appendToFsb(org.apache.xml.utils.FastStringBuffer fsb) 85 { 86 fsb.append((char[])m_obj, m_start, m_length); 87 } 88 89 90 95 public boolean hasString() 96 { 97 return (null != m_strCache); 98 } 99 100 101 106 public String str() 107 { 108 if(null == m_strCache) 109 m_strCache = new String ((char[])m_obj, m_start, m_length); 110 111 return m_strCache; 112 } 113 114 115 121 public Object object() 122 { 123 return str(); 124 } 125 126 137 public void dispatchCharactersEvents(org.xml.sax.ContentHandler ch) 138 throws org.xml.sax.SAXException 139 { 140 ch.characters((char[])m_obj, m_start, m_length); 141 } 142 143 152 public void dispatchAsComment(org.xml.sax.ext.LexicalHandler lh) 153 throws org.xml.sax.SAXException 154 { 155 lh.comment((char[])m_obj, m_start, m_length); 156 } 157 158 164 public int length() 165 { 166 return m_length; 167 } 168 169 182 public char charAt(int index) 183 { 184 return ((char[])m_obj)[index+m_start]; 185 } 186 187 208 public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) 209 { 210 System.arraycopy((char[])m_obj, m_start+srcBegin, dst, dstBegin, srcEnd); 211 } 212 213 } 214 | Popular Tags |