java类javax.xml.stream.events.DTD的实例源码

XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 22 收藏 0 点赞 0 评论 0
@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");
    }
}
XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 23 收藏 0 点赞 0 评论 0
@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");
    }
}
XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 23 收藏 0 点赞 0 评论 0
@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");
    }
}
XMLSecurityStreamReader.java 文件源码 项目:xmlsec-gost 阅读 18 收藏 0 点赞 0 评论 0
@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");
    }
}
SupportDTDTest.java 文件源码 项目:openjdk-jdk10 阅读 27 收藏 0 点赞 0 评论 0
void DisplayEntities(DTD event) {
    List entities = event.getEntities();
    if (entities == null) {
        _hasEntityDelaration = false;
        print("No entity found.");
    } else {
        _hasEntityDelaration = true;
        for (int i = 0; i < entities.size(); i++) {
            EntityDeclaration entity = (EntityDeclaration) entities.get(i);
            print(entity.getName());
        }
    }

}
Issue41Test.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        writeAsEncodedUnicode(dtd);
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            writeAsEncodedUnicode((XMLEvent) entities.get(0));
            writeAsEncodedUnicode((XMLEvent) entities.get(1));
            writeAsEncodedUnicode((XMLEvent) entities.get(2));
        }

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            writeAsEncodedUnicode((XMLEvent) notations.get(0));
            writeAsEncodedUnicode((XMLEvent) notations.get(1));
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Issue48Test.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            Assert.assertEquals(entities.size(), 3);
        }
        // Let's also verify they are all of right type...
        testListElems(entities, EntityDeclaration.class);

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            Assert.assertEquals(notations.size(), 2);
        }
        // Let's also verify they are all of right type...
        testListElems(notations, NotationDeclaration.class);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
SupportDTDTest.java 文件源码 项目:openjdk9 阅读 25 收藏 0 点赞 0 评论 0
void DisplayEntities(DTD event) {
    List entities = event.getEntities();
    if (entities == null) {
        _hasEntityDelaration = false;
        print("No entity found.");
    } else {
        _hasEntityDelaration = true;
        for (int i = 0; i < entities.size(); i++) {
            EntityDeclaration entity = (EntityDeclaration) entities.get(i);
            print(entity.getName());
        }
    }

}
Issue41Test.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        writeAsEncodedUnicode(dtd);
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            writeAsEncodedUnicode((XMLEvent) entities.get(0));
            writeAsEncodedUnicode((XMLEvent) entities.get(1));
            writeAsEncodedUnicode((XMLEvent) entities.get(2));
        }

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            writeAsEncodedUnicode((XMLEvent) notations.get(0));
            writeAsEncodedUnicode((XMLEvent) notations.get(1));
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Issue48Test.java 文件源码 项目:openjdk9 阅读 24 收藏 0 点赞 0 评论 0
/**
 * DTDEvent instances constructed via event reader are missing the notation
 * and entity declaration information
 */
@Test
public void testDTDEvent() {
    String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n"
            + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n"
            + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root />";

    try {
        XMLEventReader er = getReader(XML);
        XMLEvent evt = er.nextEvent(); // StartDocument
        evt = er.nextEvent(); // DTD
        if (evt.getEventType() != XMLStreamConstants.DTD) {
            Assert.fail("Expected DTD event");
        }
        DTD dtd = (DTD) evt;
        List entities = dtd.getEntities();
        if (entities == null) {
            Assert.fail("No entity found. Expected 3.");
        } else {
            Assert.assertEquals(entities.size(), 3);
        }
        // Let's also verify they are all of right type...
        testListElems(entities, EntityDeclaration.class);

        List notations = dtd.getNotations();
        if (notations == null) {
            Assert.fail("No notation found. Expected 2.");
        } else {
            Assert.assertEquals(notations.size(), 2);
        }
        // Let's also verify they are all of right type...
        testListElems(notations, NotationDeclaration.class);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
StaxEventXMLReader.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
private void handleDtd(DTD dtd) throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = dtd.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }

}
StaxEventXMLReader.java 文件源码 项目:spring 阅读 22 收藏 0 点赞 0 评论 0
private void handleDtd(DTD dtd) throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = dtd.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }

}
StaxEventXMLReader.java 文件源码 项目:class-guard 阅读 20 收藏 0 点赞 0 评论 0
private void handleDtd(DTD dtd) throws SAXException {
    if (getLexicalHandler() != null) {
        javax.xml.stream.Location location = dtd.getLocation();
        getLexicalHandler().startDTD(null, location.getPublicId(), location.getSystemId());
    }
    if (getLexicalHandler() != null) {
        getLexicalHandler().endDTD();
    }

}
TestEventReader.java 文件源码 项目:woodstox 阅读 20 收藏 0 点赞 0 评论 0
/**
 * As of Stax 3.0 (Woodstox 4.0+), there is additional info for
 * NotationDeclarations (base URI). Let's verify it gets properly
 * populated.
 */
