public static void main(String[] args) throws Exception { CommandLineOption op = new CommandLineOption(args); CommandLineOption.Option[] ops = op.getOptions(); String fn = null, output = null, baseDir = ".", inits = null, setting = null; for (CommandLineOption.Option o : ops) { if (o.name == null) { fn = o.value; } else { switch (o.name) { case "-o": case "--output": output = o.value; break; case "-d": case "--directory": baseDir = o.value; break; case "-s": case "--setting": setting = o.value; break; case "-i": case "--init": inits = o.value; break; case "-h": case "--help": System.out.println("[-OPTIONS] -s settingfile1[,settigfile2] input file name"); System.out.println(" -d,--direcoty:作業ディレクトリを指定します。指定しない場合は弦座のディレクトリになります。"); System.out.println(" -i,--init :ファイルを読み込む前に実行するマクロの初期化ファイルです。必須オプションです。"); System.out.println(" -o,--output :出力ファイル名を指定してください"); System.out.println(" -s,--setting :RootDocumentをHTMLDOMに変換する為の設定ファイルです。必須オプションです。"); System.out.println(" -h,--help :このヘルプを出力します"); return; } } } if (fn == null) { System.out.println("開発のテストモードで起動します。"); testMain(); return; // System.out.println("入力ファイルを指定してください"); // return; } if (inits == null) { System.err.println("マクロ初期化ファイルが指定されていません。"); return; } if (setting == null) { System.err.println("設定ファイルが指定されていません。"); return; } Path base = Paths.get(baseDir).toAbsolutePath(); Path file = base.resolve(fn); if (!Files.isReadable(file)) { System.err.println("ファイルを読み込むことが出来ません。" + file.toString()); return; } LamuriyanEngine engine = new LamuriyanEngine(fn, base); String[] s = inits.split(","); ArrayList<Path> paths = new ArrayList<>(); for (String ss : s) { paths.add(Paths.get(ss)); } engine.setInitFiles(paths); engine.evaluate(); RootDocument root = engine.getDocument(); HTMLConverter converter = new HTMLConverter(root, Paths.get(setting)); converter.convert(); if (output == null) { System.out.println(converter.toHTML()); } else { Path out = Paths.get(output); if (!Files.exists(out)) Files.createFile(out); FileWriter fw = new FileWriter(out.toFile()); fw.write(converter.toHTML()); } }