/** * <p> * Helper method to determine whether the current token index still lies * within the element this parser has been called for. Since VTD-XML does * unfortunately not use its VTDNav.TOKEN_ENDING_TAG token type, we have to * infer from token type and token depth whether we have left the element or * not. * </p> * <p> * When an XML element ends, the next token may be another starting tag with * the same depth as the original element (a sibling in the XML tree) or * something else, e.g. text data, with a lower depth belonging to the * parent element. Those two cases are checked in this method. * </p> * * @param index * The token index to check. * @param elementDepth * The depth of the original element this parser is handling. * @return True, if the token with the given index belongs to the element * for this parser. */ protected boolean tokenIndexBelongsToElement(int index, int elementDepth) { return !((vn.getTokenType(index) == VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(index) <= elementDepth) || vn.getTokenDepth(index) < elementDepth); }
private int handleDefault(){ //int curDepth = vn.context[0]; int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (d >= depth && !(d == depth && type == VTDNav.TOKEN_STARTING_TAG)) { if (isText(sp) == true && d == depth) { prevLocation = sp; return sp; } sp++; if(sp >= vn.vtdSize) return -1; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } return -1; }
private int handleDefault(){ //int curDepth = vn.context[0]; int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (d >= depth && !(d == depth && type == VTDNav.TOKEN_STARTING_TAG)) { if (isText(sp) == true && d == depth) { prevLocation = sp; return sp; } sp++; if(sp >= vn.vtdSize) return -1; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } return -1; }
private int handleDefault(){ //int curDepth = vn.context[0]; int sp = (prevLocation != -1) ? increment(prevLocation): index + 1; if (sp>=vn.vtdSize) return -1; int d = vn.getTokenDepth(sp); int type = vn.getTokenType(sp); while (d >= depth && !(d == depth && type == VTDNav.TOKEN_STARTING_TAG)) { if (isText(sp) == true && d == depth) { prevLocation = sp; return sp; } sp++; if(sp >= vn.vtdSize) return -1; d = vn.getTokenDepth(sp); type = vn.getTokenType(sp); } return -1; }
public static String getElementText(VTDNav vn) throws NavException { StringBuilder sb = new StringBuilder(); int depth = vn.getCurrentDepth(); int i = vn.getCurrentIndex(); while (vn.getTokenType(i) == VTDNav.TOKEN_STARTING_TAG) i++; while (vn.getTokenDepth(i) >= depth && !(vn.getTokenType(i) == VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(i) == depth) && i < vn.getTokenCount()) { if (vn.getTokenType(i) == VTDNav.TOKEN_CHARACTER_DATA || vn.getTokenType(i) == VTDNav.TOKEN_CDATA_VAL) sb.append(vn.toString(i)); i++; } return sb.toString(); }
case TOKEN_STARTING_TAG: case TOKEN_DOCUMENT: int depth = getTokenDepth(index); context[0] = depth; if (depth > 0) case TOKEN_COMMENT: case TOKEN_PI_NAME: depth = getTokenDepth(index);
case TOKEN_STARTING_TAG: case TOKEN_DOCUMENT: int depth = getTokenDepth(index); context[0] = depth; if (depth > 0) case TOKEN_COMMENT: case TOKEN_PI_NAME: depth = getTokenDepth(index);
while(vn.getTokenDepth(sp)==-1){ sp--;
while(vn.getTokenDepth(sp)==-1){ sp--;
while(vn.getTokenDepth(sp)==-1){ sp--;
private int increment(int sp){ int type = vn.getTokenType(sp); int vtdSize = vn.vtdBuffer.size; int i=sp+1; while(i<vtdSize && depth == vn.getTokenDepth(i) && type == vn.getTokenType(i)&& (vn.getTokenOffset(i-1)+ (int)((vn.vtdBuffer.longAt(i-1) & VTDNav.MASK_TOKEN_FULL_LEN)>>32) == vn.getTokenOffset(i)) ){ i++; } return i; }
private int increment(int sp){ int type = vn.getTokenType(sp); int vtdSize = vn.vtdBuffer.size; int i=sp+1; while(i<vtdSize && depth == vn.getTokenDepth(i) && type == vn.getTokenType(i)&& (vn.getTokenOffset(i-1)+ (int)((vn.vtdBuffer.longAt(i-1) & VTDNav.MASK_TOKEN_FULL_LEN)>>32) == vn.getTokenOffset(i)) ){ i++; } return i; }
private int increment(int sp){ int type = vn.getTokenType(sp); int vtdSize = vn.vtdBuffer.size; int i=sp+1; while(i<vtdSize && depth == vn.getTokenDepth(i) && type == vn.getTokenType(i)&& (vn.getTokenOffset(i-1)+ (int)((vn.vtdBuffer.longAt(i-1) & VTDNav.MASK_TOKEN_FULL_LEN)>>32) == vn.getTokenOffset(i)) ){ i++; } return i; }
depth = getTokenDepth(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){
depth = getTokenDepth(index); if (depth<dp || (depth==dp && tokenType==VTDNav.TOKEN_STARTING_TAG)){
XmlUtil.toIndentedString(xml, indentationSize, nav.getTokenDepth(textPos), pretty); String prettyXml = pretty.toString().substring(indentationSize * nav.getTokenDepth(textPos));
int depth = getTokenDepth(index); context[0] = depth; if (depth > 0)
int depth = getTokenDepth(index); context[0] = depth; if (depth > 0)
int depth = getTokenDepth(index); context[0] = depth; if (depth > 0)
public final ElementParsingResult parse() throws ElementParsingException { try { beforeParseElement(); checkCursorPosition(); int elementDepth = vn.getTokenDepth(vn.getCurrentIndex()); int startElementIndex = vn.getCurrentIndex(); ElementParsingResult elementParsingResult = createParsingResult(); parseElement(elementParsingResult); if (vn.getCurrentIndex() < startElementIndex) vn.recoverNode(startElementIndex); if (vn.getTokenType(vn.getCurrentIndex()) != VTDNav.TOKEN_STARTING_TAG) { vn.toElement(VTDNav.PARENT); if (getElementEnd() > elementParsingResult.getEnd()) throw new IllegalStateException("Parsed element \"" + elementName + "\" ends at byte " + elementParsingResult.getEnd() + " but VTDNav was positioned after parsing within an element which ends at " + getElementEnd() + ". Each element parser must finish within its element or at a starting tag immediately following the parser's element closing tag."); } int index = findIndexAfterElement(elementDepth, vn.getCurrentIndex()); elementParsingResult.setLastTokenIndex(index); afterParseElement(); return elementParsingResult; } catch (NavException e) { throw new ElementParsingException(e); } }