// 主にnodamushiがEclipseから起動してなんやかんややってるときのメソッド。 private static void testMain() throws Exception { String file = "testdataMain.tex"; LamuriyanEngine e = new LamuriyanEngine(file, "testdata"); e.setFileSearchDirectories(Paths.get(".")); e.setInitFiles(Paths.get("testdata\\_init_test.tex")); e.evaluate(); // Lamuriyanの変換完了 RootDocument root = e.getDocument(); // コンバート HTMLConverter hcon = new HTMLConverter(root, new File("testdata\\convsetting.hcv").toPath()); hcon.convert(); List<PageLinkObject> plos = hcon.refs(); Document document = hcon.getDocument(); NodeList chapters = document.getElementsByTagName("chapter"); ArrayList<Element> chapterlist = new ArrayList<>(); for (int i = chapters.getLength() - 1; i >= 0; i--) { Node node = chapters.item(i); node.getParentNode().removeChild(node); chapterlist.add(0, (Element) node); Element el = (Element) node; hcon.fixLink(el, "index_chapter" + (i + 1) + ".html"); } NodeList headcontentlist = document.getElementsByTagName("headcontent"); StringBuilder headcontent = new StringBuilder(); for (int i = 0, end = headcontentlist.getLength(); i < end; i++) { Node node = headcontentlist.item(i); HTMLConverter.toStringChildNode(headcontent, node, "", 0, "\n"); Attr numbera = ((Element) node).getAttributeNode("number"); } StringBuilder contents = new StringBuilder(); Node documentcontent = document.getElementById("document"); HTMLConverter.toStringChildNode(contents, documentcontent, "", 0, "\n"); // テンプレートファイル読み込み String templatefile = "testdata\\template.html"; List<String> template = Files.readAllLines(Paths.get(templatefile), Charset.forName("utf-8")); String title = root.getProperty("title"); if (title == null) { title = ""; } ArrayList<String> lis = new ArrayList<>(template.size()); File write = new File("testdata\\output\\index.html"); // System.out.println(e.current); PrintStream s = new PrintStream(write, "UTF-8"); // s.print(hcon.toHTML()); for (String str : template) { if (str.equals("<!--{PAGETITLE}-->")) { // lis.add(title); // System.out.println(title); s.println(title); } else if (str.equals("<!--{HEADCONTENT}-->")) { // lis.add(headcontent.toString()); // System.out.println(headcontent.toString()); s.println(headcontent); } else if (str.equals("<!--{CONTENTS}-->")) { // lis.add(contents.toString()); // System.out.println(contents); s.println(contents); } else { // lis.add(str); s.println(str); } } s.close(); for (int i = 0, end = chapterlist.size(); i < end; i++) { Element node = chapterlist.get(i); write = new File("testdata\\output\\index_chapter" + (i + 1) + ".html"); // System.out.println(e.current); s = new PrintStream(write, "UTF-8"); contents.setLength(0); HTMLConverter.toStringChildNode(contents, node, "", 0, "\n"); Attr numbera = node.getAttributeNode("number"); Attr titla = node.getAttributeNode("title"); // System.out.println(contents); title = numbera.getValue() + " " + titla.getValue(); for (String str : template) { if (str.equals("<!--{PAGETITLE}-->")) { // lis.add(title); // System.out.println(title); s.println(title); } else if (str.equals("<!--{HEADCONTENT}-->")) { // lis.add(headcontent.toString()); // System.out.println(headcontent.toString()); s.println(headcontent); } else if (str.equals("<!--{CONTENTS}-->")) { // lis.add(contents.toString()); // System.out.println(contents); s.println(contents); } else { // lis.add(str); s.println(str); } } s.close(); } }