本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.currentTokenType方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.currentTokenType方法的具体用法?Java XmlCursor.currentTokenType怎么用?Java XmlCursor.currentTokenType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.currentTokenType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tokenType
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @return
*/
XmlCursor.TokenType tokenType()
{
XmlCursor.TokenType result;
XmlCursor curs = newCursor();
if (curs.isStartdoc())
{
curs.toFirstContentToken();
}
result = curs.currentTokenType();
curs.dispose();
return result;
}
示例2: remove
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
*/
void remove ()
{
XmlCursor childCurs = newCursor();
if (childCurs.currentTokenType().isStartdoc())
{
// Remove on the document removes all children.
TokenType tt = childCurs.toFirstContentToken();
while (!tt.isEnd() && !tt.isEnddoc())
{
removeToken(childCurs);
tt = childCurs.currentTokenType(); // Now see where we're pointing after the delete -- next token.
}
}
else
{
removeToken(childCurs);
}
childCurs.dispose();
}
示例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: 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;
}
示例5: skipNonElements
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param curs
* @return
*/
private static TokenType skipNonElements (XmlCursor curs)
{
TokenType tt = curs.currentTokenType();
while (tt.isComment() || tt.isProcinst())
{
tt = curs.toNextToken();
}
return tt;
}
示例6: moveSrcToDest
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param srcCurs
* @param destCurs
* @param fDontMoveIfSame
* @return
*/
private boolean moveSrcToDest (XmlCursor srcCurs, XmlCursor destCurs, boolean fDontMoveIfSame)
{
boolean fMovedSomething = true;
TokenType tt;
do
{
if (fDontMoveIfSame && srcCurs.isInSameDocument(destCurs) && (srcCurs.comparePosition(destCurs) == 0))
{
// If the source and destination are pointing at the same place then there's nothing to move.
fMovedSomething = false;
break;
}
// todo ***TLL*** Use replaceContents (when added) and eliminate children removes (see above todo).
if (destCurs.currentTokenType().isStartdoc())
{
destCurs.toNextToken();
}
// todo ***TLL*** Can Eric support notion of copy instead of me copying then moving???
XmlCursor copyCurs = copy(srcCurs);
copyCurs.moveXml(destCurs);
copyCurs.dispose();
tt = srcCurs.currentTokenType();
} while (!tt.isStart() && !tt.isEnd() && !tt.isEnddoc());
return fMovedSomething;
}
示例7: changeNS
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
protected void changeNS (String oldURI, String newURI)
{
XmlCursor curs = newCursor();
while (curs.toParent()) {
/* Goto the top of the document */
}
TokenType tt = curs.currentTokenType();
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isStart())
{
do
{
if (tt.isStart() || tt.isAttr() || tt.isNamespace())
{
javax.xml.namespace.QName currQName = curs.getName();
if (oldURI.equals(currQName.getNamespaceURI()))
{
curs.setName(new javax.xml.namespace.QName(newURI, currQName.getLocalPart()));
}
}
tt = curs.toNextToken();
} while (!tt.isEnddoc() && !tt.isNone());
}
curs.dispose();
}
示例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: copy
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @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())
{
cursToCopy.toNextToken(); // It's not an element it's text so skip it.
}
}
}
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 (!cursToCopy.toNextSibling()) // If element skip element.
{
if (cursToCopy.currentTokenType().isText())
{
cursToCopy.toNextToken(); // It's not an element it's text so skip it.
}
}
}
copyCurs.toStartDoc();
copyCurs.toFirstContentToken();
return copyCurs;
}
示例10: 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();
}
示例11: 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;
}
示例12: matchDescendantAttributes
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @return
*/
private XMLList matchDescendantAttributes(XMLName xmlName)
{
XMLList result = new XMLList(lib);
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
// Set the targets for this XMLList.
result.setTargets(this, null);
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
int nestLevel = 1;
while (nestLevel > 0)
{
tt = curs.toNextToken();
// Only try to match names for attributes
if (tt.isAttr())
{
if (qnameMatches(xmlName, curs.getName()))
{
result.addToList(findAnnotation(curs));
}
}
if (tt.isStart())
{
nestLevel++;
}
else if (tt.isEnd())
{
nestLevel--;
}
else if (tt.isEnddoc())
{
// Shouldn't get here, but just in case.
break;
}
}
}
curs.dispose();
return result;
}
示例13: matchDescendantChildren
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @return
*/
private XMLList matchDescendantChildren(XMLName xmlName)
{
XMLList result = new XMLList(lib);
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
// Set the targets for this XMLList.
result.setTargets(this, null);
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
int nestLevel = 1;
while (nestLevel > 0)
{
tt = curs.toNextToken();
if (!tt.isAttr() && !tt.isEnd() && !tt.isEnddoc())
{
// Only try to match names for elements or processing instructions.
if (!tt.isStart() && !tt.isProcinst())
{
// Not an element or procinst, only add if qname is all
if (xmlName.localName().equals("*"))
{
result.addToList(findAnnotation(curs));
}
}
else
{
if (qnameMatches(xmlName, curs.getName()))
{
result.addToList(findAnnotation(curs));
}
}
}
if (tt.isStart())
{
nestLevel++;
}
else if (tt.isEnd())
{
nestLevel--;
}
else if (tt.isEnddoc())
{
// Shouldn't get here, but just in case.
break;
}
}
}
curs.dispose();
return result;
}
示例14: childIndex
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @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;
}
示例15: normalize
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
*/
void normalize()
{
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
// Walk through the tokens removing empty text nodes and merging adjacent text nodes.
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
int nestLevel = 1;
String previousText = null;
while (nestLevel > 0)
{
tt = curs.toNextToken();
if (tt == XmlCursor.TokenType.TEXT)
{
String currentText = curs.getChars().trim();
if (currentText.trim().length() == 0)
{
// Empty text node, remove.
removeToken(curs);
curs.toPrevToken();
}
else if (previousText == null)
{
// No previous text node, reset to trimmed version
previousText = currentText;
}
else
{
// It appears that this case never happens with XBeans.
// Previous text node exists, concatenate
String newText = previousText + currentText;
curs.toPrevToken();
removeToken(curs);
removeToken(curs);
curs.insertChars(newText);
}
}
else
{
previousText = null;
}
if (tt.isStart())
{
nestLevel++;
}
else if (tt.isEnd())
{
nestLevel--;
}
else if (tt.isEnddoc())
{
// Shouldn't get here, but just in case.
break;
}
}
}
curs.dispose();
}