Java 类javax.xml.stream.events.EntityReference 实例源码

项目:xmlsec-gost    文件:XMLSecurityStreamReader.java   
@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");
    }
}
项目:xmlsec-gost    文件:XMLSecurityStreamReader.java   
@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");
    }
}
项目:xmlsec-gost    文件:XMLSecurityStreamReader.java   
@Override
public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
    XMLSecEvent xmlSecEvent = getCurrentEvent();
    switch (xmlSecEvent.getEventType()) {
        case ENTITY_REFERENCE:
            ((EntityReference) xmlSecEvent).getDeclaration().getReplacementText().getChars(sourceStart, sourceStart + length, target, targetStart);
            return length;
        case DTD:
            ((DTD) xmlSecEvent).getDocumentTypeDeclaration().getChars(sourceStart, sourceStart + length, target, targetStart);
            return length;
        case COMMENT:
            ((Comment) xmlSecEvent).getText().getChars(sourceStart, sourceStart + length, target, targetStart);
            return length;
        case CDATA:
        case SPACE:
        case CHARACTERS:
            xmlSecEvent.asCharacters().getData().getChars(sourceStart, sourceStart + length, target, targetStart);
            return length;
        default:
            throw new IllegalStateException("Current state not TEXT");
    }
}
项目:xmlsec-gost    文件:XMLSecurityStreamReader.java   
@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");
    }
}
项目:openjdk-jdk10    文件:Bug6555001.java   
@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"));
}
项目:openjdk-jdk10    文件:Bug6555001.java   
@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"));
}
项目:openjdk9    文件:Bug6555001.java   
@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();
}
项目:openjdk9    文件:Bug6555001.java   
@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();
}
项目:spring4-understanding    文件:StaxEventXMLReader.java   
private void handleEntityReference(EntityReference reference) throws SAXException {
    if (getLexicalHandler() != null) {
        getLexicalHandler().startEntity(reference.getName());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endEntity(reference.getName());
    }

}
项目:spring    文件:StaxEventXMLReader.java   
private void handleEntityReference(EntityReference reference) throws SAXException {
    if (getLexicalHandler() != null) {
        getLexicalHandler().startEntity(reference.getName());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endEntity(reference.getName());
    }

}
项目:class-guard    文件:StaxEventXMLReader.java   
private void handleEntityReference(EntityReference reference) throws SAXException {
    if (getLexicalHandler() != null) {
        getLexicalHandler().startEntity(reference.getName());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endEntity(reference.getName());
    }

}
项目:lams    文件:BaseXMLEventReader.java   
@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();
}
项目:openjdk-jdk10    文件:XMLEventFactoryImpl.java   
@Override
public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
    EntityReferenceEvent event =  new EntityReferenceEvent(name, entityDeclaration);
    if(location != null)event.setLocation(location);
    return event;
}
项目:openjdk-jdk10    文件:XMLEventFactoryWrapper.java   
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return defaultImpl.createEntityReference(name, declaration);
}
项目:openjdk-jdk10    文件:XMLEventFactoryImpl.java   
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return null;
}
项目:openjdk9    文件:XMLEventFactoryImpl.java   
@Override
public EntityReference createEntityReference(String name, EntityDeclaration declaration) {
    return null;
}
项目:spring4-understanding    文件:StaxEventXMLReader.java   
@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();
    }

}
项目:spring    文件:StaxEventXMLReader.java   
@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();
    }

}
项目:javify    文件:XMLEventFactoryImpl.java   
public EntityReference createEntityReference(String name,
                                             EntityDeclaration declaration)
{
  return new EntityReferenceImpl(location, declaration, name);
}
项目:jvm-stm    文件:XMLEventFactoryImpl.java   
public EntityReference createEntityReference(String name,
                                             EntityDeclaration declaration)
{
  return new EntityReferenceImpl(location, declaration, name);
}
项目:class-guard    文件:StaxEventXMLReader.java   
@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();
    }

}
项目:werval    文件:XMLEventFactoryImpl.java   
@Override
public EntityReference createEntityReference( String name, EntityDeclaration declaration )
{
    return delegate.createEntityReference( name, declaration );
}
项目:JamVM-PH    文件:XMLEventFactoryImpl.java   
public EntityReference createEntityReference(String name,
                                             EntityDeclaration declaration)
{
  return new EntityReferenceImpl(location, declaration, name);
}
项目:SplitCharater    文件:XMLEventFactoryImpl.java   
public EntityReference createEntityReference(String name,
        EntityDeclaration declaration) {
    return new EntityReferenceImpl(name, declaration, fLocation);
}
项目:SplitCharater    文件:StAXEventResultBuilder.java   
public void entityReference(EntityReference event)
        throws XMLStreamException {
    fEventWriter.add(event);
}
项目:classpath    文件:XMLEventFactoryImpl.java   
public EntityReference createEntityReference(String name,
                                             EntityDeclaration declaration)
{
  return new EntityReferenceImpl(location, declaration, name);
}
项目:javify    文件:XMLEventFactory.java   
/**
 * Create an entity reference event.
 */
public abstract EntityReference createEntityReference(String name,
                                                      EntityDeclaration declaration);
项目:jvm-stm    文件:XMLEventFactory.java   
/**
 * Create an entity reference event.
 */
public abstract EntityReference createEntityReference(String name,
                                                      EntityDeclaration declaration);
项目:JamVM-PH    文件:XMLEventFactory.java   
/**
 * Create an entity reference event.
 */
public abstract EntityReference createEntityReference(String name,
                                                      EntityDeclaration declaration);
项目:SplitCharater    文件:StAXStreamResultBuilder.java   
public void entityReference(EntityReference event) throws XMLStreamException {
    fStreamWriter.writeEntityRef(event.getName());

}
项目:classpath    文件:XMLEventFactory.java   
/**
 * Create an entity reference event.
 */
public abstract EntityReference createEntityReference(String name,
                                                      EntityDeclaration declaration);
项目:SplitCharater    文件:StAXDocumentHandler.java   
public void entityReference(EntityReference event) throws XMLStreamException;