本文整理汇总了Java中javax.xml.stream.XMLStreamReader.getText方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamReader.getText方法的具体用法?Java XMLStreamReader.getText怎么用?Java XMLStreamReader.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: characters
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public void characters(final XMLStreamReader xmlsr) {
if (profileElement) {
String value = xmlsr.getText();
if (value.contains("EquipmentBoundary")) {
profileName = "EQBD";
} else if (value.contains("TopologyBoundary")) {
profileName = "TPBD";
} else if (value.contains("EquipmentCore")) {
profileName = "EQ";
} else if (value.contains("Topology")) {
profileName = "TP";
} else if (value.contains("StateVariables")) {
profileName = "SV";
} else if (value.contains("SteadyStateHypothesis")) {
profileName = "SSH";
} else if (value.contains("Dynamics")) {
profileName = "DY";
}
profileElement = false;
}
}
示例2: readUntilEndElement
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static String readUntilEndElement(String endElementName, XMLStreamReader reader, XmlEventHandler eventHandler) throws XMLStreamException {
String text = null;
int event;
while (!((event = reader.next()) == XMLStreamConstants.END_ELEMENT
&& reader.getLocalName().equals(endElementName))) {
text = null;
switch (event) {
case XMLStreamConstants.START_ELEMENT:
if (eventHandler != null) {
eventHandler.onStartElement();
}
break;
case XMLStreamConstants.CHARACTERS:
text = reader.getText();
break;
default:
break;
}
}
return text;
}
示例3: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static TsoFrequencySecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.END_ELEMENT:
if ("freq-out-count".equals(xmlsr.getLocalName())) {
return new TsoFrequencySecurityIndex(contingencyId, Integer.parseInt(text));
}
break;
default:
break;
}
}
throw new AssertionError("freq-out-count element not found");
}
示例4: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static UnderOverVoltageSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.END_ELEMENT:
if ("vx".equals(xmlsr.getLocalName())) {
return new UnderOverVoltageSecurityIndex(contingencyId, Double.parseDouble(text));
}
break;
default:
break;
}
}
throw new AssertionError("vx element not found");
}
示例5: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static TsoOvervoltageSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
boolean computationSucceed = true;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case "computation-succeed":
computationSucceed = Boolean.parseBoolean(text);
break;
case "overvoltage-count":
return new TsoOvervoltageSecurityIndex(contingencyId, Integer.parseInt(text), computationSucceed);
default:
break;
}
break;
default:
break;
}
}
throw new AssertionError("overvoltage-count element not found");
}
示例6: supportXMLResolver
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
@Test(dataProvider = "supportXMLResolver")
public void supportXMLResolver(URI catalogFile, String xml, String expected) throws Exception {
String xmlSource = getClass().getResource(xml).getFile();
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
XMLInputFactory xifactory = XMLInputFactory.newInstance();
xifactory.setProperty(XMLInputFactory.IS_COALESCING, true);
xifactory.setProperty(XMLInputFactory.RESOLVER, cr);
File file = new File(xmlSource);
String systemId = file.toURI().toASCIIString();
InputStream entityxml = new FileInputStream(file);
XMLStreamReader streamReader = xifactory.createXMLStreamReader(systemId, entityxml);
String result = null;
while (streamReader.hasNext()) {
int eventType = streamReader.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
eventType = streamReader.next();
if (eventType == XMLStreamConstants.CHARACTERS) {
result = streamReader.getText();
}
}
}
System.out.println(": expected [" + expected + "] <> actual [" + result.trim() + "]");
Assert.assertEquals(result.trim(), expected);
}
示例7: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static TsoUndervoltageSecurityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
boolean computationSucceed = true;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case "computation-succeed":
computationSucceed = Boolean.parseBoolean(text);
break;
case "undervoltage-count":
return new TsoUndervoltageSecurityIndex(contingencyId, Integer.parseInt(text), computationSucceed);
default:
break;
}
break;
default:
break;
}
}
throw new AssertionError("undervoltage-count element not found");
}
示例8: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static TsoDisconnectedGenerator fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
Map<String, Float> disconnectedGenerators = new HashMap<>();
String id = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.START_ELEMENT:
if ("generator".equals(xmlsr.getLocalName())) {
id = xmlsr.getAttributeValue(null, "id");
}
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case "generator":
if (id == null) {
throw new AssertionError();
}
float p = Float.parseFloat(text);
disconnectedGenerators.put(id, p);
id = null;
break;
case "index":
return new TsoDisconnectedGenerator(contingencyId, disconnectedGenerators);
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
default:
break;
}
}
throw new AssertionError("Should not happen");
}
示例9: nextElementContent
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static int nextElementContent(XMLStreamReader reader) {
int state = nextContent(reader);
if (state == CHARACTERS) {
throw new XMLStreamReaderException(
"xmlreader.unexpectedCharacterContent", reader.getText());
}
return state;
}
示例10: currentWhiteSpaceContent
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Read spaces from the reader as long as to the next element, starting from
* current position. Comments are ignored.
* @param reader
* @return
*/
public static String currentWhiteSpaceContent(XMLStreamReader reader) {
// since the there might be several valid chunks (spaces/comment/spaces)
// StringBuilder must be used; it's initialized lazily, only when needed
StringBuilder whiteSpaces = null;
for (;;) {
switch (reader.getEventType()) {
case START_ELEMENT:
case END_ELEMENT:
case END_DOCUMENT:
return whiteSpaces == null ? null : whiteSpaces.toString();
case CHARACTERS:
if (reader.isWhiteSpace()) {
if (whiteSpaces == null) {
whiteSpaces = new StringBuilder();
}
whiteSpaces.append(reader.getText());
} else {
throw new XMLStreamReaderException(
"xmlreader.unexpectedCharacterContent", reader.getText());
}
}
next(reader);
}
}
示例11: tokenTypeDesc
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
protected static String tokenTypeDesc(int tt, XMLStreamReader sr) {
String desc = tokenTypeDesc(tt);
// Let's show first 8 chars or so...
if (tt == CHARACTERS || tt == SPACE || tt == CDATA) {
String str = sr.getText();
if (str.length() > MAX_DESC_TEXT_CHARS) {
desc = "\"" + str.substring(0, MAX_DESC_TEXT_CHARS) + "\"[...]";
} else {
desc = "\"" + desc + "\"";
}
desc = " (" + desc + ")";
}
return desc;
}
示例12: handleCharacters
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
private void handleCharacters(XMLStreamReader xmlr) {
if (xmlr.hasText())
output += xmlr.getText();
}
示例13: getAndVerifyText
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
/**
* Method that not only gets currently available text from the reader, but
* also checks that its consistenly accessible using different StAX methods.
*/
protected static String getAndVerifyText(XMLStreamReader sr) throws XMLStreamException {
String text = sr.getText();
/*
* 05-Apr-2006, TSa: Although getText() is available for DTD and
* ENTITY_REFERENCE, getTextXxx() are not. Thus, can not do more checks
* for those types.
*/
int type = sr.getEventType();
if (type != ENTITY_REFERENCE && type != DTD) {
Assert.assertNotNull("getText() should never return null.", text);
int expLen = sr.getTextLength();
/*
* Hmmh. Can only return empty text for CDATA (since empty blocks
* are legal).
*/
/*
* !!! 01-Sep-2004, TSa: note: theoretically, in coalescing mode, it
* could be possible to have empty CDATA section(s) get converted to
* CHARACTERS, which would be empty... may need to enhance this to
* check that mode is not coalescing? Or something
*/
if (sr.getEventType() == CHARACTERS) {
if (expLen == 0) {
Assert.fail("Stream reader should never return empty Strings.");
}
}
Assert.assertEquals(expLen, text.length(), "Expected text length of " + expLen + ", got " + text.length());
char[] textChars = sr.getTextCharacters();
int start = sr.getTextStart();
String text2 = new String(textChars, start, expLen);
Assert.assertEquals("Expected getText() and getTextCharacters() to return same value for event of type (" + tokenTypeDesc(sr.getEventType()) + ")",
text, text2);
} else { // DTD or ENTITY_REFERENCE
// not sure if null is legal for these either, but...
if (text == null) { // let's prevent an NPE at caller
text = "";
}
}
return text;
}
示例14: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static MultiCriteriaVoltageStabilityIndex fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
String text = null;
Map<String, Float> lockedTapChangerLoads = new LinkedHashMap<>();
Map<String, Float> stoppedTapChangerLoads = new LinkedHashMap<>();
Map<String, Float> underVoltageAutomatonGenerators = new LinkedHashMap<>();
Set<String> underVoltageBuses = new LinkedHashSet<>();
String id = null;
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.START_ELEMENT:
switch (xmlsr.getLocalName()) {
case TAG_LOCKED_TAP_CHANGER_LOAD:
case TAG_STOPPED_TAP_CHANGER_LOAD:
case TAG_UNDER_VOLTAGE_AUTOMATON_GENERATOR:
id = xmlsr.getAttributeValue(null, TAG_ID);
break;
case TAG_UNDER_BUS_VOLTAGE:
case TAG_INDEX:
// nothing to do
break;
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case TAG_LOCKED_TAP_CHANGER_LOAD:
if (id == null) {
throw new AssertionError();
}
lockedTapChangerLoads.put(id, Float.parseFloat(text));
id = null;
break;
case TAG_STOPPED_TAP_CHANGER_LOAD:
if (id == null) {
throw new AssertionError();
}
stoppedTapChangerLoads.put(id, Float.parseFloat(text));
id = null;
break;
case TAG_UNDER_VOLTAGE_AUTOMATON_GENERATOR:
if (id == null) {
throw new AssertionError();
}
underVoltageAutomatonGenerators.put(id, Float.parseFloat(text));
id = null;
break;
case TAG_UNDER_BUS_VOLTAGE:
underVoltageBuses.add(text);
break;
case TAG_INDEX:
return new MultiCriteriaVoltageStabilityIndex(contingencyId, lockedTapChangerLoads, stoppedTapChangerLoads,
underVoltageAutomatonGenerators, underVoltageBuses);
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
default:
break;
}
}
throw new AssertionError("Should not happen");
}
示例15: fromXml
import javax.xml.stream.XMLStreamReader; //导入方法依赖的package包/类
public static TsoGeneratorSpeedAutomaton fromXml(String contingencyId, XMLStreamReader xmlsr) throws XMLStreamException {
LimitsXmlParsingState state = null;
String text = null;
List<String> onUnderSpeedDiconnectedGenerators = new ArrayList<>();
List<String> onOverSpeedDiconnectedGenerators = new ArrayList<>();
while (xmlsr.hasNext()) {
int eventType = xmlsr.next();
switch (eventType) {
case XMLEvent.CHARACTERS:
text = xmlsr.getText();
break;
case XMLEvent.START_ELEMENT:
switch (xmlsr.getLocalName()) {
case ON_UNDER_SPEED_DISCONNECTED_GENERATORS:
state = LimitsXmlParsingState.UNDER;
break;
case ON_OVER_SPEED_DISCONNECTED_GENERATORS:
state = LimitsXmlParsingState.OVER;
break;
case GEN:
case INDEX:
// nothing to do
break;
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
case XMLEvent.END_ELEMENT:
switch (xmlsr.getLocalName()) {
case ON_UNDER_SPEED_DISCONNECTED_GENERATORS:
case ON_OVER_SPEED_DISCONNECTED_GENERATORS:
state = null;
break;
case GEN:
LimitsXmlParsingState.addGenerator(state, text, onUnderSpeedDiconnectedGenerators, onOverSpeedDiconnectedGenerators);
break;
case INDEX:
return new TsoGeneratorSpeedAutomaton(contingencyId, onUnderSpeedDiconnectedGenerators, onOverSpeedDiconnectedGenerators);
default:
throw new AssertionError("Unexpected element: " + xmlsr.getLocalName());
}
break;
default:
break;
}
}
throw new AssertionError("Should not happen");
}