本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.COMMENT属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.COMMENT属性的具体用法?Java XMLStreamConstants.COMMENT怎么用?Java XMLStreamConstants.COMMENT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.XMLStreamConstants
的用法示例。
在下文中一共展示了XMLStreamConstants.COMMENT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nextTagSkipDTD
/**
* A copy of the nextTag algorithm from the XMLStreamReader javadocs,
* but which also skips over DTD events as well as whitespace,
* comments and PIs.
*
* @param xsr the reader to advance
* @return {@link XMLStreamConstants#START_ELEMENT} or
* {@link XMLStreamConstants#END_ELEMENT} for the next tag.
* @throws XMLStreamException
*/
private static int nextTagSkipDTD(XMLStreamReader xsr)
throws XMLStreamException {
int eventType = xsr.next();
while((eventType == XMLStreamConstants.CHARACTERS && xsr.isWhiteSpace())
|| (eventType == XMLStreamConstants.CDATA && xsr.isWhiteSpace())
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
|| eventType == XMLStreamConstants.DTD) {
eventType = xsr.next();
}
if(eventType != XMLStreamConstants.START_ELEMENT
&& eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException("expected start or end tag", xsr
.getLocation());
}
return eventType;
}
示例2: nextTag
@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;
}
示例3: toDom4jDocument
private Document toDom4jDocument(XMLEventReader staxEventReader, Origin origin) {
STAXEventReader dom4jStaxEventReader = new STAXEventReader();
try {
// the dom4j converter class is touchy about comments (aka, comments make it implode)
// so wrap the event stream in a filtering stream to filter out comment events
staxEventReader = new FilteringXMLEventReader( staxEventReader ) {
@Override
protected XMLEvent filterEvent(XMLEvent event, boolean peek) {
return event.getEventType() == XMLStreamConstants.COMMENT
? null
: event;
}
};
return dom4jStaxEventReader.readDocument( staxEventReader );
}
catch (XMLStreamException e) {
throw new InvalidMappingException( "Unable to read StAX source as dom4j Document for processing", origin, e );
}
}
示例4: nextTag
/** Skips any insignificant events (COMMENT and PROCESSING_INSTRUCTION)
* until a START_ELEMENT or
* END_ELEMENT is reached. If 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
* then DTD is missing or not interpreted.
* @return the event type of the element read
* @throws XMLStreamException if the current event is not white space
*/
public int nextTag() throws XMLStreamException {
int eventType = next();
while((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
|| (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
// skip whitespace
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT
) {
eventType = next();
}
if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
throw new XMLStreamException(
"found: " + getEventTypeString(eventType)
+ ", expected " + getEventTypeString(XMLStreamConstants.START_ELEMENT)
+ " or " + getEventTypeString(XMLStreamConstants.END_ELEMENT),
getLocation());
}
return eventType;
}
示例5: getElementText
/**
* Reads the content of a text-only element. Precondition: the current event
* is START_ELEMENT. Postcondition: The current event is the corresponding
* END_ELEMENT.
*
* @throws XMLStreamException if the current event is not a START_ELEMENT or
* if a non text element is encountered
*/
public String getElementText() throws XMLStreamException {
if (getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuilder content = new StringBuilder();
while (eventType != XMLStreamConstants.END_ELEMENT) {
if (eventType == XMLStreamConstants.CHARACTERS
|| eventType == XMLStreamConstants.CDATA
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) {
content.append(getText());
} else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if (eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException(
"unexpected end of document when reading element text content");
} else if (eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException("elementGetText() function expects text "
+ "only elment but START_ELEMENT was encountered.", getLocation());
} else {
throw new XMLStreamException(
"Unexpected event type " + eventType, getLocation());
}
eventType = next();
}
return content.toString();
}
示例6: getEventName
/**
* Get the human readable event name for the numeric event id
*/
public static String getEventName(int eventId) {
switch (eventId) {
case XMLStreamConstants.START_ELEMENT:
return "StartElementEvent";
case XMLStreamConstants.END_ELEMENT:
return "EndElementEvent";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "ProcessingInstructionEvent";
case XMLStreamConstants.CHARACTERS:
return "CharacterEvent";
case XMLStreamConstants.COMMENT:
return "CommentEvent";
case XMLStreamConstants.START_DOCUMENT:
return "StartDocumentEvent";
case XMLStreamConstants.END_DOCUMENT:
return "EndDocumentEvent";
case XMLStreamConstants.ENTITY_REFERENCE:
return "EntityReferenceEvent";
case XMLStreamConstants.ATTRIBUTE:
return "AttributeBase";
case XMLStreamConstants.DTD:
return "DTDEvent";
case XMLStreamConstants.CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
示例7: testSkippingExternalDTD
@Test
public void testSkippingExternalDTD() throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
try(
InputStream is= getClass().getResourceAsStream("XMLSchema.xsd");
) {
XMLStreamReader reader = xif.createXMLStreamReader(getClass().getResource("XMLSchema.xsd").getFile(), is);
int e;
while ((e = reader.next()) == XMLStreamConstants.COMMENT);
Assert.assertEquals(e, XMLStreamConstants.DTD, "should be DTD");
reader.nextTag();
Assert.assertEquals(reader.getLocalName(), "schema", "next tag should be schema");
}
}
示例8: unmarshal
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;
}
示例9: getEventType
private int getEventType() throws XMLStreamException {
int event = in.getEventType();
// if the parser is at the start tag, proceed to the first element
//Note - need to do this every time because we could be using a composite reader
if(event == XMLStreamConstants.START_DOCUMENT) {
// nextTag doesn't correctly handle DTDs
while( !in.isStartElement() ) {
event = in.next();
if (event == XMLStreamConstants.COMMENT)
handleComment();
}
}
return event;
}
示例10: unmarshalNodeContent
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();
}
示例11: getElementText
/** Reads the content of a text-only element. Precondition:
* the current event is START_ELEMENT. Postcondition:
* The current event is the corresponding END_ELEMENT.
* @throws XMLStreamException if the current event is not a START_ELEMENT or if
* a non text element is encountered
*/
public String getElementText() throws XMLStreamException {
if(getEventType() != XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"parser must be on START_ELEMENT to read next text", getLocation());
}
int eventType = next();
StringBuffer content = new StringBuffer();
while(eventType != XMLStreamConstants.END_ELEMENT ) {
if(eventType == XMLStreamConstants.CHARACTERS
|| eventType == XMLStreamConstants.CDATA
|| eventType == XMLStreamConstants.SPACE
|| eventType == XMLStreamConstants.ENTITY_REFERENCE) {
content.append(getText());
} else if(eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
|| eventType == XMLStreamConstants.COMMENT) {
// skipping
} else if(eventType == XMLStreamConstants.END_DOCUMENT) {
throw new XMLStreamException("unexpected end of document when reading element text content");
} else if(eventType == XMLStreamConstants.START_ELEMENT) {
throw new XMLStreamException(
"elementGetText() function expects text only elment but START_ELEMENT was encountered.", getLocation());
} else {
throw new XMLStreamException(
"Unexpected event type "+ eventType, getLocation());
}
eventType = next();
}
return content.toString();
}
示例12: nextTag
/** 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));
}
示例13: getEventTypeString
public final static String getEventTypeString(int eventType) {
switch (eventType){
case XMLStreamConstants.START_ELEMENT:
return "START_ELEMENT";
case XMLStreamConstants.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamConstants.CHARACTERS:
return "CHARACTERS";
case XMLStreamConstants.COMMENT:
return "COMMENT";
case XMLStreamConstants.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamConstants.END_DOCUMENT:
return "END_DOCUMENT";
case XMLStreamConstants.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamConstants.ATTRIBUTE:
return "ATTRIBUTE";
case XMLStreamConstants.DTD:
return "DTD";
case XMLStreamConstants.CDATA:
return "CDATA";
}
return "UNKNOWN_EVENT_TYPE";
}
示例14: getElementText
@Override
public final String getElementText() throws XMLStreamException {
XMLEvent event = this.previousEvent;
if (event == null) {
throw new XMLStreamException("Must be on START_ELEMENT to read next text, element was null");
}
if (!event.isStartElement()) {
throw new XMLStreamException("Must be on START_ELEMENT to read next text", event.getLocation());
}
final StringBuilder text = new StringBuilder();
while (!event.isEndDocument()) {
switch (event.getEventType()) {
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA: {
final Characters characters = event.asCharacters();
text.append(characters.getData());
break;
}
case XMLStreamConstants.ENTITY_REFERENCE: {
final EntityReference entityReference = (EntityReference)event;
final EntityDeclaration declaration = entityReference.getDeclaration();
text.append(declaration.getReplacementText());
break;
}
case XMLStreamConstants.COMMENT:
case XMLStreamConstants.PROCESSING_INSTRUCTION: {
//Ignore
break;
}
default: {
throw new XMLStreamException("Unexpected event type '" + XMLStreamConstantsUtils.getEventName(event.getEventType()) + "' encountered. Found event: " + event, event.getLocation());
}
}
event = this.nextEvent();
}
return text.toString();
}
示例15: parseFactories
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);
}