/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s before the element * @param s * */ public void insertBeforeElement(String s) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,s.getBytes(charSet)); else insertBytesAt((offset)<<1,s.getBytes(charSet)); }
/** * This method will insert byte content of string right before the tail of cursor element, * @param s * @throws ModifyException * @throws NavException */ public void insertBeforeTail(String s) throws ModifyException,UnsupportedEncodingException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(s.getBytes(charSet)); return; } insertBytesAt((int)i,s.getBytes()); } /**
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s before the element * @param s * */ public void insertBeforeElement(String s) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,s.getBytes(charSet)); else insertBytesAt((offset)<<1,s.getBytes(charSet)); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s before the element * @param s * */ public void insertBeforeElement(String s) throws ModifyException,UnsupportedEncodingException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,s.getBytes(charSet)); else insertBytesAt((offset)<<1,s.getBytes(charSet)); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte array b before the element * @param b the byte array to be inserted into the master document * @throws ModifyException * */ public void insertBeforeElement(byte[] b) throws ModifyException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); int offset = md.getTokenOffset(startTagIndex)-1; if (encoding < VTDNav.FORMAT_UTF_16BE) insertBytesAt(offset,b); else insertBytesAt((offset)<<1,b); }
/** * This method will insert a segment of the byte array before the tail of cursor element, * l1 (a long)'s upper 32 bit is length, lower 32 bit is offset * @param b * @param l * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); insertAfterHead(b,l); return; } insertBytesAt((int)i,b,l); } /**
/** * This method will insert s' byte array representation * of the string after the head of cursor element, * @param s * @return * @throws ModifyException * @throws NavException * @throws TranscodeException * */ public void insertAfterHead(String s) throws ModifyException, UnsupportedEncodingException, NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,s.getBytes(charSet)); insertEndingTag(i); return; } insertBytesAt((int)i,s.getBytes(charSet)); }
/** * This method will insert byte array b right before the tail of cursor element, * @param b * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b) throws ModifyException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(b); return; } insertBytesAt((int)i,b); } /**
/** * This method will insert byte array b right before the tail of cursor element, * @param b * @throws ModifyException * @throws NavException */ public void insertBeforeTail(byte[] b) throws ModifyException,NavException { long i = md.getOffsetBeforeTail(); if (i<0){ //throw new ModifyException("Insertion failed"); // handle empty element case // <a/> would become <a>b's content</a> // so there are two insertions there insertAfterHead(b); return; } insertBytesAt((int)i,b); } /**
/** * * @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); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s after the element * @param s the string whose byte content will be inserted into the master document * */ public void insertAfterElement(String s) throws ModifyException,UnsupportedEncodingException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,s.getBytes(charSet)); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s after the element * @param s the string whose byte content will be inserted into the master document * */ public void insertAfterElement(String s) throws ModifyException,UnsupportedEncodingException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,s.getBytes(charSet)); }
/** * This method will insert a segment of the byte array b after the head of cursor element * @param b * @param l * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,b, (int)l,(int)(l<<32)); insertEndingTag(i); return; } insertBytesAt((int)i,b,l); }
/** * This method will insert a segment of the byte array b after the head of cursor element * @param b * @param l * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b, long l) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,b, (int)l,(int)(l<<32)); insertEndingTag(i); return; } insertBytesAt((int)i,b,l); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte value of s after the element * @param s the string whose byte content will be inserted into the master document * */ public void insertAfterElement(String s) throws ModifyException,UnsupportedEncodingException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,s.getBytes(charSet)); }
/** * This method will insert a segment of the byte array b after the head of cursor element, * @param b * @param offset * @param len * @throws ModifyException * @throws NavException * */ public void insertAfterHead(byte[] b, int offset, int len) throws ModifyException,NavException{ long i = md.getOffsetAfterHead(); if (i<0){ //throw new ModifyException("Insertion failed"); insertBytesEnclosedAt((int)i-1,b, offset,len ); insertEndingTag(i); return; } insertBytesAt((int)i,b,offset, len); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert the byte array b after the element * @param b * @throws ModifyException * @throws NavException * */ public void insertAfterElement(byte[] b) throws ModifyException,NavException{ int startTagIndex =md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type!=VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int)l; int len = (int)(l>>32); insertBytesAt(offset+len,b); }
/** * This method will first call getCurrentIndex() to get the cursor index value * then insert a segment of the byte array b after the element * @param b * @param contentOffset * @param contentLen * @throws ModifyException * @throws NavException * */ public void insertAfterElement(byte[] b, int contentOffset, int contentLen) throws ModifyException, NavException { int startTagIndex = md.getCurrentIndex(); int type = md.getTokenType(startTagIndex); if (type != VTDNav.TOKEN_STARTING_TAG) throw new ModifyException("Token type is not a starting tag"); long l = md.getElementFragment(); int offset = (int) l; int len = (int) (l >> 32); insertBytesAt(offset + len, b, contentOffset, contentLen); }