public void testDtdNotations()
    throws Exception
{
    final String URI = "http://test";

    /* Ok. And here we should just check that we do not get 2 adjacent
     * separate Characters event. We can try to trigger this by long
     * segment and a set of char entities...
     */
    final String XML = "<?xml version='1.0'?>"
        +"<!DOCTYPE root [\n"
        +"<!ELEMENT root EMPTY>\n"
        +"<!NOTATION not PUBLIC 'some-public-id'>\n"
        +"]>"
        +"<root/>";

    // Need to disable coalescing though for test to work:
    XMLEventReader2 er = getReader(XML, false);
    // Need to set Base URI; can do it for factory or instance
    er.setProperty(WstxInputProperties.P_BASE_URL, new URL(URI));
    assertTrue(er.nextEvent().isStartDocument());
    XMLEvent evt = er.nextEvent(); // DTD
    assertTokenType(DTD, evt.getEventType());

    DTD dtd = (DTD) evt;
    List<?> nots = dtd.getNotations();
    assertEquals(1, nots.size());
    NotationDeclaration2 notDecl = (NotationDeclaration2) nots.get(0);

    assertEquals(URI, notDecl.getBaseURI());
}
Transformer.java 文件源码 项目:HTMLtoc 阅读 27 收藏 0 点赞 0 评论 0
protected void addDTD(StartElement event) throws XMLStreamException
{
 QName qName = ((StartElement)event).getName();
 String name = qName.getPrefix();
 if (null == name)
  name = "";
 else if (0 < name.length())
  name += ':';
 name += qName.getLocalPart();
 XMLEventFactory eventFactory = getXMLEventFactory();
 DTD dtdEvent = eventFactory.createDTD("<!DOCTYPE " + name + '>');
 super.add(dtdEvent);
 super.add(eventFactory.createCharacters("\n"));
}
DTDEvent.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
/** Creates a new instance of DTDEvent */
public DTDEvent() {
    setEventType(DTD);
}
DTDEvent.java 文件源码 项目:OpenJSharp 阅读 25 收藏 0 点赞 0 评论 0
public DTDEvent(String dtd){
    setEventType(DTD);
    _dtd = dtd;
}
DTDEvent.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
protected void init(){
    setEventType(XMLEvent.DTD);
}
DTDEvent.java 文件源码 项目:openjdk-jdk10 阅读 25 收藏 0 点赞 0 评论 0
/** Creates a new instance of DTDEvent */
public DTDEvent() {
    setEventType(DTD);
}
DTDEvent.java 文件源码 项目:openjdk-jdk10 阅读 24 收藏 0 点赞 0 评论 0
public DTDEvent(String dtd){
    setEventType(DTD);
    _dtd = dtd;
}
DTDEvent.java 文件源码 项目:openjdk-jdk10 阅读 21 收藏 0 点赞 0 评论 0
protected final void init() {
    setEventType(XMLEvent.DTD);
}
XMLEventFactoryWrapper.java 文件源码 项目:openjdk-jdk10 阅读 26 收藏 0 点赞 0 评论 0
@Override
public DTD createDTD(String dtd) {
    return defaultImpl.createDTD(dtd);
}
XMLEventFactoryImpl.java 文件源码 项目:openjdk-jdk10 阅读 23 收藏 0 点赞 0 评论 0
@Override
public DTD createDTD(String dtd) {
    return null;
}
DTDEvent.java 文件源码 项目:openjdk9 阅读 32 收藏 0 点赞 0 评论 0
/** Creates a new instance of DTDEvent */
public DTDEvent() {
    setEventType(DTD);
}
DTDEvent.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
public DTDEvent(String dtd){
    setEventType(DTD);
    _dtd = dtd;
}
DTDEvent.java 文件源码 项目:openjdk9 阅读 25 收藏 0 点赞 0 评论 0
protected void init(){
    setEventType(XMLEvent.DTD);
}
XMLEventFactoryImpl.java 文件源码 项目:openjdk9 阅读 21 收藏 0 点赞 0 评论 0
@Override
public DTD createDTD(String dtd) {
    return null;
}
StaxEventXMLReader.java 文件源码 项目:spring4-understanding 阅读 21 收藏 0 点赞 0 评论 0
@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();
    }

}
DTDEvent.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 22 收藏 0 点赞 0 评论 0
/** Creates a new instance of DTDEvent */
public DTDEvent() {
    setEventType(DTD);
}
DTDEvent.java 文件源码 项目:lookaside_java-1.8.0-openjdk 阅读 31 收藏 0 点赞 0 评论 0
public DTDEvent(String dtd){
    setEventType(DTD);
    _dtd = dtd;
}


问题


面经


文章

微信
公众号

扫码关注公众号