本文整理匯總了Java中javax.xml.stream.XMLStreamReader.getEventType方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLStreamReader.getEventType方法的具體用法?Java XMLStreamReader.getEventType怎麽用?Java XMLStreamReader.getEventType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.XMLStreamReader
的用法示例。
在下文中一共展示了XMLStreamReader.getEventType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readRequest
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
void readRequest( Object[] args, XMLStreamReader r, AttachmentSet att) throws JAXBException {
Object obj = null;
AttachmentUnmarshallerImpl au = (att != null)?new AttachmentUnmarshallerImpl(att):null;
if (bridge instanceof RepeatedElementBridge) {
RepeatedElementBridge rbridge = (RepeatedElementBridge)bridge;
ArrayList list = new ArrayList();
QName name = r.getName();
while (r.getEventType()==XMLStreamReader.START_ELEMENT && name.equals(r.getName())) {
list.add(rbridge.unmarshal(r, au));
XMLStreamReaderUtil.toNextTag(r, name);
}
obj = rbridge.collectionHandler().convert(list);
} else {
obj = bridge.unmarshal(r, au);
}
setter.put(obj,args);
}
示例2: toNextTag
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void toNextTag(XMLStreamReader reader, QName name) {
// skip any whitespace
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT &&
reader.getEventType() != XMLStreamConstants.END_ELEMENT) {
XMLStreamReaderUtil.nextElementContent(reader);
}
if(reader.getEventType() == XMLStreamConstants.END_ELEMENT && name.equals(reader.getName())) {
XMLStreamReaderUtil.nextElementContent(reader);
}
}
示例3: configureExternalMetadataReader
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
protected ExternalMetadataFeature configureExternalMetadataReader(XMLStreamReader reader) {
ExternalMetadataFeature.Builder featureBuilder = null;
while (QNAME_EXT_METADA.equals(reader.getName())) {
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
Attributes attrs = XMLStreamReaderUtil.getAttributes(reader);
String file = getAttribute(attrs, ATTR_FILE);
if (file != null) {
if (featureBuilder == null) {
featureBuilder = ExternalMetadataFeature.builder();
}
featureBuilder.addFiles(new File(file));
}
String res = getAttribute(attrs, ATTR_RESOURCE);
if (res != null) {
if (featureBuilder == null) {
featureBuilder = ExternalMetadataFeature.builder();
}
featureBuilder.addResources(res);
}
}
XMLStreamReaderUtil.nextElementContent(reader);
}
return buildFeature(featureBuilder);
}
示例4: createElementFragment
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Creates the buffer from a stream reader that is an element fragment.
* <p>
* The stream reader will be moved to the position of the next start of
* an element if the stream reader is not already positioned at the start
* of an element.
* <p>
* The element and all its children will be stored and after storing the stream
* will be positioned at the next event after the end of the element.
* <p>
* @param storeInScopeNamespaces true if in-scope namespaces of the element
* fragment should be stored.
* @return the mutable stream buffer.
* @throws XMLStreamException if the stream reader cannot be positioned at
* the start of an element.
*/
public MutableXMLStreamBuffer createElementFragment(XMLStreamReader reader,
boolean storeInScopeNamespaces) throws XMLStreamException {
if (_buffer == null) {
createBuffer();
}
if (!reader.hasNext()) {
return _buffer;
}
_storeInScopeNamespacesOnElementFragment = storeInScopeNamespaces;
_eventType = reader.getEventType();
if (_eventType != XMLStreamReader.START_ELEMENT) {
do {
_eventType = reader.next();
} while(_eventType != XMLStreamReader.START_ELEMENT && _eventType != XMLStreamReader.END_DOCUMENT);
}
if (storeInScopeNamespaces) {
_inScopePrefixes = new HashMap<String,Integer>();
}
storeElementAndChildren(reader);
return getXMLStreamBuffer();
}
示例5: getSheetId
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Helper method to read the "workbook.xml" in the document and find out the sheet id for
* given sheet name, or the first sheet if sheetName is null or empty.
* @param workbook InputStream of the workbook. Caller is responsible for closing it.
* @param sheetName Sheet name to lookup.
* @return Non-null value if found a sheet with given name. Otherwise null
* @throws XMLStreamException
*/
public static String getSheetId(final InputStream workbook, final String sheetName) throws XMLStreamException {
checkNotNull(workbook);
final XMLStreamReader wbReader = XML_INPUT_FACTORY.createXMLStreamReader(workbook);
final boolean retrieveFirstSheet = sheetName == null || sheetName.isEmpty();
while (wbReader.hasNext()) {
wbReader.next();
final int event = wbReader.getEventType();
switch (event) {
case START_ELEMENT: {
final String name = wbReader.getLocalName();
if (SHEET.equals(name)) {
String sheet = wbReader.getAttributeValue(/*namespaceURI=*/null, SHEET_NAME);
// Sheet names are case insensitive
if (retrieveFirstSheet || sheetName.equalsIgnoreCase(sheet)) {
return wbReader.getAttributeValue(SHEET_ID_NS, SHEET_ID);
}
}
break;
}
}
}
return null;
}
示例6: test1
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Verifies that the initial event of an XMLStreamReader instance is
* START_DOCUMENT.
*
* @param xml the xml input
* @param type1 the type of the 1st event
* @param type2 the type of the 2nd event
* @throws Exception if the test fails to run properly
*/
@Test(dataProvider = "xmls")
public static void test1(String xml, int type1, int type2) throws Exception {
XMLInputFactory factory = XMLInputFactory.newFactory();
XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
int type1stEvent = reader.getEventType();
int type2ndEvent = reader.next();
System.out.println("First event: " + type1stEvent);
System.out.println("2nd event: " + type2ndEvent);
Assert.assertEquals(type1, type1stEvent);
Assert.assertEquals(type2, type2ndEvent);
}
示例7: verifyReaderState
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void verifyReaderState(XMLStreamReader reader, int expectedState) {
int state = reader.getEventType();
if (state != expectedState) {
throw new XMLStreamReaderException(
"xmlreader.unexpectedState",
getStateName(expectedState), getStateName(state));
}
}
示例8: getAttribute
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
@Nullable
public String getAttribute(@NotNull String nsUri, @NotNull String localName) {
try {
XMLStreamReader sr = epr.read("EndpointReference"/*doesn't matter*/);
while(sr.getEventType()!= XMLStreamConstants.START_ELEMENT)
sr.next();
return sr.getAttributeValue(nsUri,localName);
} catch (XMLStreamException e) {
// since we are reading from buffer, this can't happen.
throw new AssertionError(e);
}
}
示例9: 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);
}
}
示例10: readRest
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void readRest(XMLStreamReader reader) {
try {
while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT) {
reader.next();
}
} catch (XMLStreamException e) {
throw wrapException(e);
}
}
示例11: post
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
private boolean post(QName tagName, XMLStreamReader xsr, boolean result) {
if(!tagName.equals(xsr.getName()))
return foundFool();
if(result) {
if(xsr.getEventType()!=XMLStreamConstants.END_ELEMENT)
foundFool();
} else {
if(xsr.getEventType()!=XMLStreamConstants.START_ELEMENT)
foundFool();
}
return result;
}
示例12: 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;
}
示例13: accept
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public boolean accept(XMLStreamReader r) {
return types[r.getEventType()];
}
示例14: printEvent
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
public static void printEvent(XMLStreamReader xmlr, boolean showEvents) {
if (showEvents) {
System.out.print("EVENT:[" + xmlr.getLocation().getLineNumber() + "]["
+ xmlr.getLocation().getColumnNumber() + "] [" + getEventTypeName(xmlr.getEventType())
+ "]");
System.out.print(" [");
}
switch (xmlr.getEventType()) {
case XMLStreamConstants.START_ELEMENT:
System.out.print("<");
printName(xmlr);
printNamespaces(xmlr);
printAttributes(xmlr);
System.out.print(">");
break;
case XMLStreamConstants.END_ELEMENT:
System.out.print("</");
printName(xmlr);
System.out.print(">");
break;
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CHARACTERS:
int start = xmlr.getTextStart();
int length = xmlr.getTextLength();
System.out.print(new String(xmlr.getTextCharacters(), start, length));
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
System.out.print("<?");
if (xmlr.hasText())
System.out.print(xmlr.getText());
System.out.print("?>");
break;
case XMLStreamConstants.CDATA:
System.out.print("<![CDATA[");
start = xmlr.getTextStart();
length = xmlr.getTextLength();
System.out.print(new String(xmlr.getTextCharacters(), start, length));
System.out.print("]]>");
break;
case XMLStreamConstants.COMMENT:
System.out.print("<!--");
if (xmlr.hasText())
System.out.print(xmlr.getText());
System.out.print("-->");
break;
case XMLStreamConstants.ENTITY_REFERENCE:
System.out.print(xmlr.getLocalName() + "=");
if (xmlr.hasText())
System.out.print("[" + xmlr.getText() + "]");
break;
case XMLStreamConstants.START_DOCUMENT:
System.out.print("<?xml");
System.out.print(" version='" + xmlr.getVersion() + "'");
System.out.print(" encoding='" + xmlr.getCharacterEncodingScheme() + "'");
if (xmlr.isStandalone())
System.out.print(" standalone='yes'");
else
System.out.print(" standalone='no'");
System.out.print("?>");
break;
}
System.out.println("]");
}
示例15: getAttributes
import javax.xml.stream.XMLStreamReader; //導入方法依賴的package包/類
/**
* Read all attributes into an data structure. Note that this method cannot
* be called multiple times to get the same list of attributes.
*/
public static Attributes getAttributes(XMLStreamReader reader) {
return (reader.getEventType() == START_ELEMENT ||
reader.getEventType() == ATTRIBUTE) ?
new AttributesImpl(reader) : null;
}