本文整理匯總了Java中javax.xml.stream.events.XMLEvent.getEventType方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLEvent.getEventType方法的具體用法?Java XMLEvent.getEventType怎麽用?Java XMLEvent.getEventType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.stream.events.XMLEvent
的用法示例。
在下文中一共展示了XMLEvent.getEventType方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: nextTag
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Override
public final XMLEvent nextTag() throws XMLStreamException {
XMLEvent event = this.nextEvent();
while ((event.isCharacters() && event.asCharacters().isWhiteSpace())
|| event.isProcessingInstruction()
|| event.getEventType() == XMLStreamConstants.COMMENT) {
event = this.nextEvent();
}
if (!event.isStartElement() && event.isEndElement()) {
throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
}
return event;
}
示例2: unmarshal
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
XMLEvent event = null;
while (reader.hasNext()) {
try {
event = reader.peek();
switch (event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.COMMENT:
reader.nextEvent();
break;
case XMLStreamConstants.CHARACTERS:
processCharacters(event.asCharacters(), parentElement, map);
reader.nextEvent();
break;
case XMLStreamConstants.END_ELEMENT:
processEndTag(event.asEndElement(), parentElement);
reader.nextEvent();
return map;
case XMLStreamConstants.START_ELEMENT:
final StartElement element = event.asStartElement();
processStartTag(element, parentElement, reader, map);
break;
case XMLStreamConstants.END_DOCUMENT:
return map;
default:
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
}
} catch (XMLStreamException e) {
final Location location = event == null ? null : event.getLocation();
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
}
}
return map;
}
示例3: unmarshalModel
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/**
* See {@link PolicyModelUnmarshaller#unmarshalModel(Object) base method documentation}.
*/
public PolicySourceModel unmarshalModel(final Object storage) throws PolicyException {
final XMLEventReader reader = createXMLEventReader(storage);
PolicySourceModel model = null;
loop:
while (reader.hasNext()) {
try {
final XMLEvent event = reader.peek();
switch (event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
case XMLStreamConstants.COMMENT:
reader.nextEvent();
break; // skipping the comments and start document events
case XMLStreamConstants.CHARACTERS:
processCharacters(ModelNode.Type.POLICY, event.asCharacters(), null);
// we advance the reader only if there is no exception thrown from
// the processCharacters(...) call. Otherwise we don't modify the stream
reader.nextEvent();
break;
case XMLStreamConstants.START_ELEMENT:
if (NamespaceVersion.resolveAsToken(event.asStartElement().getName()) == XmlToken.Policy) {
StartElement rootElement = reader.nextEvent().asStartElement();
model = initializeNewModel(rootElement);
unmarshalNodeContent(model.getNamespaceVersion(), model.getRootNode(), rootElement.getName(), reader);
break loop;
} else {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
}
default:
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
}
} catch (XMLStreamException e) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
}
}
return model;
}
示例4: unmarshalNodeContent
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private String unmarshalNodeContent(final NamespaceVersion nsVersion, final ModelNode node, final QName nodeElementName, final XMLEventReader reader) throws PolicyException {
StringBuilder valueBuffer = null;
loop:
while (reader.hasNext()) {
try {
final XMLEvent xmlParserEvent = reader.nextEvent();
switch (xmlParserEvent.getEventType()) {
case XMLStreamConstants.COMMENT:
break; // skipping the comments
case XMLStreamConstants.CHARACTERS:
valueBuffer = processCharacters(node.getType(), xmlParserEvent.asCharacters(), valueBuffer);
break;
case XMLStreamConstants.END_ELEMENT:
checkEndTagName(nodeElementName, xmlParserEvent.asEndElement());
break loop; // data exctraction for currently processed policy node is done
case XMLStreamConstants.START_ELEMENT:
final StartElement childElement = xmlParserEvent.asStartElement();
ModelNode childNode = addNewChildNode(nsVersion, node, childElement);
String value = unmarshalNodeContent(nsVersion, childNode, childElement.getName(), reader);
if (childNode.isDomainSpecific()) {
parseAssertionData(nsVersion, value, childNode, childElement);
}
break;
default:
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0011_UNABLE_TO_UNMARSHALL_POLICY_XML_ELEM_EXPECTED()));
}
} catch (XMLStreamException e) {
throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
}
}
return (valueBuffer == null) ? null : valueBuffer.toString().trim();
}
示例5: nextTag
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/** Skips any insignificant space events until a START_ELEMENT or
* END_ELEMENT is reached. If anything other than space characters are
* encountered, an exception is thrown. This method should
* be used when processing element-only content because
* the parser is not able to recognize ignorable whitespace if
* the DTD is missing or not interpreted.
* @throws XMLStreamException if anything other than space characters are encountered
*/
public XMLEvent nextTag() throws XMLStreamException {
//its really a pain if there is peeked event before calling nextTag()
if(fPeekedEvent != null){
//check the peeked event first.
XMLEvent event = fPeekedEvent;
fPeekedEvent = null ;
int eventType = event.getEventType();
//if peeked event is whitespace move to the next event
//if peeked event is PI or COMMENT move to the next event
if( (event.isCharacters() && event.asCharacters().isWhiteSpace())
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
|| eventType == XMLStreamConstants.START_DOCUMENT){
event = nextEvent();
eventType = event.getEventType();
}
//we have to have the while loop because there can be many PI or comment event in sucession
while((event.isCharacters() && event.asCharacters().isWhiteSpace())
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT){
event = nextEvent();
eventType = event.getEventType();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException("expected start or end tag", event.getLocation());
}
return event;
}
//if there is no peeked event -- delegate the work of getting next event to fXMLReader
fXMLReader.nextTag();
return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
}
示例6: addMenu
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
void addMenu(XMLEventReader xer, XMLEvent event) throws XMLStreamException {
// user did not submit this part of code, just jump to the end of menu
// element
int eventType = 0;
while (true) {
event = xer.nextEvent();
// System.out.println("event: " + event);
eventType = event.getEventType();
if (eventType == XMLStreamConstants.END_ELEMENT && event.asEndElement().getName().equals(new QName("menu"))) {
break;
}
}
}
示例7: testEventReader
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
@Test(dataProvider = "xml-data")
public void testEventReader(String xml, int chunkSize, int expectedNumOfChunks, boolean withinLimit) throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", true);
if (chunkSize > 0) {
xif.setProperty(CDATA_CHUNK_SIZE, chunkSize);
}
XMLEventReader reader = xif.createXMLEventReader(new StringReader(xml));
StringBuilder cdata = new StringBuilder();
int numOfChunks = 0;
boolean isWithinLimit = true;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
//All text events get reported as Characters events
if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
Characters cdataEvent = (Characters) event;
if (cdataEvent.isCData()) {
String text = cdataEvent.getData();
numOfChunks++;
if (text.length() > chunkSize) {
isWithinLimit = false;
}
debugPrint("\nCDATA: " + text.length());
cdata.append(text);
}
}
}
debugPrint("CData in single chunk:" + cdata.toString().length());
Assert.assertEquals(numOfChunks, expectedNumOfChunks);
Assert.assertEquals(isWithinLimit, withinLimit);
}
示例8: testDTDEvent
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
/**
* DTDEvent instances constructed via event reader are missing the notation
* and entity declaration information
*/
@Test
public void testDTDEvent() {
String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
+ "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
+ "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";
try {
XMLEventReader er = getReader(XML);
XMLEvent evt = er.nextEvent(); // StartDocument
evt = er.nextEvent(); // DTD
if (evt.getEventType() != XMLStreamConstants.DTD) {
Assert.fail("Expected DTD event");
}
DTD dtd = (DTD) evt;
List entities = dtd.getEntities();
if (entities == null) {
Assert.fail("No entity found. Expected 3.");
} else {
Assert.assertEquals(entities.size(), 3);
}
// Let's also verify they are all of right type...
testListElems(entities, EntityDeclaration.class);
List notations = dtd.getNotations();
if (notations == null) {
Assert.fail("No notation found. Expected 2.");
} else {
Assert.assertEquals(notations.size(), 2);
}
// Let's also verify they are all of right type...
testListElems(notations, NotationDeclaration.class);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
示例9: accept
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public boolean accept(XMLEvent e) {
return types[e.getEventType()];
}
示例10: parseFactories
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private TubelineFeature parseFactories(final boolean enabled, final StartElement element, final XMLEventReader reader)
throws WebServiceException {
int elementRead = 0;
loop:
while (reader.hasNext()) {
try {
final XMLEvent event = reader.nextEvent();
switch (event.getEventType()) {
case XMLStreamConstants.COMMENT:
break; // skipping the comments and start document events
case XMLStreamConstants.CHARACTERS:
if (event.asCharacters().isWhiteSpace()) {
break;
}
else {
// TODO: logging message
throw LOGGER.logSevereException(new WebServiceException("No character data allowed, was " + event.asCharacters()));
}
case XMLStreamConstants.START_ELEMENT:
// TODO implement
elementRead++;
break;
case XMLStreamConstants.END_ELEMENT:
elementRead--;
if (elementRead < 0) {
final EndElement endElement = event.asEndElement();
if (!element.getName().equals(endElement.getName())) {
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("End element does not match " + endElement));
}
break loop;
}
else {
break;
}
default:
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("Unexpected event, was " + event));
}
} catch (XMLStreamException e) {
// TODO logging message
throw LOGGER.logSevereException(new WebServiceException("Failed to unmarshal XML document", e));
}
}
// TODO implement
return new TubelineFeature(enabled);
}
示例11: isTag
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private boolean isTag(XMLEvent event) {
int eventType = event.getEventType();
return eventType==XMLEvent.START_ELEMENT || eventType==XMLEvent.END_ELEMENT;
}
示例12: isIgnorable
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
private boolean isIgnorable(XMLEvent event) {
int eventType = event.getEventType();
return eventType==XMLEvent.COMMENT || eventType==XMLEvent.PROCESSING_INSTRUCTION;
}
示例13: parse
import javax.xml.stream.events.XMLEvent; //導入方法依賴的package包/類
public void parse(XMLEventReader input) throws XMLStreamException, XNIException {
XMLEvent currentEvent = input.peek();
if (currentEvent != null) {
int eventType = currentEvent.getEventType();
if (eventType != XMLStreamConstants.START_DOCUMENT &&
eventType != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException();
}
fLocationWrapper.setLocation(currentEvent.getLocation());
fSchemaDOMParser.startDocument(fLocationWrapper, null, fNamespaceContext, null);
loop: while (input.hasNext()) {
currentEvent = input.nextEvent();
eventType = currentEvent.getEventType();
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
++fDepth;
StartElement start = currentEvent.asStartElement();
fillQName(fElementQName, start.getName());
fLocationWrapper.setLocation(start.getLocation());
fNamespaceContext.setNamespaceContext(start.getNamespaceContext());
fillXMLAttributes(start);
fillDeclaredPrefixes(start);
addNamespaceDeclarations();
fNamespaceContext.pushContext();
fSchemaDOMParser.startElement(fElementQName, fAttributes, null);
break;
case XMLStreamConstants.END_ELEMENT:
EndElement end = currentEvent.asEndElement();
fillQName(fElementQName, end.getName());
fillDeclaredPrefixes(end);
fLocationWrapper.setLocation(end.getLocation());
fSchemaDOMParser.endElement(fElementQName, null);
fNamespaceContext.popContext();
--fDepth;
if (fDepth <= 0) {
break loop;
}
break;
case XMLStreamConstants.CHARACTERS:
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
break;
case XMLStreamConstants.SPACE:
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), true);
break;
case XMLStreamConstants.CDATA:
fSchemaDOMParser.startCDATA(null);
sendCharactersToSchemaParser(currentEvent.asCharacters().getData(), false);
fSchemaDOMParser.endCDATA(null);
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
ProcessingInstruction pi = (ProcessingInstruction)currentEvent;
fillProcessingInstruction(pi.getData());
fSchemaDOMParser.processingInstruction(pi.getTarget(), fTempString, null);
break;
case XMLStreamConstants.DTD:
/* There shouldn't be a DTD in the schema */
break;
case XMLStreamConstants.ENTITY_REFERENCE:
/* Not needed for schemas */
break;
case XMLStreamConstants.COMMENT:
/* No point in sending comments */
break;
case XMLStreamConstants.START_DOCUMENT:
fDepth++;
/* We automatically call startDocument before the loop */
break;
case XMLStreamConstants.END_DOCUMENT:
/* We automatically call endDocument after the loop */
break;
}
}
fLocationWrapper.setLocation(null);
fNamespaceContext.setNamespaceContext(null);
fSchemaDOMParser.endDocument(null);
}
}