本文整理汇总了Java中javax.xml.stream.XMLStreamConstants.ENTITY_REFERENCE属性的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamConstants.ENTITY_REFERENCE属性的具体用法?Java XMLStreamConstants.ENTITY_REFERENCE怎么用?Java XMLStreamConstants.ENTITY_REFERENCE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.xml.stream.XMLStreamConstants
的用法示例。
在下文中一共展示了XMLStreamConstants.ENTITY_REFERENCE属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEventTypeName
private static String getEventTypeName(int eventType) {
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
return "START_ELEMENT";
case XMLStreamConstants.END_ELEMENT:
return "END_ELEMENT";
case XMLStreamConstants.SPACE:
return "SPACE";
case XMLStreamConstants.CHARACTERS:
return "CHARACTERS";
case XMLStreamConstants.PROCESSING_INSTRUCTION:
return "PROCESSING_INSTRUCTION";
case XMLStreamConstants.CDATA:
return "CDATA";
case XMLStreamConstants.COMMENT:
return "COMMENT";
case XMLStreamConstants.ENTITY_REFERENCE:
return "ENTITY_REFERENCE";
case XMLStreamConstants.START_DOCUMENT:
return "START_DOCUMENT";
case XMLStreamConstants.END_DOCUMENT:
return "END_DOCUMENT";
}
return null;
}
示例2: testHasNameOnEntityEvent
/**
* CR 6631264 / sjsxp Issue 45:
* https://sjsxp.dev.java.net/issues/show_bug.cgi?id=45
* XMLStreamReader.hasName() should return false for ENTITY_REFERENCE
*/
@Test
public void testHasNameOnEntityEvent() throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader r = xif.createXMLStreamReader(
this.getClass().getResourceAsStream("ExternalDTD.xml"));
while (r.next() != XMLStreamConstants.ENTITY_REFERENCE) {
System.out.println("event type: " + r.getEventType());
continue;
}
if (r.hasName()) {
System.out.println("hasName returned true on ENTITY_REFERENCE event.");
}
Assert.assertFalse(r.hasName()); // fails
}
示例3: getText
/**
* Returns the accumulated text of an event type.
*
* @param streamReader the XMLStreamReader
* @param type the type of event requested
* @return the text of the accumulated text for the request type
* @throws XMLStreamException
*/
String getText(XMLStreamReader streamReader, int type) throws XMLStreamException {
StringBuilder text = new StringBuilder();
StringBuilder entityRef = new StringBuilder();
while(streamReader.hasNext()){
int eventType = streamReader.next();
switch (eventType) {
case XMLStreamConstants.START_ELEMENT:
break;
case XMLStreamConstants.CHARACTERS:
text.append(streamReader.getText());
break;
case XMLStreamConstants.ENTITY_REFERENCE:
entityRef.append(streamReader.getText());
break;
}
}
if (type == XMLStreamConstants.CHARACTERS) {
return text.toString();
} else {
return entityRef.toString();
}
}
示例4: 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";
}
示例5: 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";
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: parse
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);
}
}
示例10: printEvent
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("]");
}