+
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public static void writeNormalizedNode(final NormalizedNode<?, ?> normalized,
+ final @Nullable NormalizedMetadata metadata,
+ final DOMResult result, final SchemaPath schemaPath,
+ final SchemaContext context) throws IOException, XMLStreamException {
+ if (metadata == null) {
+ writeNormalizedNode(normalized, result, schemaPath, context);
+ return;
+ }
+
+ final XMLStreamWriter writer = XML_FACTORY.createXMLStreamWriter(result);
+ try (
+ NormalizedNodeStreamWriter normalizedNodeStreamWriter =
+ XMLStreamNormalizedNodeStreamWriter.create(writer, context, schemaPath);
+ NormalizedMetadataWriter normalizedNodeWriter =
+ NormalizedMetadataWriter.forStreamWriter(normalizedNodeStreamWriter)
+ ) {
+ normalizedNodeWriter.write(normalized, metadata);
+ normalizedNodeWriter.flush();
+ } finally {
+ try {
+ if (writer != null) {
+ writer.close();
+ }
+ } catch (final Exception e) {
+ LOG.warn("Unable to close resource properly", e);
+ }
+ }
+ }
+
+ public static void writeFilter(final YangInstanceIdentifier query, final DOMResult result,
+ final SchemaPath schemaPath, final SchemaContext context) throws IOException, XMLStreamException {
+ if (query.isEmpty()) {
+ // No query at all
+ return;
+ }
+
+ final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
+ try {
+ try (NormalizedNodeStreamWriter writer =
+ XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, schemaPath)) {
+ final Iterator<PathArgument> it = query.getPathArguments().iterator();
+ final PathArgument first = it.next();
+ StreamingContext.fromSchemaAndQNameChecked(context, first.getNodeType()).streamToWriter(writer, first,
+ it);
+ }
+ } finally {
+ xmlWriter.close();
+ }
+ }