DocumentView implements Transform<Document, String>,
    HasElementsView<Document> { @Override public Optional<String> transform(Generator gen, Document model) { return Optional.of( Stream.of( gen.onEach(model.preamble()).map(s -> useIndent() ? Formatting.indent(s) : s).collect(joinIfNotEmpty(Formatting.nl(), "", "")), model.getXmlDeclaration().flatMap(gen::on).orElse(""), model.getDocType().flatMap(gen::on).orElse(""), transformElements(gen, model) ).filter(s -> !s.isEmpty()) .collect(joinIfNotEmpty(Formatting.nl(), "", "")) ); }  @Override boolean useIndent(); @Override Optional<String> transform(Generator gen, Document model);  }
@Test void transform() { final Generator generator = Generator.forJava(); final DocumentView documentView = new DocumentView(); final Document document = Document.of(); assertTrue(documentView.transform(generator, document).isPresent()); }