use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method removeToken.
/**
*
* @param curs
*/
protected void removeToken(XmlCursor curs) {
XmlObject xo = XmlObject.Factory.newInstance();
// Don't delete anything move to another document so it gets orphaned nicely.
XmlCursor tmpCurs = xo.newCursor();
tmpCurs.toFirstContentToken();
curs.moveXml(tmpCurs);
tmpCurs.dispose();
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method childIndex.
/**
*
* @return
*/
int childIndex() {
int index = 0;
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
while (true) {
if (tt.isText()) {
index++;
if (!curs.toPrevSibling()) {
break;
}
} else if (tt.isStart()) {
tt = curs.toPrevToken();
if (tt.isEnd()) {
curs.toNextToken();
if (!curs.toPrevSibling()) {
break;
}
index++;
} else {
// Hit the parent start tag so get out we're down counting children.
break;
}
} else if (tt.isComment() || tt.isProcinst()) {
curs.toPrevToken();
} else {
break;
}
tt = curs.currentTokenType();
}
index = curs.currentTokenType().isStartdoc() ? -1 : index;
curs.dispose();
return index;
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method prependChild.
/**
*
* @param xml
* @return
*/
XML prependChild(Object xml) {
XmlCursor curs = newCursor();
if (curs.isStartdoc()) {
curs.toFirstContentToken();
}
// Move the cursor to the first content token
curs.toFirstContentToken();
insertChild(curs, xml);
curs.dispose();
return this;
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method copy.
/**
*
* @return
*/
Object copy() {
XmlCursor srcCurs = newCursor();
if (srcCurs.isStartdoc()) {
srcCurs.toFirstContentToken();
}
XML xml = createEmptyXML(lib);
XmlCursor destCurs = xml.newCursor();
destCurs.toFirstContentToken();
srcCurs.copyXml(destCurs);
destCurs.dispose();
srcCurs.dispose();
return xml;
}
use of org.apache.xmlbeans.XmlCursor in project hackpad by dropbox.
the class XML method copy.
/**
*
* @param cursToCopy
* @return
*/
private XmlCursor copy(XmlCursor cursToCopy) {
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor copyCurs = null;
if (cursToCopy.currentTokenType().isText()) {
try {
// Try just as a textnode, to do that we need to wrap the text in a special fragment tag
// that is not visible from the XmlCursor.
copyCurs = XmlObject.Factory.parse("<x:fragment xmlns:x=\"http://www.openuri.org/fragment\">" + cursToCopy.getChars() + "</x:fragment>").newCursor();
if (!cursToCopy.toNextSibling()) {
if (cursToCopy.currentTokenType().isText()) {
// It's not an element it's text so skip it.
cursToCopy.toNextToken();
}
}
} catch (Exception ex) {
throw ScriptRuntime.typeError(ex.getMessage());
}
} else {
copyCurs = xo.newCursor();
copyCurs.toFirstContentToken();
if (cursToCopy.currentTokenType() == XmlCursor.TokenType.STARTDOC) {
cursToCopy.toNextToken();
}
cursToCopy.copyXml(copyCurs);
if (// If element skip element.
!cursToCopy.toNextSibling()) {
if (cursToCopy.currentTokenType().isText()) {
// It's not an element it's text so skip it.
cursToCopy.toNextToken();
}
}
}
copyCurs.toStartDoc();
copyCurs.toFirstContentToken();
return copyCurs;
}
Aggregations