当前位置: 首页>>代码示例>>Java>>正文


Java EntityReference类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:XMLSecurityStreamReader.java

示例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");
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:19,代码来源:XMLSecurityStreamReader.java

示例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");
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:19,代码来源:XMLSecurityStreamReader.java

示例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"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:Bug6555001.java

示例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"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:Bug6555001.java

示例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();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:31,代码来源:Bug6555001.java

示例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();
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:31,代码来源:Bug6555001.java

示例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());
	}

}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:StaxEventXMLReader.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:BaseXMLEventReader.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:XMLEventFactoryImpl.java

示例11: createEntityReference

import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return defaultImpl.createEntityReference(name, declaration);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:XMLEventFactoryWrapper.java

示例12: createEntityReference

import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:XMLEventFactoryImpl.java

示例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();
	}

}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:61,代码来源:StaxEventXMLReader.java

示例14: createEntityReference

import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
public EntityReference createEntityReference(String name,
                                             EntityDeclaration declaration)
{
  return new EntityReferenceImpl(location, declaration, name);
}
 
开发者ID:vilie,项目名称:javify,代码行数:6,代码来源:XMLEventFactoryImpl.java

示例15: createEntityReference

import javax.xml.stream.events.EntityReference; //导入依赖的package包/类
@Override
public EntityReference createEntityReference( String name, EntityDeclaration declaration )
{
    return delegate.createEntityReference( name, declaration );
}
 
开发者ID:werval,项目名称:werval,代码行数:6,代码来源:XMLEventFactoryImpl.java


注:本文中的javax.xml.stream.events.EntityReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。