public String evalString(VTDNavHuge vn){ vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = evalNodeSet(vn); if (a != -1) { if (vn.getTokenType(a) == VTDNavHuge.TOKEN_ATTR_NAME) { a++; } if (vn.getTokenType(a) == VTDNavHuge.TOKEN_STARTING_TAG) { a = vn.getText(); } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); try { if (a != -1) return vn.toString(a); } catch (NavExceptionHuge e) { } return ""; }
VTDNavHuge vn = new VTDNavHuge(rootIndex, encoding, ns, if (getCurrentDepth()>1){ vn.l2index = this.l2index; vn.l2upper = l2upper; vn.l2lower = l2lower; if (getCurrentDepth() > 2) { vn.l3lower = l3lower; vn.l3index = l3index;
/** * <em>New in 2.0</em> * Compare the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets compared against * This method has to take care of the underlying encoding conversion * but it <em> doesn't </em> resolve entity reference in the underlying document * The behavior is the same as calling toRawString on index, then compare to s * @param index * @param s * @return the result of lexical comparison * @exception NavExceptionHuge * */ final public int compareRawTokenString(int index, String s) throws NavExceptionHuge { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // 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), len, s); } /**
/** * Convert a token at the given index to a String, (entities and char references resolved). * 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 NavExceptionHuge */ public String toString(int index) throws NavExceptionHuge { int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) return toRawString(index); int len; //long l; if (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) len = getTokenLength(index) & 0xffff; else len = getTokenLength(index); long offset = getTokenOffset(index); return toString(offset, len); }
/** * Match the string against the token at the given index value. When a token * is an attribute name or starting tag, qualified name is what gets matched against * This method has to take care of the underlying encoding conversion * as well as entity reference comparison * @return boolean * @param index int * @param s java.lang.String * @exception com.ximpleware.extended.NavExceptionHuge When if the underlying byte * content contains various errors. Notice that we are being conservative in making little assumption on * the correctness of underlying byte content. This is because the VTD can be generated by another * machine such as a load-balancer. **/ final public boolean matchTokenString(int index, String s) throws NavExceptionHuge { int type = getTokenType(index); int len = (type == TOKEN_STARTING_TAG || type == TOKEN_ATTR_NAME || type == TOKEN_ATTR_NS) ? getTokenLength(index) & 0xffff : getTokenLength(index); // 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 compareTokenString(getTokenOffset(index), len, s)==0; } /**
int t = getTokenType(index); boolean b = (t==VTDNavHuge.TOKEN_CHARACTER_DATA )|| (t==VTDNavHuge.TOKEN_ATTR_VAL); long offset = getTokenOffset(index); long endOffset = offset + getTokenLength(index); l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32); l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);//skip sign l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);; throw new NumberFormatException("Overflow: " + toString(index)); while (offset <= endOffset && isWS(c)) { l = b? getCharResolved(offset):getChar(offset); c = (int)l; offset += (int)(l>>32);
private String getNameSpaceURI(VTDNavHuge vn){ if (argCount()==0){ try{ int i = vn.getCurrentIndex(); int type = vn.getTokenType(i); int a = vn.lookupNS(); if (a == 0) return ""; else return vn.toString(a); vn.push2(); int size = vn.contextStack2.size; int a = -1; int type = vn.getTokenType(a); if (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME) s= vn.toString(vn.lookupNS()); vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return s;
int c = getCurrentIndex2(); (getTokenLength(c) & 0xffff); // get the length of qualified node int count=0; if (d > 0){ // depth > 0 every node except document and root element int k=getCurrentIndex2()+1; if (k<this.vtdSize){ int type = this.getTokenType(k); if (type==VTDNavHuge.TOKEN_ATTR_NAME || type==VTDNavHuge.TOKEN_ATTR_NS) if (type == VTDNavHuge.TOKEN_ATTR_NS){ int type = this.getTokenType(k); if (type == VTDNavHuge.TOKEN_ATTR_NAME || type == VTDNavHuge.TOKEN_ATTR_NS) { if (matchTokens(fib.intAt(z), this, k)) { unique = false; break; long[] l = getElementFragment();
private String getString(VTDNavHuge vn){ if (argCount()== 0) try{ if (vn.atTerminal){ if (vn.getTokenType(vn.LN) == VTDNavHuge.TOKEN_CDATA_VAL ) return vn.toRawString(vn.LN); return vn.toString(vn.LN); } return vn.toString(vn.getCurrentIndex()); } catch(NavExceptionHuge e){ return ""; // this will almost never occur } else if (argCount() == 1){ return argumentList.e.evalString(vn); } else throw new IllegalArgumentException ("String()'s argument count is invalid"); }
return null; long so = getTokenOffset(getCurrentIndex())-1; BookMarkHuge bmh = new BookMarkHuge(this); bmh.recordCursorPosition(); while(i>1 && toElement(VTDNav.NEXT_SIBLING)){ i--; long[] l= getElementFragment(); long len = l[0]+l[1]-so; if (i==1 && toElement(VTDNav.NEXT_SIBLING)){ }else bmh.setCursorPosition();
long len = l[1]; IByteBuffer xml = vn.getXML(); if (stLen==0){ int enc = vn.getEncoding(); long temp = 0; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; tos = vn.getTokenOffset(fib.intAt(i))<<1; tlen= (vn.getTokenLength(fib.intAt(i)) & 0xffff)<<1; tos = (vn.getTokenOffset(fib.intAt(i)+1)-1)<<1; tlen= ((vn.getTokenLength(fib.intAt(i)+1) & 0xffff)+2)<<1; tos = vn.getTokenOffset(fib.intAt(i)); tlen = (vn.getTokenLength(fib.intAt(i)) & 0xffff); tos = vn.getTokenOffset(fib.intAt(i) + 1) - 1 ; tlen = (vn.getTokenLength(fib.intAt(i) + 1) & 0xffff) + 2;
private String getName(VTDNavHuge vn){ int a; if (argCount()==0){ a = vn.getCurrentIndex(); int type = vn.getTokenType(a); return vn.toString(a); }catch(Exception e){ return ""; return ""; else { int type = vn.getTokenType(a); if (type == VTDNavHuge.TOKEN_STARTING_TAG || type == VTDNavHuge.TOKEN_ATTR_NAME) return vn.toString(a); return "";
while (apFE.evalXPath() != -1) { if (options.returnXMLFragment) { long[] fragment = vn.getElementFragment(); long offset = fragment[0]; long length = fragment[1]; JulieXMLBuffer mb = (JulieXMLBuffer) vn.getXML(); byte[] fragmentBytes = mb.getFragment(offset, length); retList.add(new String(fragmentBytes));
/** * This method matches two VTD tokens of VTDNav objects * @param i1 * @param vn2 * @param i2 * @return boolean true if two tokens are lexically identical * */ final public boolean matchTokens(int i1, VTDNavHuge vn2, int i2) throws NavExceptionHuge{ return compareTokens(i1,vn2,i2)==0; }
private long getChar4OtherEncoding(long offset) throws NavExceptionHuge{ if (encoding <= FORMAT_WIN_1258){ int temp = decode(offset); if (temp == '\r') { if (XMLDoc.byteAt(offset + 1) == '\n') { return '\n'|(2L<<32); } else { return '\n'|(1L<<32); } } return temp|(1L<<32); } throw new NavExceptionHuge("Unknown Encoding"); } /**
private boolean compareVString2(int k, VTDNavHuge vn, String s, int op) throws NavExceptionHuge { int i = vn.compareTokenString(k, s); switch(i){ case -1: if (op== NE || op == GT || op == GE){ return true; } break; case 0: if (op==EQ || op == LE || op == GE ){ return true; } break; case 1: if (op == NE || op==LE || op == LT ){ return true; } } return false; }
/** * Duplicate the VTDNavHuge instance with shared XML, VTD and LC buffers * This method may be useful for parallel XPath evaluation * The node Position is at root element * @return a VTDNavHuge instance * */ final public VTDNavHuge duplicateNav(){ return new VTDNavHuge(rootIndex, encoding, ns, nestingLevel-1, XMLDoc, vtdBuffer, l1Buffer, l2Buffer, l3Buffer, docOffset, docLen ); } /**
import com.ximpleware.extended.*; public class mem_mapped_read { public static void main(String[] s) throws Exception{ VTDGenHuge vg = new VTDGenHuge(); if (vg.parseFile("test.xml",true,VTDGenHuge.MEM_MAPPED)){ VTDNavHuge vnh = vg.getNav(); AutoPilotHuge aph = new AutoPilotHuge(vnh); aph.selectXPath("//*"); int i = 0; while ((i=aph.evalXPath())!=-1){ System.out.println(" element name is "+vnh.toString(i)); } } } }
final private boolean matchRawTokenString(long offset, int len, String s) throws NavExceptionHuge{ return compareRawTokenString(offset, len, s)==0; }
private boolean contains(VTDNavHuge vn){ String s2 = argumentList.next.e.evalString(vn); if (argumentList.e.isNodeSet()){ int a = evalFirstArgumentListNodeSet(vn); if (a==-1) return false; try { return vn.contains(a, s2); }catch (Exception e){ return false; } } String s1 = argumentList.e.evalString(vn); //return s1.contains(s2); return s1.indexOf(s2)!=-1; //return (s1.i)) }