use of javax.xml.stream.events.XMLEvent in project core by weld.
the class BeansXmlStreamParser method handleFilter.
private void handleFilter(StartElement filterElement, XMLEventReader reader, Consumer<XmlMetadata<Filter>> consumer) throws XMLStreamException {
String name = getAttribute(filterElement, NAME_ATTRIBUTE_NAME);
String pattern = name != null ? null : getAttribute(filterElement, PATTERN_ATTRIBUTE_NAME);
if (name != null || pattern != null) {
List<Metadata<SystemPropertyActivation>> systemPropertyActivations = new LinkedList<>();
List<Metadata<ClassAvailableActivation>> classAvailableActivations = new LinkedList<>();
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (isEnd(event, EXCLUDE, SCANNING_URIS) || isEnd(event, INCLUDE, SCANNING_URIS)) {
Filter filter;
if (filterElement.getName().getNamespaceURI().equals(WELD_URI)) {
filter = new WeldFilterImpl(name, systemPropertyActivations, classAvailableActivations, pattern);
} else {
filter = new FilterImpl(name, systemPropertyActivations, classAvailableActivations);
}
consumer.accept(new XmlMetadata<Filter>(filterElement.getName().toString(), filter, beansXml, filterElement.getLocation().getLineNumber()));
return;
} else if (event.isStartElement()) {
StartElement element = (StartElement) event;
if (isStartElement(element, IF_CLASS_AVAILABLE, SCANNING_URIS)) {
classAvailable(element, classAvailableActivations::add, false);
} else if (isStartElement(element, IF_CLASS_NOT_AVAILABLE, SCANNING_URIS)) {
classAvailable(element, classAvailableActivations::add, true);
} else if (isStartElement(element, IF_SYSTEM_PROPERTY, SCANNING_URIS)) {
systemProperty(element, systemPropertyActivations::add);
}
}
}
}
}
use of javax.xml.stream.events.XMLEvent in project core by weld.
the class BeansXmlStreamParser method parse.
public BeansXml parse() {
if (beansXml == null) {
throw XmlLogger.LOG.loadError("unknown", null);
}
try (InputStream in = beansXml.openStream()) {
if (in.available() == 0) {
// The file is just acting as a marker file
return EMPTY_BEANS_XML;
}
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLEventReader reader = factory.createXMLEventReader(in);
StartElement element = nextStartElement(reader, BEANS, JAVAEE_URIS);
if (element != null) {
parseBeans(element);
while (reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if (isEnd(event, BEANS)) {
break;
} else if (isStartElement(event, ALTERNATIVES)) {
parseAlternatives(reader, event);
} else if (isStartElement(event, INTERCEPTORS)) {
parseInterceptors(reader, event);
} else if (isStartElement(event, DECORATORS)) {
parseDecorators(reader, event);
} else if (isStartElement(event, SCAN, SCANNING_URIS)) {
parseScan(reader, event);
} else if (isStartElement(event, TRIM)) {
isTrimmed = true;
}
}
}
reader.close();
} catch (IOException e) {
throw XmlLogger.LOG.loadError(beansXml, e);
} catch (XMLStreamException e) {
throw XmlLogger.LOG.parsingError(beansXml, e);
}
return new BeansXmlImpl(orEmpty(selectedAlternatives), orEmpty(selectedAlternativeStereotypes), orEmpty(enabledDecorators), orEmpty(enabledInterceptors), new ScanningImpl(orEmpty(includes), orEmpty(excludes)), beansXml, discoveryMode, version, isTrimmed);
}
use of javax.xml.stream.events.XMLEvent in project santuario-java by apache.
the class XMLSecEventTest method testwWiteAsEncodedUnicode.
@Test
public void testwWiteAsEncodedUnicode() throws Exception {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
Deque<XMLSecEvent> xmlSecEventDeque = new ArrayDeque<XMLSecEvent>();
do {
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
xmlStreamReader.next();
} while (xmlStreamReader.hasNext());
// EndDocumentEvent
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlSecEventDeque, 0);
XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
final StringWriter stdWriter = new StringWriter();
final StringWriter secWriter = new StringWriter();
while (xmlEventReader.hasNext()) {
XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
stdXmlEvent.writeAsEncodedUnicode(stdWriter);
secXmlEvent.writeAsEncodedUnicode(secWriter);
}
Assert.assertEquals(secWriter.toString(), stdWriter.toString());
}
use of javax.xml.stream.events.XMLEvent in project santuario-java by apache.
the class XMLSecurityEventWriterTest method testConformness.
@Test
public void testConformness() throws Exception {
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
StringWriter secStringWriter = new StringWriter();
XMLStreamWriter secXmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(secStringWriter);
XMLSecurityEventWriter xmlSecurityEventWriter = new XMLSecurityEventWriter(secXmlStreamWriter);
StringWriter stdStringWriter = new StringWriter();
XMLEventWriter stdXmlEventWriter = xmlOutputFactory.createXMLEventWriter(stdStringWriter);
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
while (xmlStreamReader.hasNext()) {
XMLEvent xmlEvent = XMLSecEventFactory.allocate(xmlStreamReader, null);
xmlSecurityEventWriter.add(xmlEvent);
stdXmlEventWriter.add(xmlEvent);
xmlStreamReader.next();
}
xmlSecurityEventWriter.close();
stdXmlEventWriter.close();
XMLAssert.assertXMLEqual(stdStringWriter.toString(), secStringWriter.toString());
}
use of javax.xml.stream.events.XMLEvent in project santuario-java by apache.
the class XMLSecurityEventReaderTest method testIndex.
@Test
public void testIndex() throws Exception {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
Deque<XMLSecEvent> xmlSecEventDeque = new ArrayDeque<XMLSecEvent>();
do {
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
xmlStreamReader.next();
} while (xmlStreamReader.hasNext());
// EndDocumentEvent
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
int skip = 100;
XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlSecEventDeque, skip);
XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
int currentIndex = 0;
while (xmlEventReader.hasNext()) {
XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
if (currentIndex++ < skip) {
continue;
}
XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
Assert.assertEquals(stdXmlEvent.getEventType(), secXmlEvent.getEventType());
XMLEvent stdPeekedXMLEvent = xmlEventReader.peek();
XMLEvent secPeekedXMLEvent = xmlSecurityEventReader.peek();
if (stdPeekedXMLEvent == null) {
Assert.assertNull(secPeekedXMLEvent);
} else {
Assert.assertEquals(stdPeekedXMLEvent.getEventType(), secPeekedXMLEvent.getEventType());
}
}
Assert.assertFalse(xmlEventReader.hasNext());
Assert.assertFalse(xmlSecurityEventReader.hasNext());
}
Aggregations