/** * getSize gets the fragment with ns compensation * @return * */ public final int getSize(){ //int encoding = vn.encoding; int len = (int) (l >> 32); if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); len += (vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4; } return len; }
/** * getSize gets the fragment with ns compensation * @return * */ public final int getSize(){ //int encoding = vn.encoding; int len = (int) (l >> 32); if (stLen != 0) for (int i = 0; i < fib.size(); i++) { int k = fib.intAt(i); len += (vn.getTokenLength(k) & 0xffff) + vn.getTokenLength(k + 1) + 4; } return len; }
/** * Convert a token at the given index to a String, * (entities and char references not expanded). * Creation date: (11/16/03 7:28:49 PM) * * @return java.lang.String * @param index int * @exception NavException When the encoding has errors */ final public String toRawString(int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); int offset = getTokenOffset(index); return toRawString(offset, len); }
/** * Convert a token at the given index to a String, lower case chars * get converted into upper case * (entities and char references not expanded). * @param index * @return * @exception NavException */ final public String toRawStringUpperCase(int index) throws NavException { int type = getTokenType(index); int len; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); int offset = getTokenOffset(index); return toRawStringUpperCase(offset, len); }
final protected boolean matchRawTokenString2_IgnoreCase(int index, String s) throws NavException { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int len2= (int)((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN)>>43) ; int os2 = (len2 == 0)?0:len2+1; // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime return compareRawTokenString_IgnoreCase(getTokenOffset(index)+os2, len-os2, s)==0; }
final protected boolean matchRawTokenString2(int index, String s) throws NavException { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); int len2= (int)((vtdBuffer.longAt(index)& MASK_TOKEN_FULL_LEN)>>43) ; int os2 = (len2 == 0)?0:len2+1; // upper 16 bit is zero or for prefix //currentOffset = getTokenOffset(index); // point currentOffset to the beginning of the token // for UTF 8 and ISO, the performance is a little better by avoid // calling getChar() everytime return compareRawTokenString(getTokenOffset(index)+os2, len-os2, s)==0; } /**
/** * Test whether the URL is defined in the scope. Null is allowed to indicate * the name space is undefined. Creation date: (11/16/03 7:54:01 PM) * * @param URL * java.lang.String * @exception com.ximpleware.NavException * When there is any encoding conversion error or unknown * entity. */ final protected int lookupNS() throws NavException { if (context[0]==-1) throw new NavException("Can't lookup NS for document node"); int i = getTokenLength((context[0] != 0) ? context[context[0]] : rootIndex); int offset = getTokenOffset((context[0] != 0) ? context[context[0]] : rootIndex); int preLen = (i >> 16) & 0xffff; return lookupNS(offset, preLen); //return resolveNS(URL, offset, preLen); }
/** * Convert a token at the given index to a String and any lower case * character will be converted to upper case, (entities and char * references resolved character data and attr val). * @param index * @return * @exception NavException */ public String toStringUpperCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringUpperCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringUpperCase(offset, len); }
/** * Convert a token at the given index to a String and any lower case * character will be converted to upper case, (entities and char * references resolved character data and attr val). * @param index * @return * @throws NavException */ public String toStringUpperCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringUpperCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringUpperCase(offset, len); }
/** * Convert a token at the given index to a String and any upper case * character will be converted to lower case, (entities and char * references resolved for character data and attr val). * @param index * @return * @throws NavException */ public String toStringLowerCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringLowerCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringLowerCase(offset, len); }
/** * Convert a token at the given index to a String and any upper case * character will be converted to lower case, (entities and char * references resolved for character data and attr val). * @param index * @return * @exception NavException */ public String toStringLowerCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringLowerCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringLowerCase(offset, len); }
/** * Convert a token at the given index to a String and any lower case * character will be converted to upper case, (entities and char * references resolved character data and attr val). * @param index * @return * @throws NavException */ public String toStringUpperCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringUpperCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringUpperCase(offset, len); }
/** * Convert a token at the given index to a String and any upper case * character will be converted to lower case, (entities and char * references resolved for character data and attr val). * @param index * @return * @throws NavException */ public String toStringLowerCase(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawStringLowerCase(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toStringLowerCase(offset, len); }
/** * Convert a token at the given index to a String, (entities and char * references resolved character data and attr val). An attribute name or * an element name will get the UCS2 string of qualified name * Creation date: (11/16/03 7:27:19 PM) * * @return java.lang.String * @param index * @exception NavException */ public String toString(int index) throws NavException { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); int len; len = getTokenLength(index); int offset = getTokenOffset(index); return toString(offset, len); }
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
/** * * @param l * @throws ModifyException */ private void insertEndingTag(long l) throws ModifyException{ int i = md.getCurrentIndex(); int offset = md.getTokenOffset(i); int length = md.getTokenLength(i)&0xffff; byte[] xml = md.getXML().getBytes(); if (md.encoding <VTDNav.FORMAT_UTF_16BE ) insertBytesAt((int)l,xml,offset,length); else insertBytesAt((int)l, xml, offset<<1, length<<1); }
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }
/** * Remove an attribute name value pair from the master document. * @param attrNameIndex * */ public void removeAttribute(int attrNameIndex) throws ModifyException{ int type = md.getTokenType(attrNameIndex); if (type != VTDNav.TOKEN_ATTR_NAME&& type != VTDNav.TOKEN_ATTR_NS) throw new ModifyException("token type should be attribute name"); int os1 = md.getTokenOffset(attrNameIndex); int os2 = md.getTokenOffset(attrNameIndex+1); int len2 = md.getTokenLength(attrNameIndex+1); if (encoding < VTDNav.FORMAT_UTF_16BE) removeContent(os1,os2+len2-os1+1); else removeContent(os1<<1,(os2+len2-os1+1)<<1); }