本文整理汇总了Java中javax.xml.stream.events.EntityReference类的典型用法代码示例。如果您正苦于以下问题:Java EntityReference类的具体用法?Java EntityReference怎么用?Java EntityReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityReference类属于javax.xml.stream.events包,在下文中一共展示了EntityReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public String getText() {
XMLSecEvent xmlSecEvent = getCurrentEvent();
switch (xmlSecEvent.getEventType()) {
case ENTITY_REFERENCE:
return ((EntityReference) xmlSecEvent).getDeclaration().getReplacementText();
case DTD:
return ((DTD) xmlSecEvent).getDocumentTypeDeclaration();
case COMMENT:
return ((Comment) xmlSecEvent).getText();
case CDATA:
case SPACE:
case CHARACTERS:
return xmlSecEvent.asCharacters().getData();
default:
throw new IllegalStateException("Current state not TEXT");
}
}
示例2: getTextCharacters
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public char[] getTextCharacters() {
XMLSecEvent xmlSecEvent = getCurrentEvent();
switch (xmlSecEvent.getEventType()) {
case ENTITY_REFERENCE:
return ((EntityReference) xmlSecEvent).getDeclaration().getReplacementText().toCharArray();
case DTD:
return ((DTD) xmlSecEvent).getDocumentTypeDeclaration().toCharArray();
case COMMENT:
return ((Comment) xmlSecEvent).getText().toCharArray();
case CDATA:
case SPACE:
case CHARACTERS:
return xmlSecEvent.asCharacters().getText();
default:
throw new IllegalStateException("Current state not TEXT");
}
}
示例3: getTextLength
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public int getTextLength() {
XMLSecEvent xmlSecEvent = getCurrentEvent();
switch (xmlSecEvent.getEventType()) {
case ENTITY_REFERENCE:
return ((EntityReference) xmlSecEvent).getDeclaration().getReplacementText().length();
case DTD:
return ((DTD) xmlSecEvent).getDocumentTypeDeclaration().length();
case COMMENT:
return ((Comment) xmlSecEvent).getText().length();
case CDATA:
case SPACE:
case CHARACTERS:
return xmlSecEvent.asCharacters().getData().length();
default:
throw new IllegalStateException("Current state not TEXT");
}
}
示例4: testReplacing
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Test
public void testReplacing() throws Exception {
JAXPTestUtilities.tryRunWithTmpPermission(() -> {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.isReplacingEntityReferences", true);
StringReader sr = new StringReader(XML);
XMLEventReader reader = factory.createXMLEventReader(sr);
boolean sawUndef = false;
boolean sawDef = false;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
// System.out.println("Event: " + event);
if (event.isEntityReference()) {
EntityReference ref = (EntityReference) event;
if ("def".equals(ref.getName())) {
sawDef = true;
} else if ("undef".equals(ref.getName())) {
sawUndef = true;
} else {
throw new IllegalArgumentException("Unexpected entity name");
}
}
}
Assert.assertEquals(false, sawDef);
Assert.assertEquals(true, sawUndef);
reader.close();
}, new FilePermission("/tmp/this/does/not/exist/but/that/is/ok", "read"));
}
示例5: testNotReplacing
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Test
public void testNotReplacing() throws Exception {
JAXPTestUtilities.tryRunWithTmpPermission(() -> {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.isReplacingEntityReferences", false);
StringReader sr = new StringReader(XML);
XMLEventReader reader = factory.createXMLEventReader(sr);
boolean sawUndef = false;
boolean sawDef = false;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
// System.out.println("Event: " + event);
if (event.isEntityReference()) {
EntityReference ref = (EntityReference) event;
if ("def".equals(ref.getName())) {
sawDef = true;
} else if ("undef".equals(ref.getName())) {
sawUndef = true;
} else {
throw new IllegalArgumentException("Unexpected entity name");
}
}
}
Assert.assertEquals(true, sawDef);
Assert.assertEquals(true, sawUndef);
reader.close();
}, new FilePermission("/tmp/this/does/not/exist/but/that/is/ok", "read"));
}
示例6: testReplacing
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Test
public void testReplacing() throws Exception {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.isReplacingEntityReferences", true);
StringReader sr = new StringReader(XML);
XMLEventReader reader = factory.createXMLEventReader(sr);
boolean sawUndef = false;
boolean sawDef = false;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
// System.out.println("Event: " + event);
if (event.isEntityReference()) {
EntityReference ref = (EntityReference) event;
if ("def".equals(ref.getName())) {
sawDef = true;
} else if ("undef".equals(ref.getName())) {
sawUndef = true;
} else {
throw new IllegalArgumentException("Unexpected entity name");
}
}
}
Assert.assertEquals(false, sawDef);
Assert.assertEquals(true, sawUndef);
reader.close();
}
示例7: testNotReplacing
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Test
public void testNotReplacing() throws Exception {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty("javax.xml.stream.isReplacingEntityReferences", false);
StringReader sr = new StringReader(XML);
XMLEventReader reader = factory.createXMLEventReader(sr);
boolean sawUndef = false;
boolean sawDef = false;
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
// System.out.println("Event: " + event);
if (event.isEntityReference()) {
EntityReference ref = (EntityReference) event;
if ("def".equals(ref.getName())) {
sawDef = true;
} else if ("undef".equals(ref.getName())) {
sawUndef = true;
} else {
throw new IllegalArgumentException("Unexpected entity name");
}
}
}
Assert.assertEquals(true, sawDef);
Assert.assertEquals(true, sawUndef);
reader.close();
}
示例8: handleEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
private void handleEntityReference(EntityReference reference) throws SAXException {
if (getLexicalHandler() != null) {
getLexicalHandler().startEntity(reference.getName());
}
if (getLexicalHandler() != null) {
getLexicalHandler().endEntity(reference.getName());
}
}
示例9: getElementText
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@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();
}
示例10: createEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
if(location != null)event.setLocation(location);
return event;
}
示例11: createEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
return defaultImpl.createEntityReference(name, declaration);
}
示例12: createEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
return null;
}
示例13: parseInternal
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
protected void parseInternal() throws SAXException, XMLStreamException {
boolean documentStarted = false;
boolean documentEnded = false;
int elementDepth = 0;
while (this.reader.hasNext() && elementDepth >= 0) {
XMLEvent event = this.reader.nextEvent();
if (!event.isStartDocument() && !event.isEndDocument() && !documentStarted) {
handleStartDocument(event);
documentStarted = true;
}
switch (event.getEventType()) {
case XMLStreamConstants.START_DOCUMENT:
handleStartDocument(event);
documentStarted = true;
break;
case XMLStreamConstants.START_ELEMENT:
elementDepth++;
handleStartElement(event.asStartElement());
break;
case XMLStreamConstants.END_ELEMENT:
elementDepth--;
if (elementDepth >= 0) {
handleEndElement(event.asEndElement());
}
break;
case XMLStreamConstants.PROCESSING_INSTRUCTION:
handleProcessingInstruction((ProcessingInstruction) event);
break;
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.SPACE:
case XMLStreamConstants.CDATA:
handleCharacters(event.asCharacters());
break;
case XMLStreamConstants.END_DOCUMENT:
handleEndDocument();
documentEnded = true;
break;
case XMLStreamConstants.NOTATION_DECLARATION:
handleNotationDeclaration((NotationDeclaration) event);
break;
case XMLStreamConstants.ENTITY_DECLARATION:
handleEntityDeclaration((EntityDeclaration) event);
break;
case XMLStreamConstants.COMMENT:
handleComment((Comment) event);
break;
case XMLStreamConstants.DTD:
handleDtd((DTD) event);
break;
case XMLStreamConstants.ENTITY_REFERENCE:
handleEntityReference((EntityReference) event);
break;
}
}
if (documentStarted && !documentEnded) {
handleEndDocument();
}
}
示例14: createEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
public EntityReference createEntityReference(String name,
EntityDeclaration declaration)
{
return new EntityReferenceImpl(location, declaration, name);
}
示例15: createEntityReference
import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference( String name, EntityDeclaration declaration )
{
return delegate.createEntityReference( name, declaration );
}