本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.insertChars方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.insertChars方法的具体用法?Java XmlCursor.insertChars怎么用?Java XmlCursor.insertChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.insertChars方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTextElement
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param qname
* @param value
* @return
*/
static XML createTextElement(XMLLibImpl lib, javax.xml.namespace.QName qname, String value)
{
XScriptAnnotation anno;
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor cursor = xo.newCursor();
try {
cursor.toNextToken();
cursor.beginElement(qname.getLocalPart(), qname.getNamespaceURI());
//if(namespace.length() > 0)
// cursor.insertNamespace("", namespace);
cursor.insertChars(value);
cursor.toStartDoc();
cursor.toNextToken();
anno = new XScriptAnnotation(cursor);
cursor.setBookmark(anno);
} finally {
cursor.dispose();
}
return new XML(lib, anno);
}
示例2: escapeTextValue
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Escapes the reserved characters in a value of a text node
*
* @param value Unescaped text
* @return The escaped text
*/
public String escapeTextValue(Object value)
{
if (value instanceof XMLObjectImpl) {
return ((XMLObjectImpl)value).toXMLString(0);
}
String text = ScriptRuntime.toString(value);
if (text.length() == 0) return text;
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor cursor = xo.newCursor();
cursor.toNextToken();
cursor.beginElement("a");
cursor.insertChars(text);
cursor.dispose();
String elementText = xo.toString();
int begin = elementText.indexOf('>') + 1;
int end = elementText.lastIndexOf('<');
return (begin < end) ? elementText.substring(begin, end) : "";
}
示例3: processSimpleType
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processSimpleType( SchemaType stype, XmlCursor xmlc )
{
if( _soapEnc )
{
QName typeName = stype.getName();
if( typeName != null )
{
xmlc.insertAttributeWithValue( XSI_TYPE, formatQName( xmlc, typeName ) );
}
}
String sample = sampleDataForSimpleType( stype );
xmlc.insertChars( sample );
}
示例4: processElement
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processElement( SchemaParticle sp, XmlCursor xmlc, boolean mixed )
{
// cast as schema local element
SchemaLocalElement element = ( SchemaLocalElement )sp;
// Add comment about type
addElementTypeAndRestricionsComment( element, xmlc );
// / ^ -> <elemenname></elem>^
if( _soapEnc )
xmlc.insertElement( element.getName().getLocalPart() ); // soap
// encoded?
// drop
// namespaces.
else
xmlc.insertElement( element.getName().getLocalPart(), element.getName().getNamespaceURI() );
// / -> <elem>^</elem>
// processAttributes( sp.getType(), xmlc );
xmlc.toPrevToken();
// -> <elem>stuff^</elem>
String[] values = null;
if( multiValues != null )
values = multiValues.get( element.getName() );
if( values != null )
xmlc.insertChars( StringUtils.join( values, "," ) );
else if( sp.isDefault() )
xmlc.insertChars( sp.getDefaultText() );
else
createSampleForType( element.getType(), xmlc );
// -> <elem>stuff</elem>^
xmlc.toNextToken();
}
示例5: processSequence
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processSequence( SchemaParticle sp, XmlCursor xmlc, boolean mixed )
{
SchemaParticle[] spc = sp.getParticleChildren();
for( int i = 0; i < spc.length; i++ )
{
// / <parent>maybestuff^</parent>
processParticle( spc[i], xmlc, mixed );
// <parent>maybestuff...morestuff^</parent>
if( mixed && i < spc.length - 1 )
xmlc.insertChars( pick( WORDS ) );
}
}
示例6: processAll
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processAll( SchemaParticle sp, XmlCursor xmlc, boolean mixed )
{
SchemaParticle[] spc = sp.getParticleChildren();
if( !_skipComments )
xmlc.insertComment( "You may enter the following " + String.valueOf( spc.length ) + " items in any order" );
for( int i = 0; i < spc.length; i++ )
{
processParticle( spc[i], xmlc, mixed );
if( mixed && i < spc.length - 1 )
xmlc.insertChars( pick( WORDS ) );
}
}
示例7: processSimpleType
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processSimpleType(SchemaType stype, XmlCursor xmlc, Map<String, String> mapValues)
{
String sample = sampleDataForSimpleType(stype);
if(_bIsAttrib)
{
String itemName = "";
String itemValue = "";
StringBuffer strBuffer = new StringBuffer();
StringBuffer strBufferAll = new StringBuffer();
int lastIndexof = sample.lastIndexOf("}");
if(lastIndexof != -1)
{
Iterator<String> iters = mapValues.keySet().iterator();
while(iters.hasNext())
{
itemName = iters.next();
itemValue = mapValues.get(itemName);
strBuffer.append(", '").append(itemName).append("':'").append(itemValue).append("'");
}
strBufferAll.append(sample.substring(0, lastIndexof)).append(strBuffer.toString()).append("}");
} else {
strBufferAll.append("{").append(sample).append(strBuffer.toString()).append("}");
}
sample = strBufferAll.toString();
}
xmlc.insertChars(sample);
}
示例8: processSequence
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processSequence(SchemaParticle sp, XmlCursor xmlc, boolean mixed)
{
SchemaParticle[] spc = sp.getParticleChildren();
for (int i=0; i < spc.length; i++)
{
/// <parent>maybestuff^</parent>
processParticle(spc[i], xmlc, mixed);
//<parent>maybestuff...morestuff^</parent>
if (mixed && i < spc.length-1)
xmlc.insertChars(pick(WORDS));
}
}
示例9: processAll
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
private void processAll(SchemaParticle sp, XmlCursor xmlc, boolean mixed)
{
SchemaParticle[] spc = sp.getParticleChildren();
// xmlc.insertComment("You may enter the following " + String.valueOf(spc.length) + " items in any order");
for (int i=0; i < spc.length; i++)
{
processParticle(spc[i], xmlc, mixed);
if (mixed && i < spc.length-1)
xmlc.insertChars(pick(WORDS));
}
}
示例10: createSampleForType
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Cursor position Before: <theElement>^</theElement> After:
* <theElement><lots of stuff/>^</theElement>
*/
public void createSampleForType( SchemaType stype, XmlCursor xmlc )
{
_exampleContent = SoapUI.getSettings().getBoolean( WsdlSettings.XML_GENERATION_TYPE_EXAMPLE_VALUE );
_typeComment = SoapUI.getSettings().getBoolean( WsdlSettings.XML_GENERATION_TYPE_COMMENT_TYPE );
_skipComments = SoapUI.getSettings().getBoolean( WsdlSettings.XML_GENERATION_SKIP_COMMENTS );
QName nm = stype.getName();
if( nm == null && stype.getContainerField() != null )
nm = stype.getContainerField().getName();
if( nm != null && excludedTypes.contains( nm ) )
{
if( !_skipComments )
xmlc.insertComment( "Ignoring type [" + nm + "]" );
return;
}
if( _typeStack.contains( stype ) )
return;
_typeStack.add( stype );
try
{
if( stype.isSimpleType() || stype.isURType() )
{
processSimpleType( stype, xmlc );
return;
}
// complex Type
// <theElement>^</theElement>
processAttributes( stype, xmlc );
// <theElement attri1="string">^</theElement>
switch( stype.getContentType() )
{
case SchemaType.NOT_COMPLEX_TYPE :
case SchemaType.EMPTY_CONTENT :
// noop
break;
case SchemaType.SIMPLE_CONTENT :
{
processSimpleType( stype, xmlc );
}
break;
case SchemaType.MIXED_CONTENT :
xmlc.insertChars( pick( WORDS ) + " " );
if( stype.getContentModel() != null )
{
processParticle( stype.getContentModel(), xmlc, true );
}
xmlc.insertChars( pick( WORDS ) );
break;
case SchemaType.ELEMENT_CONTENT :
if( stype.getContentModel() != null )
{
processParticle( stype.getContentModel(), xmlc, false );
}
break;
}
}
finally
{
_typeStack.remove( _typeStack.size() - 1 );
}
}
示例11: insertChild
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param curs
* @param xmlToInsert
*/
private void insertChild(XmlCursor curs, Object xmlToInsert)
{
if (xmlToInsert == null || xmlToInsert instanceof Undefined)
{
// Do nothing
}
else if (xmlToInsert instanceof XmlCursor)
{
moveSrcToDest((XmlCursor)xmlToInsert, curs, true);
}
else if (xmlToInsert instanceof XML)
{
XML xmlValue = (XML) xmlToInsert;
// If it's an attribute, then change to text node
if (xmlValue.tokenType() == XmlCursor.TokenType.ATTR)
{
insertChild(curs, xmlValue.toString());
}
else
{
XmlCursor cursToInsert = ((XML) xmlToInsert).newCursor();
moveSrcToDest(cursToInsert, curs, true);
cursToInsert.dispose();
}
}
else if (xmlToInsert instanceof XMLList)
{
XMLList list = (XMLList) xmlToInsert;
for (int i = 0; i < list.length(); i++)
{
insertChild(curs, list.item(i));
}
}
else
{
// Convert to string and make XML out of it
String xmlStr = ScriptRuntime.toString(xmlToInsert);
XmlObject xo = XmlObject.Factory.newInstance(); // Create an empty document.
XmlCursor sourceCurs = xo.newCursor();
sourceCurs.toNextToken();
// To hold the text.
sourceCurs.insertChars(xmlStr);
sourceCurs.toPrevToken();
// Call us again with the cursor.
moveSrcToDest(sourceCurs, curs, true);
}
}
示例12: 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();
}
示例13: createSampleForType
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
* Cursor position
* Before:
* <theElement>^</theElement>
* After:
* <theElement><lots of stuff/>^</theElement>
*/
private void createSampleForType(SchemaType stype, XmlCursor xmlc, Map<String, String> mapValues)
{
if (_typeStack.contains( stype ))
return;
_typeStack.add( stype );
try
{
if (stype.isSimpleType() || stype.isURType())
{
processSimpleType(stype, xmlc, mapValues);
return;
}
// complex Type
// <theElement>^</theElement>
processAttributes(stype, xmlc);
// <theElement attri1="string">^</theElement>
switch (stype.getContentType())
{
case SchemaType.NOT_COMPLEX_TYPE :
case SchemaType.EMPTY_CONTENT :
// noop
break;
case SchemaType.SIMPLE_CONTENT :
{
processSimpleType(stype, xmlc, mapValues);
}
break;
case SchemaType.MIXED_CONTENT :
xmlc.insertChars(pick(WORDS) + " ");
if (stype.getContentModel() != null)
{
processParticle(stype.getContentModel(), xmlc, true);
}
xmlc.insertChars(pick(WORDS));
break;
case SchemaType.ELEMENT_CONTENT :
if (stype.getContentModel() != null)
{
processParticle(stype.getContentModel(), xmlc, false);
}
break;
}
}
finally
{
_typeStack.remove( _typeStack.size() - 1 );
}
}
示例14: setText
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
public void setText(XmlObject xmlObject, String txt) {
XmlCursor cursor = xmlObject.newCursor();
cursor.toFirstContentToken();
cursor.insertChars(txt);
cursor.dispose();
}