本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.toEndToken方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.toEndToken方法的具体用法?Java XmlCursor.toEndToken怎么用?Java XmlCursor.toEndToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.toEndToken方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendChild
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param xml
* @return
*/
XML appendChild(Object xml)
{
XmlCursor curs = newCursor();
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
// Move the cursor to the end of this element
if (curs.isStart())
{
curs.toEndToken();
}
insertChild(curs, xml);
curs.dispose();
return this;
}
示例2: addSection
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public XmlObjectBuilder addSection(String sectionName, XmlObject section){
cursor.beginElement(sectionName);
cursor.push();
XmlCursor srcCursor = section.newCursor();
srcCursor.toNextToken();
while(srcCursor.currentTokenType() != XmlCursor.TokenType.NONE && srcCursor.currentTokenType() != XmlCursor.TokenType.ENDDOC){
srcCursor.copyXml(cursor);
if(srcCursor.currentTokenType() == XmlCursor.TokenType.START) srcCursor.toEndToken();
srcCursor.toNextToken();
}
cursor.pop();
cursor.toEndToken();
cursor.toNextToken();
srcCursor.dispose();
return this;
}
示例3: addSection
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public XmlObjectBuilder addSection(String sectionName, XmlObject section) {
cursor.beginElement(sectionName);
cursor.push();
XmlCursor srcCursor = section.newCursor();
srcCursor.toNextToken();
while (srcCursor.currentTokenType() != XmlCursor.TokenType.NONE
&& srcCursor.currentTokenType() != XmlCursor.TokenType.ENDDOC) {
srcCursor.copyXml(cursor);
if (srcCursor.currentTokenType() == XmlCursor.TokenType.START)
srcCursor.toEndToken();
srcCursor.toNextToken();
}
cursor.pop();
cursor.toEndToken();
cursor.toNextToken();
srcCursor.dispose();
return this;
}
示例4: getOrCreateHPCProfileApplication
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public static HPCProfileApplicationType getOrCreateHPCProfileApplication(JobDefinitionType value) {
ApplicationType application = getOrCreateApplication(value);
if(getPOSIXApplication(value) != null){
//TODO handle: creating HPC element if POSIX already exists
return getHPCProfileApplication(value);
}
if (getHPCProfileApplication(value) == null) {
XmlCursor acursor = application.newCursor();
acursor.toEndToken();
acursor.insertElement(HPC_PROFILE_APPLICATION);
acursor.dispose();
}
return getHPCProfileApplication(value);
}
示例5: getOrCreatePOSIXApplication
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public static POSIXApplicationType getOrCreatePOSIXApplication(JobDefinitionType value) {
ApplicationType application = getOrCreateApplication(value);
if(getHPCProfileApplication(value) != null){
//TODO handle: not creating POSIX element if HPCProfile already exists
return getPOSIXApplication(value);
}
if (getPOSIXApplication(value) == null) {
XmlCursor acursor = application.newCursor();
acursor.toEndToken();
acursor.insertElement(POSIX_APPLICATION);
acursor.dispose();
}
return getPOSIXApplication(value);
}
示例6: replace
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param destCurs
* @param newValue
*/
private void replace(XmlCursor destCurs, XML newValue)
{
if (destCurs.isStartdoc())
{
// Can't overwrite a whole document (user really wants to overwrite the contents of).
destCurs.toFirstContentToken();
}
// Orphan the token -- don't delete it outright on the XmlCursor.
removeToken(destCurs);
XmlCursor srcCurs = newValue.newCursor();
if (srcCurs.currentTokenType().isStartdoc())
{
// Cann't append a whole document (user really wants to append the contents of).
srcCurs.toFirstContentToken();
}
moveSrcToDest(srcCurs, destCurs, false);
// Re-link a new annotation to this cursor -- we just deleted the previous annotation on entrance to replace.
if (!destCurs.toPrevSibling())
{
destCurs.toPrevToken();
}
destCurs.setBookmark(new XScriptAnnotation(destCurs));
// todo would be nice if destCurs.toNextSibling went to where the next token if the cursor was pointing at the last token in the stream.
destCurs.toEndToken();
destCurs.toNextToken();
srcCurs.dispose();
}
示例7: getOrCreateSPMDApplication
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public static SPMDApplicationType getOrCreateSPMDApplication(JobDefinitionType value) {
ApplicationType application = getOrCreateApplication(value);
if (getSPMDApplication(value) == null) {
XmlCursor acursor = application.newCursor();
acursor.toEndToken();
acursor.insertElement(SPMD_APPLICATION);
acursor.dispose();
}
return getSPMDApplication(value);
}
示例8: moveToChild
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private boolean moveToChild(XmlCursor curs, long index, boolean fFirstChild, boolean fUseStartDoc)
{
if (index < 0)
throw new IllegalArgumentException();
long idxChild = 0;
if (!fUseStartDoc && curs.currentTokenType().isStartdoc())
{
// We always move to the children of the top node.
// todo: This assumes that we want have multiple top-level nodes. Which we should be able tohave.
curs.toFirstContentToken();
}
TokenType tt = curs.toFirstContentToken();
if (!tt.isNone() && !tt.isEnd())
{
while (true)
{
if (index == idxChild)
{
return true;
}
tt = curs.currentTokenType();
if (tt.isText())
{
curs.toNextToken();
}
else if (tt.isStart())
{
// Need to do this we want to be pointing at the text if that after the end token.
curs.toEndToken();
curs.toNextToken();
}
else if (tt.isComment() || tt.isProcinst())
{
continue;
}
else
{
break;
}
idxChild++;
}
}
else if (fFirstChild && index == 0)
{
// Drill into where first child would be.
// curs.toFirstContentToken();
return true;
}
return false;
}
示例9: insertChild
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param childToMatch
* @param xmlToInsert
* @param addToType
*/
private void insertChild(XML childToMatch, Object xmlToInsert, int addToType)
{
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
XmlCursor xmlChildCursor = childToMatch.newCursor();
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
tt = curs.toNextToken();
while (!tt.isEnd())
{
if (tt.isStart())
{
// See if this child is the same as the one thep passed in
if (curs.comparePosition(xmlChildCursor) == 0)
{
// Found it
if (addToType == APPEND_CHILD)
{
// Move the cursor to just past the end of this element
curs.toEndToken();
curs.toNextToken();
}
insertChild(curs, xmlToInsert);
break;
}
}
// Skip over child elements
if (tt.isStart())
{
tt = curs.toEndToken();
}
tt = curs.toNextToken();
}
}
xmlChildCursor.dispose();
curs.dispose();
}
示例10: allChildNodes
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param namespace
* @return
*/
private XMLList allChildNodes(String namespace)
{
XMLList result = new XMLList(lib);
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
javax.xml.namespace.QName targetProperty = new javax.xml.namespace.QName(namespace, "*");
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
tt = curs.toFirstContentToken();
while (!tt.isEnd())
{
if (!tt.isStart())
{
// Not an element
result.addToList(findAnnotation(curs));
// Reset target property to null in this case
targetProperty = null;
}
else
{
// Match namespace as well if specified
if (namespace == null ||
namespace.length() == 0 ||
namespace.equals("*") ||
curs.getName().getNamespaceURI().equals(namespace))
{
// Add it to the list
result.addToList(findAnnotation(curs));
// Set target property if target name is "*",
// Otherwise if target property does not match current, then
// set to null
if (targetProperty != null)
{
if (targetProperty.getLocalPart().equals("*"))
{
targetProperty = curs.getName();
}
else if (!targetProperty.getLocalPart().equals(curs.getName().getLocalPart()))
{
// Not a match, unset target property
targetProperty = null;
}
}
}
}
// Skip over child elements
if (tt.isStart())
{
tt = curs.toEndToken();
}
tt = curs.toNextToken();
}
}
curs.dispose();
// Set the targets for this XMLList.
result.setTargets(this, targetProperty);
return result;
}
示例11: insertNewTable
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* 在某个段落起始处插入表格
*
* @param run
* @param row
* @param col
* @return
*/
public XWPFTable insertNewTable(XWPFRun run, int row, int col) {
XmlCursor cursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
// XmlCursor cursor = run.getCTR().newCursor();
if (isCursorInBody(cursor)) {
String uri = CTTbl.type.getName().getNamespaceURI();
String localPart = "tbl";
cursor.beginElement(localPart, uri);
cursor.toParent();
CTTbl t = (CTTbl) cursor.getObject();
XWPFTable newT = new XWPFTable(t, this, row, col);
XmlObject o = null;
while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
o = cursor.getObject();
}
if (!(o instanceof CTTbl)) {
tables.add(0, newT);
} else {
int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
tables.add(pos, newT);
}
int i = 0;
XmlCursor tableCursor = t.newCursor();
try {
cursor.toCursor(tableCursor);
while (cursor.toPrevSibling()) {
o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl){
i++;
}
}
bodyElements.add(i > bodyElements.size() ? bodyElements.size() : i, newT);
// bodyElements.add(i, newT);
cursor.toCursor(tableCursor);
cursor.toEndToken();
return newT;
} finally {
tableCursor.dispose();
}
}
return null;
}
示例12: insertNewParagraph
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* 在某个段落起始处插入段落
* @param run
* @return
*/
public XWPFParagraph insertNewParagraph(XWPFRun run) {
// XmlCursor cursor = run.getCTR().newCursor();
XmlCursor cursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
if (isCursorInBody(cursor)) {
String uri = CTP.type.getName().getNamespaceURI();
/*
* TODO DO not use a coded constant, find the constant in the OOXML
* classes instead, as the child of type CT_Paragraph is defined in the
* OOXML schema as 'p'
*/
String localPart = "p";
// creates a new Paragraph, cursor is positioned inside the new
// element
cursor.beginElement(localPart, uri);
// move the cursor to the START token to the paragraph just created
cursor.toParent();
CTP p = (CTP) cursor.getObject();
XWPFParagraph newP = new XWPFParagraph(p, this);
XmlObject o = null;
/*
* move the cursor to the previous element until a) the next
* paragraph is found or b) all elements have been passed
*/
while (!(o instanceof CTP) && (cursor.toPrevSibling())) {
o = cursor.getObject();
}
/*
* if the object that has been found is a) not a paragraph or b) is
* the paragraph that has just been inserted, as the cursor in the
* while loop above was not moved as there were no other siblings,
* then the paragraph that was just inserted is the first paragraph
* in the body. Otherwise, take the previous paragraph and calculate
* the new index for the new paragraph.
*/
if ((!(o instanceof CTP)) || (CTP) o == p) {
paragraphs.add(0, newP);
} else {
int pos = paragraphs.indexOf(getParagraph((CTP) o)) + 1;
paragraphs.add(pos, newP);
}
/*
* create a new cursor, that points to the START token of the just
* inserted paragraph
*/
XmlCursor newParaPos = p.newCursor();
try {
/*
* Calculate the paragraphs index in the list of all body
* elements
*/
int i = 0;
cursor.toCursor(newParaPos);
while (cursor.toPrevSibling()) {
o = cursor.getObject();
if (o instanceof CTP || o instanceof CTTbl)
i++;
}
bodyElements.add(i, newP);
cursor.toCursor(newParaPos);
cursor.toEndToken();
return newP;
} finally {
newParaPos.dispose();
}
}
return null;
}