javax.xml.stream.events.DTD Java Examples
The following examples show how to use
javax.xml.stream.events.DTD.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaxEventXMLReader.java From spring-analysis-note with MIT License | 5 votes |
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(); } }
Example #2
Source File: SupportDTDTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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()); } } }
Example #3
Source File: Issue41Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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()); } }
Example #4
Source File: Issue48Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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()); } }
Example #5
Source File: StaxEventXMLReader.java From lams with GNU General Public License v2.0 | 5 votes |
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(); } }
Example #6
Source File: StaxEventXMLReader.java From spring4-understanding with Apache License 2.0 | 5 votes |
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(); } }
Example #7
Source File: TestEventReader.java From woodstox with Apache License 2.0 | 5 votes |
/** * 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()); }
Example #8
Source File: StaxEventXMLReader.java From java-technology-stack with MIT License | 5 votes |
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(); } }
Example #9
Source File: StAXEncoder.java From exificient with MIT License | 4 votes |
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(); }
Example #10
Source File: StaxUtils.java From cxf with Apache License 2.0 | 4 votes |
public static void writeEvent(XMLEvent event, XMLStreamWriter writer) throws XMLStreamException { switch (event.getEventType()) { case XMLStreamConstants.START_ELEMENT: writeStartElementEvent(event, writer); break; case XMLStreamConstants.END_ELEMENT: writer.writeEndElement(); break; case XMLStreamConstants.ATTRIBUTE: writeAttributeEvent(event, writer); break; case XMLStreamConstants.ENTITY_REFERENCE: writer.writeEntityRef(((javax.xml.stream.events.EntityReference)event).getName()); break; case XMLStreamConstants.DTD: writer.writeDTD(((DTD)event).getDocumentTypeDeclaration()); break; case XMLStreamConstants.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 XMLStreamConstants.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 XMLStreamConstants.COMMENT: writer.writeComment(((javax.xml.stream.events.Comment)event).getText()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: writer.writeCharacters(event.asCharacters().getData()); break; case XMLStreamConstants.CDATA: writer.writeCData(event.asCharacters().getData()); break; case XMLStreamConstants.START_DOCUMENT: if (((StartDocument)event).encodingSet()) { writer.writeStartDocument(((StartDocument)event).getCharacterEncodingScheme(), ((StartDocument)event).getVersion()); } else { writer.writeStartDocument(((StartDocument)event).getVersion()); } break; case XMLStreamConstants.END_DOCUMENT: writer.writeEndDocument(); break; default: //shouldn't get here } }
Example #11
Source File: StaxEventXMLReader.java From spring-analysis-note with MIT License | 4 votes |
@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(); } }
Example #12
Source File: XMLEventFactoryWrapper.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public DTD createDTD(String dtd) { return defaultImpl.createDTD(dtd); }
Example #13
Source File: XMLEventFactoryImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public DTD createDTD(String dtd) { return null; }
Example #14
Source File: DTDEvent.java From hottub with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of DTDEvent */ public DTDEvent() { setEventType(DTD); }
Example #15
Source File: DTDEvent.java From hottub with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }
Example #16
Source File: DTDEvent.java From hottub with GNU General Public License v2.0 | 4 votes |
protected void init(){ setEventType(XMLEvent.DTD); }
Example #17
Source File: DTDEvent.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of DTDEvent */ public DTDEvent() { setEventType(DTD); }
Example #18
Source File: DTDEvent.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }
Example #19
Source File: DTDEvent.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected void init(){ setEventType(XMLEvent.DTD); }
Example #20
Source File: StaxEventXMLReader.java From spring4-understanding with Apache License 2.0 | 4 votes |
@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(); } }
Example #21
Source File: DTDEvent.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
protected void init(){ setEventType(XMLEvent.DTD); }
Example #22
Source File: DTDEvent.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of DTDEvent */ public DTDEvent() { setEventType(DTD); }
Example #23
Source File: DTDEvent.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }
Example #24
Source File: DTDEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }
Example #25
Source File: DTDEvent.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of DTDEvent */ public DTDEvent() { setEventType(DTD); }
Example #26
Source File: DTDEvent.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }
Example #27
Source File: DTDEvent.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
protected void init(){ setEventType(XMLEvent.DTD); }
Example #28
Source File: StaxEventXMLReader.java From java-technology-stack with MIT License | 4 votes |
@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(); } }
Example #29
Source File: DTDEvent.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Creates a new instance of DTDEvent */ public DTDEvent() { setEventType(DTD); }
Example #30
Source File: DTDEvent.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public DTDEvent(String dtd){ setEventType(DTD); _dtd = dtd; }