• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DTD类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.xml.stream.events.DTD的典型用法代码示例。如果您正苦于以下问题:Java DTD类的具体用法?Java DTD怎么用?Java DTD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DTD类属于javax.xml.stream.events包,在下文中一共展示了DTD类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getText

import javax.xml.stream.events.DTD; //导入依赖的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.DTD; //导入依赖的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.DTD; //导入依赖的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: DisplayEntities

import javax.xml.stream.events.DTD; //导入依赖的package包/类
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());
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:SupportDTDTest.java


示例5: testDTDEvent

import javax.xml.stream.events.DTD; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Issue41Test.java


示例6: testDTDEvent

import javax.xml.stream.events.DTD; //导入依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Issue48Test.java


示例7: handleDtd

import javax.xml.stream.events.DTD; //导入依赖的package包/类
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();
	}

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


示例8: testDtdNotations

import javax.xml.stream.events.DTD; //导入依赖的package包/类
/**
 * 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());
}
 
开发者ID:FasterXML,项目名称:woodstox,代码行数:37,代码来源:TestEventReader.java


示例9: addDTD

import javax.xml.stream.events.DTD; //导入依赖的package包/类
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"));
}
 
开发者ID:StanLivitski,项目名称:HTMLtoc,代码行数:15,代码来源:Transformer.java


示例10: DTDEvent

import javax.xml.stream.events.DTD; //导入依赖的package包/类
/** Creates a new instance of DTDEvent */
public DTDEvent() {
    setEventType(DTD);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:DTDEvent.java


示例11: init

import javax.xml.stream.events.DTD; //导入依赖的package包/类
protected void init(){
    setEventType(XMLEvent.DTD);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:DTDEvent.java


示例12: init

import javax.xml.stream.events.DTD; //导入依赖的package包/类
protected final void init() {
    setEventType(XMLEvent.DTD);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:DTDEvent.java


示例13: createDTD

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


示例14: createDTD

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


示例15: parseInternal

import javax.xml.stream.events.DTD; //导入依赖的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


示例16: add

import javax.xml.stream.events.DTD; //导入依赖的package包/类
public void add(XMLEvent event)
  throws XMLStreamException
{
  QName name;
  String uri;
  switch (event.getEventType())
    {
    case XMLStreamConstants.START_ELEMENT:
      StartElement startElement = event.asStartElement();
      name = startElement.getName();
      uri = name.getNamespaceURI();
      if (uri != null && !"".equals(uri))
        writer.writeStartElement(name.getPrefix(), name.getLocalPart(), uri);
      else
        writer.writeStartElement(name.getLocalPart());
      break;
    case XMLStreamConstants.END_ELEMENT:
      writer.writeEndElement();
      break;
    case XMLStreamConstants.ATTRIBUTE:
      Attribute attribute = (Attribute) event;
      name = attribute.getName();
      uri = name.getNamespaceURI();
      if (uri != null && !"".equals(uri))
        writer.writeAttribute(name.getPrefix(), uri, name.getLocalPart(),
                              attribute.getValue());
      else
        writer.writeAttribute(name.getLocalPart(), attribute.getValue());
      break;
    case XMLStreamConstants.NAMESPACE:
      Namespace namespace = (Namespace) event;
      uri = namespace.getNamespaceURI();
      writer.writeNamespace(namespace.getPrefix(), uri);
      break;
    case XMLStreamConstants.PROCESSING_INSTRUCTION:
      ProcessingInstruction pi = (ProcessingInstruction) event;
      String data = pi.getData();
      if (data == null)
        writer.writeProcessingInstruction(pi.getTarget());
      else
        writer.writeProcessingInstruction(pi.getTarget(), data);
      break;
    case XMLStreamConstants.COMMENT:
      Comment comment = (Comment) event;
      writer.writeComment(comment.getText());
      break;
    case XMLStreamConstants.START_DOCUMENT:
      StartDocument startDocument = (StartDocument) event;
      writer.writeStartDocument(startDocument.getVersion());
      break;
    case XMLStreamConstants.END_DOCUMENT:
      writer.writeEndDocument();
      break;
    case XMLStreamConstants.DTD:
      DTD dtd = (DTD) event;
      writer.writeDTD(dtd.getDocumentTypeDeclaration());
      break;
    case XMLStreamConstants.CHARACTERS:
    case XMLStreamConstants.SPACE:
      Characters characters = event.asCharacters();
      writer.writeCharacters(characters.getData());
      break;
    case XMLStreamConstants.CDATA:
      Characters cdata = event.asCharacters();
      writer.writeCData(cdata.getData());
      break;
    }
}
 
开发者ID:vilie,项目名称:javify,代码行数:69,代码来源:XMLEventWriterImpl.java


示例17: getEventType

import javax.xml.stream.events.DTD; //导入依赖的package包/类
public int getEventType()
{
  return DTD;
}
 
开发者ID:vilie,项目名称:javify,代码行数:5,代码来源:DTDImpl.java


示例18: createDTD

import javax.xml.stream.events.DTD; //导入依赖的package包/类
public DTD createDTD(String dtd)
{
  return new DTDImpl(location, dtd, null,
                     Collections.EMPTY_LIST,
                     Collections.EMPTY_LIST);
}
 
开发者ID:vilie,项目名称:javify,代码行数:7,代码来源:XMLEventFactoryImpl.java


示例19: encode

import javax.xml.stream.events.DTD; //导入依赖的package包/类
public void encode(XMLStreamReader xmlStream) throws XMLStreamException,
		EXIException, IOException {

	// StartDocument should be initial state
	assert (xmlStream.getEventType() == XMLStreamConstants.START_DOCUMENT);

	writeStartDocument();

	while (xmlStream.hasNext()) {
		int event = xmlStream.next();
		switch (event) {
		case XMLStreamConstants.START_DOCUMENT:
			// should have happened beforehand
			throw new EXIException("Unexpected START_DOCUMENT event");
		case XMLStreamConstants.END_DOCUMENT:
			this.writeEndDocument();
			break;
		case XMLStreamConstants.START_ELEMENT:
			QName qn = xmlStream.getName();
			String pfx = qn.getPrefix();
			writeStartElement(pfx, qn.getLocalPart(), qn.getNamespaceURI());
			// parse NS declarations
			int nsCnt = xmlStream.getNamespaceCount();
			for (int i = 0; i < nsCnt; i++) {
				String nsPfx = xmlStream.getNamespacePrefix(i);
				nsPfx = nsPfx == null ? Constants.XML_DEFAULT_NS_PREFIX
						: nsPfx;
				String nsUri = xmlStream.getNamespaceURI(i);
				this.writeNamespace(nsPfx, nsUri);
			}
			// parse attributes
			int atCnt = xmlStream.getAttributeCount();
			for (int i = 0; i < atCnt; i++) {
				QName atQname = xmlStream.getAttributeName(i);
				this.writeAttribute(atQname.getPrefix(),
						atQname.getNamespaceURI(), atQname.getLocalPart(),
						xmlStream.getAttributeValue(i));
			}

			break;
		case XMLStreamConstants.END_ELEMENT:
			writeEndElement();
			break;
		case XMLStreamConstants.NAMESPACE:
			break;
		case XMLStreamConstants.CHARACTERS:
			this.writeCharacters(xmlStream.getTextCharacters(),
					xmlStream.getTextStart(), xmlStream.getTextLength());
			break;
		case XMLStreamConstants.SPACE:
			// @SuppressWarnings("unused")
			String ignorableSpace = xmlStream.getText();
			writeCharacters(ignorableSpace);
			break;
		case XMLStreamConstants.ATTRIBUTE:
			// @SuppressWarnings("unused")
			// int attsX = xmlStream.getAttributeCount();
			break;
		case XMLStreamConstants.PROCESSING_INSTRUCTION:
			this.writeProcessingInstruction(xmlStream.getPITarget(),
					xmlStream.getPIData());
			break;
		case XMLStreamConstants.COMMENT:
			this.writeComment(xmlStream.getText());
			break;
		case XMLStreamConstants.DTD:
			// TODO DTD
			break;
		case XMLStreamConstants.ENTITY_REFERENCE:
			// TODO ER
			break;
		default:
			System.out.println("Event '" + event + "' not supported!");
		}
	}

	// this.flush();
}
 
开发者ID:EXIficient,项目名称:exificient,代码行数:79,代码来源:StAXEncoder.java


示例20: writeEvent

import javax.xml.stream.events.DTD; //导入依赖的package包/类
public static void writeEvent(XMLEvent event, XMLStreamWriter writer)
    throws XMLStreamException {

    switch (event.getEventType()) {
    case XMLEvent.START_ELEMENT:
        writeStartElementEvent(event, writer);
        break;
    case XMLEvent.END_ELEMENT:
        writer.writeEndElement();
        break;
    case XMLEvent.ATTRIBUTE: 
        writeAttributeEvent(event, writer);
        break;
    case XMLEvent.ENTITY_REFERENCE:
        writer.writeEntityRef(((javax.xml.stream.events.EntityReference)event).getName());
        break;
    case XMLEvent.DTD:
        writer.writeDTD(((DTD)event).getDocumentTypeDeclaration());
        break;
    case XMLEvent.PROCESSING_INSTRUCTION:
        if (((javax.xml.stream.events.ProcessingInstruction)event).getData() != null) {
            writer.writeProcessingInstruction(
                ((javax.xml.stream.events.ProcessingInstruction)event).getTarget(), 
                ((javax.xml.stream.events.ProcessingInstruction)event).getData());
        } else {
            writer.writeProcessingInstruction(
                ((javax.xml.stream.events.ProcessingInstruction)event).getTarget());
        }
        break;
    case XMLEvent.NAMESPACE:
        if (((Namespace)event).isDefaultNamespaceDeclaration()) {
            writer.writeDefaultNamespace(((Namespace)event).getNamespaceURI());
            writer.setDefaultNamespace(((Namespace)event).getNamespaceURI());
        } else {
            writer.writeNamespace(((Namespace)event).getPrefix(),
                                  ((Namespace)event).getNamespaceURI());
            writer.setPrefix(((Namespace)event).getPrefix(),
                             ((Namespace)event).getNamespaceURI()); 
        }
        break;
    case XMLEvent.COMMENT:
        writer.writeComment(((javax.xml.stream.events.Comment)event).getText());
        break;
    case XMLEvent.CHARACTERS:
    case XMLEvent.SPACE:
        writer.writeCharacters(event.asCharacters().getData());
        break;
    case XMLEvent.CDATA:
        writer.writeCData(event.asCharacters().getData());
        break;
    case XMLEvent.START_DOCUMENT:
        if (((StartDocument)event).encodingSet()) {
            writer.writeStartDocument(((StartDocument)event).getCharacterEncodingScheme(),
                                      ((StartDocument)event).getVersion());

        } else {
            writer.writeStartDocument(((StartDocument)event).getVersion());
        }
        break;
    case XMLEvent.END_DOCUMENT:
        writer.writeEndDocument();
        break;
    default:
        //shouldn't get here
    }
}
 
开发者ID:beemsoft,项目名称:techytax-zk,代码行数:67,代码来源:StaxUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ResponseWrapper类代码示例发布时间:2022-05-20
下一篇:
Java VoiceStatus类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap