DocGenerator { public void generate() throws Exception { this.repository = unmarshal(inputStream); pathManager = getPathManager(outputRootDir); final Path baseOutputPath = pathManager.makeRootPath(outputRootDir); createCss(baseOutputPath); generateMain(baseOutputPath, getTitle()); generateMetadata(baseOutputPath, repository, repository.getMetadata().getAny()); final Path datatypesOutputPath = pathManager.makeDirectory(baseOutputPath.resolve("datatypes")); generateDatatypeList(datatypesOutputPath, repository.getDatatypes().getDatatype()); repository.getDatatypes().getDatatype().forEach(d -> { try { generateDatatype(datatypesOutputPath, d); } catch (final Exception e) { throw new RuntimeException(e); } }); final Path fieldsOutputPath = pathManager.makeDirectory(baseOutputPath.resolve("fields")); final List<FieldType> sortedFieldList = repository.getFields().getField().stream() .sorted(Comparator.comparing(FieldType::getName)).collect(Collectors.toList()); generateFieldsList(fieldsOutputPath, sortedFieldList); repository.getFields().getField().forEach(f -> { try { generateFieldDetail(fieldsOutputPath, f); } catch (final Exception e) { throw new RuntimeException(e); } }); final List<CodeSetType> allCodeSets = repository.getCodeSets().getCodeSet(); generateCodeSetList(datatypesOutputPath, allCodeSets.stream() .sorted(Comparator.comparing(CodeSetType::getName)).collect(Collectors.toList())); repository.getCodeSets().getCodeSet().forEach(cs -> { try { generateCodeSetDetail(datatypesOutputPath, cs); } catch (final Exception e) { throw new RuntimeException(e); } }); final Path messagesDocPath = pathManager.makeDirectory(baseOutputPath.resolve("messages")); final Path messagesImgPath = pathManager.makeDirectory(messagesDocPath.resolve("img")); final Optional<Categories> optCategories = Optional.ofNullable(repository.getCategories()); final List<CategoryType> sortedCategoryList = optCategories.orElse(new Categories()).getCategory().stream() .filter(c -> c.getComponentType() == CatComponentTypeT.MESSAGE).sorted((o1, o2) -> { final String sectionValue1 = o1.getSection() != null ? o1.getSection() : ""; final String sectionValue2 = o2.getSection() != null ? o2.getSection() : ""; int retv = sectionValue1.compareTo(sectionValue2); if (retv == 0) { retv = o1.getName().compareTo(o2.getName()); } return retv; }).collect(Collectors.toList()); generateCategories(messagesDocPath, "Message Categories", sortedCategoryList); final List<MessageType> sortedMessageList = repository.getMessages().getMessage().stream().sorted(Comparator.comparing(MessageType::getName).thenComparing(MessageType::getScenario)).collect(Collectors.toList()); final Optional<Actors> actors = Optional.ofNullable(repository.getActors()); final List<ActorType> actorList = actors.orElse(new Actors()).getActorOrFlow().stream().filter(af -> af instanceof ActorType) .map(af -> (ActorType) af).collect(Collectors.toList()); generateActorsList(messagesDocPath, actorList); actorList.forEach(a -> { try { generateActorDetail(messagesDocPath, messagesImgPath, a); } catch (final Exception e) { throw new RuntimeException(e); } }); final List<FlowType> flowList = actors.orElse(new Actors()).getActorOrFlow().stream() .filter(af -> af instanceof FlowType).map(af -> (FlowType) af).collect(Collectors.toList()); generateFlowsList(messagesDocPath, flowList); flowList.forEach(f -> { try { generateFlowDetail(messagesDocPath, f); generateMessageListByFlow(messagesDocPath, f, sortedMessageList); } catch (final Exception e) { throw new RuntimeException(e); } }); generateAllMessageList(messagesDocPath, sortedMessageList); sortedCategoryList.forEach(c -> { try { generateMessageListByCategory(messagesDocPath, c, sortedMessageList); } catch (final Exception e) { throw new RuntimeException(e); } }); final List<ComponentType> componentList = repository.getComponents().getComponent(); final List<ComponentType> sortedComponentList = componentList.stream().sorted(Comparator.comparing(ComponentType::getName).thenComparing(ComponentType::getScenario)).collect(Collectors.toList()); generateAllComponentsList(messagesDocPath, sortedComponentList); componentList.forEach(c -> { try { generateComponentDetail(messagesDocPath, c); } catch (final Exception e) { throw new RuntimeException(e); } }); final List<GroupType> groupList = repository.getGroups().getGroup(); final List<GroupType> sortedGroupList = groupList.stream().sorted(Comparator.comparing(GroupType::getName).thenComparing(GroupType::getScenario)).collect(Collectors.toList()); generateAllGroupsList(messagesDocPath, sortedGroupList); groupList.forEach(c -> { try { generateGroupDetail(messagesDocPath, c); } catch (final Exception e) { throw new RuntimeException(e); } }); repository.getMessages().getMessage().forEach(m -> { try { generateMessageDetail(messagesDocPath, messagesImgPath, m); } catch (final Exception e) { throw new RuntimeException(e); } }); pathManager.close(); } DocGenerator(final InputStream inputStream, final String outputRootDir, final PrintStream errorStream); static void main(final String[] args); void generate();  }
@Test public void generateFile() throws Exception { DocGenerator generator = new DocGenerator( Thread.currentThread().getContextClassLoader().getResourceAsStream("mit_2016.xml"), "target/test/doc", new PrintStream("target/test/doc-err.txt")); generator.generate(); }
@Test public void generateZip() throws Exception { DocGenerator generator = new DocGenerator( Thread.currentThread().getContextClassLoader().getResourceAsStream("mit_2016.xml"), "target/test/doc.zip", new PrintStream("target/test/zip-err.txt")); generator.generate(); }