-/*\r
- * pmd 2 xml converter main entry\r
- *\r
- * License : The MIT License\r
- * Copyright(c) 2010 MikuToga Partners\r
- */\r
-\r
-package jp.sourceforge.mikutoga.pmd2xml;\r
-\r
-import java.io.BufferedInputStream;\r
-import java.io.BufferedOutputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.OutputStream;\r
-import java.nio.channels.FileChannel;\r
-import java.util.Properties;\r
-import javax.xml.parsers.DocumentBuilder;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import jp.sourceforge.mikutoga.parser.MmdFormatException;\r
-import jp.sourceforge.mikutoga.parser.MmdSource;\r
-import jp.sourceforge.mikutoga.pmd.PmdModel;\r
-import jp.sourceforge.mikutoga.pmd.pmdexporter.IllegalPmdException;\r
-import jp.sourceforge.mikutoga.pmd.pmdexporter.PmdExporter;\r
-import jp.sourceforge.mikutoga.pmd.pmdloader.PmdLoader;\r
-import jp.sourceforge.mikutoga.pmd.xml.PmdXmlExporter;\r
-import jp.sourceforge.mikutoga.pmd.xml.PmdXmlResources;\r
-import jp.sourceforge.mikutoga.pmd.xml.Xml2PmdLoader;\r
-import jp.sourceforge.mikutoga.xml.TogaXmlException;\r
-import org.xml.sax.InputSource;\r
-import org.xml.sax.SAXException;\r
-\r
-/**\r
- * PMDモデルファイルとXMLとの間で変換を行うアプリケーション。\r
- */\r
-public final class Pmd2Xml {\r
-\r
- private static final Class THISCLASS;\r
- private static final String APPNAME;\r
- private static final String APPVER;\r
- private static final String APPLICENSE;\r
-\r
- static{\r
- THISCLASS = Pmd2Xml.class;\r
- InputStream ver =\r
- THISCLASS.getResourceAsStream("resources/version.properties");\r
- Properties verProps = new Properties();\r
- try{\r
- verProps.load(ver);\r
- }catch(IOException e){\r
- throw new ExceptionInInitializerError(e);\r
- }\r
-\r
- APPNAME = verProps.getProperty("app.name");\r
- APPVER = verProps.getProperty("app.version");\r
- APPLICENSE = verProps.getProperty("app.license");\r
-\r
- Object dummy = new Pmd2Xml();\r
- }\r
-\r
- /**\r
- * 隠しコンストラクタ。\r
- */\r
- private Pmd2Xml(){\r
- super();\r
- assert this.getClass().equals(THISCLASS);\r
- return;\r
- }\r
-\r
- /**\r
- * Mainエントリ。\r
- * @param args コマンドパラメータ\r
- */\r
- public static void main(String[] args){\r
- checkJRE();\r
-\r
- String inputFile = null;\r
- String outputFile = null;\r
- boolean pmd2xml = false;\r
- boolean xml2pmd = false;\r
- boolean force = false;\r
- int argsLen = args.length;\r
- for(int argIdx = 0; argIdx < argsLen; argIdx++){\r
- String arg = args[argIdx];\r
-\r
- if(arg.equals("-h")){\r
- putHelp();\r
- }else if(arg.equals("-pmd2xml")){\r
- pmd2xml = true;\r
- xml2pmd = false;\r
- }else if(arg.equals("-xml2pmd")){\r
- pmd2xml = false;\r
- xml2pmd = true;\r
- }else if(arg.equals("-i")){\r
- if(++argIdx >= argsLen){\r
- System.err.println("ERROR:");\r
- System.err.println("You need -i argument.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
- inputFile = args[argIdx];\r
- }else if(arg.equals("-o")){\r
- if(++argIdx >= argsLen){\r
- System.err.println("ERROR:");\r
- System.err.println("You need -o argument.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
- outputFile = args[argIdx];\r
- }else if(arg.equals("-f")){\r
- force = true;\r
- }\r
- }\r
-\r
- if( ( ! pmd2xml) && ( ! xml2pmd) ){\r
- System.err.println("ERROR:");\r
- System.err.println("You must specify -pmd2xml or -xml2pmd.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
-\r
- if(inputFile == null){\r
- System.err.println("ERROR:");\r
- System.err.println("You must specify input file with -i.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
-\r
- if(outputFile == null){\r
- System.err.println("ERROR:");\r
- System.err.println("You must specify output file with -o.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
-\r
- File iFile = new File(inputFile);\r
- if( (! iFile.exists()) || (! iFile.isFile()) ){\r
- System.err.println("ERROR:");\r
- System.err.println("Can't find input file:"\r
- + iFile.getAbsolutePath());\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
-\r
- if( ! force ){\r
- File oFile = new File(outputFile);\r
- if(oFile.exists()){\r
- System.err.println("ERROR:");\r
- System.err.println(oFile.getAbsolutePath()\r
- + " already exists.");\r
- System.err.println("If you want to overwrite, use -f.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
- }else{\r
- File oFile = new File(outputFile);\r
- if(oFile.exists()){\r
- if( ! oFile.isFile()){\r
- System.err.println("ERROR:");\r
- System.err.println(oFile.getAbsolutePath()\r
- + " is not file.");\r
- System.err.println("(-h for help)");\r
- System.exit(1);\r
- }\r
- }\r
- }\r
-\r
- try{\r
- if(pmd2xml) pmd2xml(inputFile, outputFile);\r
- else xml2pmd(inputFile, outputFile);\r
- }catch(IOException e){\r
- ioError(e);\r
- }catch(ParserConfigurationException e){\r
- internalError(e);\r
- }catch(IllegalPmdException e){\r
- internalError(e);\r
- }catch(MmdFormatException e){\r
- pmdError(e);\r
- }catch(TogaXmlException e){\r
- xmlError(e);\r
- }catch(SAXException e){\r
- xmlError(e);\r
- }\r
-\r
- System.exit(0);\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * 入出力エラー処理。\r
- * 例外を出力してVM終了する。\r
- * @param ex 例外\r
- */\r
- private static void ioError(Throwable ex){\r
- System.err.println(ex);\r
- System.exit(1);\r
- }\r
-\r
- /**\r
- * XML構文エラー処理。\r
- * 例外を出力してVM終了する。\r
- * @param ex 例外\r
- */\r
- private static void xmlError(Throwable ex){\r
- System.err.println(ex);\r
- System.exit(2);\r
- }\r
-\r
- /**\r
- * PMDファイルフォーマットエラー処理。\r
- * 例外を出力してVM終了する。\r
- * @param ex 例外\r
- */\r
- private static void pmdError(Throwable ex){\r
- System.err.println(ex);\r
- ex.printStackTrace(System.err);\r
- System.exit(3);\r
- }\r
-\r
- /**\r
- * 内部エラー処理。\r
- * 例外を出力してVM終了する。\r
- * @param ex 例外\r
- */\r
- private static void internalError(Throwable ex){\r
- System.err.println(ex);\r
- ex.printStackTrace(System.err);\r
- System.exit(4);\r
- }\r
-\r
- /**\r
- * JREのバージョン判定を行う。\r
- * 不適切ならVMごと終了。\r
- */\r
- private static void checkJRE(){\r
- Package jrePackage = java.lang.Object.class.getPackage();\r
- if( ! jrePackage.isCompatibleWith("1.6")){\r
- System.err.println("You need JRE 1.6 or later.");\r
- System.exit(1);\r
- }\r
- return;\r
- }\r
-\r
- /**\r
- * ヘルプメッセージを出力してVMを終了させる。\r
- */\r
- private static void putHelp(){\r
- System.err.println(APPNAME + ' ' + APPVER );\r
- System.err.println(" License : " + APPLICENSE);\r
- System.err.println(" http://mikutoga.sourceforge.jp/");\r
- System.err.println();\r
- System.err.println("-h : put help massage");\r
- System.err.println("-pmd2xml : convert *.pmd to *.xml");\r
- System.err.println("-xml2pmd : convert *.xml to *.pmd");\r
- System.err.println("-i file : specify input file");\r
- System.err.println("-o file : specify output file");\r
- System.err.println("-f : force overwriting");\r
- System.exit(0);\r
- return;\r
- }\r
-\r
- /**\r
- * PMD->XML変換を行う。\r
- * @param inputFile 入力ファイル名\r
- * @param outputFile 出力ファイル名\r
- * @throws IOException 入出力エラー\r
- * @throws MmdFormatException 不正なPMDファイル\r
- * @throws IllegalPmdException 不正なモデルデータ\r
- */\r
- private static void pmd2xml(String inputFile, String outputFile)\r
- throws IOException, MmdFormatException, IllegalPmdException{\r
- File iFile = new File(inputFile);\r
- InputStream is = new FileInputStream(iFile);\r
- is = new BufferedInputStream(is);\r
- PmdModel model = pmdRead(is);\r
- is.close();\r
-\r
- File oFile = new File(outputFile);\r
- trunc(oFile);\r
- OutputStream ostream;\r
- ostream = new FileOutputStream(oFile, false);\r
- ostream = new BufferedOutputStream(ostream);\r
- xmlOut(model, ostream);\r
- ostream.close();\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * XML->PMD変換を行う。\r
- * @param inputFile 入力ファイル名\r
- * @param outputFile 出力ファイル名\r
- * @throws IOException 入出力エラー\r
- * @throws ParserConfigurationException XML構成のエラー\r
- * @throws SAXException 不正なXMLファイル\r
- * @throws TogaXmlException 不正なXMLファイル\r
- * @throws IllegalPmdException 不正なPMDモデルデータ\r
- */\r
- private static void xml2pmd(String inputFile, String outputFile)\r
- throws IOException,\r
- ParserConfigurationException,\r
- SAXException,\r
- TogaXmlException,\r
- IllegalPmdException {\r
- File iFile = new File(inputFile);\r
- InputStream is = new FileInputStream(iFile);\r
- is = new BufferedInputStream(is);\r
- InputSource source = new InputSource(is);\r
- PmdModel model = xmlRead(source);\r
- is.close();\r
-\r
- File oFile = new File(outputFile);\r
- trunc(oFile);\r
- OutputStream ostream;\r
- ostream = new FileOutputStream(oFile, false);\r
- ostream = new BufferedOutputStream(ostream);\r
- pmdOut(model, ostream);\r
- ostream.close();\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * ファイルサイズを0に切り詰める。\r
- * @param file ファイル\r
- * @throws IOException 入出力エラー\r
- */\r
- private static void trunc(File file) throws IOException{\r
- if( ! file.exists() ) return;\r
- if( ! file.isFile() ) return;\r
-\r
- FileOutputStream foStream = new FileOutputStream(file);\r
- FileChannel channnel = foStream.getChannel();\r
- channnel.truncate(0);\r
-\r
- channnel.close();\r
- foStream.close();\r
-\r
- return;\r
- }\r
-\r
- /**\r
- * PMDファイルからモデルデータを読み込む。\r
- * @param is 入力ストリーム\r
- * @return モデルデータ\r
- * @throws IOException 入力エラー\r
- * @throws MmdFormatException 不正なPMDファイルフォーマット\r
- */\r
- private static PmdModel pmdRead(InputStream is)\r
- throws IOException, MmdFormatException{\r
- MmdSource source = new MmdSource(is);\r
- PmdLoader loader = new PmdLoader(source);\r
-\r
- PmdModel model = loader.load();\r
-\r
- return model;\r
- }\r
-\r
- /**\r
- * XMLファイルからモデルデータを読み込む。\r
- * @param source 入力ソース\r
- * @return モデルデータ\r
- * @throws IOException 入力エラー\r
- * @throws ParserConfigurationException XML構成エラー\r
- * @throws SAXException XML構文エラー\r
- * @throws TogaXmlException 不正なXMLデータ\r
- */\r
- private static PmdModel xmlRead(InputSource source)\r
- throws IOException,\r
- ParserConfigurationException,\r
- SAXException,\r
- TogaXmlException {\r
- DocumentBuilder builder =\r
- PmdXmlResources.newBuilder(XmlHandler.HANDLER);\r
- Xml2PmdLoader loader = new Xml2PmdLoader(builder);\r
-\r
- PmdModel model = loader.parse(source);\r
-\r
- return model;\r
- }\r
-\r
- /**\r
- * モデルデータをPMDファイルに出力する。\r
- * @param model モデルデータ\r
- * @param ostream 出力ストリーム\r
- * @throws IOException 出力エラー\r
- * @throws IllegalPmdException 不正なモデルデータ\r
- */\r
- private static void pmdOut(PmdModel model, OutputStream ostream)\r
- throws IOException, IllegalPmdException{\r
- PmdExporter exporter = new PmdExporter(ostream);\r
- exporter.dumpPmdModel(model);\r
- ostream.close();\r
- return;\r
- }\r
-\r
- /**\r
- * モデルデータをXMLファイルに出力する。\r
- * @param model モデルデータ\r
- * @param ostream 出力ストリーム\r
- * @throws IOException 出力エラー\r
- * @throws IllegalPmdException 不正なモデルデータ\r
- */\r
- private static void xmlOut(PmdModel model, OutputStream ostream)\r
- throws IOException, IllegalPmdException{\r
- PmdXmlExporter exporter = new PmdXmlExporter(ostream);\r
- exporter.setNewLine("\r\n");\r
- exporter.setGenerator(APPNAME + ' ' + APPVER);\r
- exporter.putPmdModel(model);\r
- exporter.close();\r
- return;\r
- }\r
-\r
-}\r
+/*
+ * pmd 2 xml converter main entry
+ *
+ * License : The MIT License
+ * Copyright(c) 2010 MikuToga Partners
+ */
+
+package jp.sourceforge.mikutoga.pmd2xml;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.channels.FileChannel;
+import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
+import jp.sourceforge.mikutoga.parser.MmdFormatException;
+import jp.sourceforge.mikutoga.parser.MmdInputStream;
+import jp.sourceforge.mikutoga.pmd.IllegalPmdDataException;
+import jp.sourceforge.mikutoga.pmd.model.PmdModel;
+import jp.sourceforge.mikutoga.pmd.model.binio.PmdExporter;
+import jp.sourceforge.mikutoga.pmd.model.binio.PmdLoader;
+import jp.sourceforge.mikutoga.pmd.model.xml.PmdXmlExporter;
+import jp.sourceforge.mikutoga.pmd.model.xml.PmdXmlResources;
+import jp.sourceforge.mikutoga.pmd.model.xml.Xml2PmdLoader;
+import jp.sourceforge.mikutoga.xml.TogaXmlException;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * PMDモデルファイルとXMLとの間で変換を行うアプリケーション。
+ */
+public final class Pmd2Xml {
+
+ private static final Class<?> THISCLASS;
+ private static final String APPNAME;
+ private static final String APPVER;
+ private static final String APPLICENSE;
+
+ static{
+ THISCLASS = Pmd2Xml.class;
+ InputStream ver =
+ THISCLASS.getResourceAsStream("resources/version.properties");
+ Properties verProps = new Properties();
+ try{
+ verProps.load(ver);
+ }catch(IOException e){
+ throw new ExceptionInInitializerError(e);
+ }
+
+ APPNAME = verProps.getProperty("app.name");
+ APPVER = verProps.getProperty("app.version");
+ APPLICENSE = verProps.getProperty("app.license");
+
+ Object dummy = new Pmd2Xml();
+ }
+
+ /**
+ * 隠しコンストラクタ。
+ */
+ private Pmd2Xml(){
+ super();
+ assert this.getClass().equals(THISCLASS);
+ return;
+ }
+
+ /**
+ * Mainエントリ。
+ * @param args コマンドパラメータ
+ */
+ public static void main(String[] args){
+ checkJRE();
+
+ String inputFile = null;
+ String outputFile = null;
+ boolean pmd2xml = false;
+ boolean xml2pmd = false;
+ boolean force = false;
+ int argsLen = args.length;
+ for(int argIdx = 0; argIdx < argsLen; argIdx++){
+ String arg = args[argIdx];
+
+ if(arg.equals("-h")){
+ putHelp();
+ }else if(arg.equals("-pmd2xml")){
+ pmd2xml = true;
+ xml2pmd = false;
+ }else if(arg.equals("-xml2pmd")){
+ pmd2xml = false;
+ xml2pmd = true;
+ }else if(arg.equals("-i")){
+ if(++argIdx >= argsLen){
+ System.err.println("ERROR:");
+ System.err.println("You need -i argument.");
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+ inputFile = args[argIdx];
+ }else if(arg.equals("-o")){
+ if(++argIdx >= argsLen){
+ System.err.println("ERROR:");
+ System.err.println("You need -o argument.");
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+ outputFile = args[argIdx];
+ }else if(arg.equals("-f")){
+ force = true;
+ }else{
+ System.err.println("ERROR:");
+ System.err.println("Unknown option:"+arg);
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+ }
+
+ if( ( ! pmd2xml) && ( ! xml2pmd) ){
+ System.err.println("ERROR:");
+ System.err.println("You must specify -pmd2xml or -xml2pmd.");
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+
+ if(inputFile == null){
+ System.err.println("ERROR:");
+ System.err.println("You must specify input file with -i.");
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+
+ if(outputFile == null){
+ System.err.println("ERROR:");
+ System.err.println("You must specify output file with -o.");
+ System.err.println("(-h for help)");
+ System.exit(5);
+ }
+
+ File iFile = new File(inputFile);
+ if( (! iFile.exists()) || (! iFile.isFile()) ){
+ System.err.println("ERROR:");
+ System.err.println("Can't find input file:"
+ + iFile.getAbsolutePath());
+ System.err.println("(-h for help)");
+ System.exit(1);
+ }
+
+ if( ! force ){
+ File oFile = new File(outputFile);
+ if(oFile.exists()){
+ System.err.println("ERROR:");
+ System.err.println(oFile.getAbsolutePath()
+ + " already exists.");
+ System.err.println("If you want to overwrite, use -f.");
+ System.err.println("(-h for help)");
+ System.exit(1);
+ }
+ }else{
+ File oFile = new File(outputFile);
+ if(oFile.exists()){
+ if( ! oFile.isFile()){
+ System.err.println("ERROR:");
+ System.err.println(oFile.getAbsolutePath()
+ + " is not file.");
+ System.err.println("(-h for help)");
+ System.exit(1);
+ }
+ }
+ }
+
+ try{
+ if(pmd2xml) pmd2xml(inputFile, outputFile);
+ else xml2pmd(inputFile, outputFile);
+ }catch(IOException e){
+ ioError(e);
+ }catch(ParserConfigurationException e){
+ internalError(e);
+ }catch(IllegalPmdDataException e){
+ internalError(e);
+ }catch(MmdFormatException e){
+ pmdError(e);
+ }catch(TogaXmlException e){
+ xmlError(e);
+ }catch(SAXException e){
+ xmlError(e);
+ }
+
+ System.exit(0);
+
+ return;
+ }
+
+ /**
+ * 入出力エラー処理。
+ * 例外を出力してVM終了する。
+ * @param ex 例外
+ */
+ private static void ioError(Throwable ex){
+ System.err.println(ex);
+ System.exit(1);
+ }
+
+ /**
+ * XML構文エラー処理。
+ * 例外を出力してVM終了する。
+ * @param ex 例外
+ */
+ private static void xmlError(Throwable ex){
+ System.err.println(ex);
+ System.exit(2);
+ }
+
+ /**
+ * PMDファイルフォーマットエラー処理。
+ * 例外を出力してVM終了する。
+ * @param ex 例外
+ */
+ private static void pmdError(Throwable ex){
+ System.err.println(ex);
+ ex.printStackTrace(System.err);
+ System.exit(3);
+ }
+
+ /**
+ * 内部エラー処理。
+ * 例外を出力してVM終了する。
+ * @param ex 例外
+ */
+ private static void internalError(Throwable ex){
+ System.err.println(ex);
+ ex.printStackTrace(System.err);
+ System.exit(4);
+ }
+
+ /**
+ * JREのバージョン判定を行う。
+ * 不適切ならVMごと終了。
+ */
+ private static void checkJRE(){
+ Package jrePackage = java.lang.Object.class.getPackage();
+ if( ! jrePackage.isCompatibleWith("1.6")){
+ System.err.println("You need JRE 1.6 or later.");
+ System.exit(4);
+ }
+ return;
+ }
+
+ /**
+ * ヘルプメッセージを出力してVMを終了させる。
+ */
+ private static void putHelp(){
+ System.err.println(APPNAME + ' ' + APPVER );
+ System.err.println(" License : " + APPLICENSE);
+ System.err.println(" http://mikutoga.sourceforge.jp/");
+ System.err.println();
+ System.err.println("-h : put help massage");
+ System.err.println("-pmd2xml : convert *.pmd to *.xml");
+ System.err.println("-xml2pmd : convert *.xml to *.pmd");
+ System.err.println("-i file : specify input file");
+ System.err.println("-o file : specify output file");
+ System.err.println("-f : force overwriting");
+ System.exit(0);
+ return;
+ }
+
+ /**
+ * PMD->XML変換を行う。
+ * @param inputFile 入力ファイル名
+ * @param outputFile 出力ファイル名
+ * @throws IOException 入出力エラー
+ * @throws MmdFormatException 不正なPMDファイル
+ * @throws IllegalPmdDataException 不正なモデルデータ
+ */
+ private static void pmd2xml(String inputFile, String outputFile)
+ throws IOException, MmdFormatException, IllegalPmdDataException{
+ File iFile = new File(inputFile);
+ InputStream is = new FileInputStream(iFile);
+ is = new BufferedInputStream(is);
+ PmdModel model = pmdRead(is);
+ is.close();
+
+ File oFile = new File(outputFile);
+ trunc(oFile);
+ OutputStream ostream;
+ ostream = new FileOutputStream(oFile, false);
+ ostream = new BufferedOutputStream(ostream);
+ xmlOut(model, ostream);
+ ostream.close();
+
+ return;
+ }
+
+ /**
+ * XML->PMD変換を行う。
+ * @param inputFile 入力ファイル名
+ * @param outputFile 出力ファイル名
+ * @throws IOException 入出力エラー
+ * @throws ParserConfigurationException XML構成のエラー
+ * @throws SAXException 不正なXMLファイル
+ * @throws TogaXmlException 不正なXMLファイル
+ * @throws IllegalPmdDataException 不正なPMDモデルデータ
+ */
+ private static void xml2pmd(String inputFile, String outputFile)
+ throws IOException,
+ ParserConfigurationException,
+ SAXException,
+ TogaXmlException,
+ IllegalPmdDataException {
+ File iFile = new File(inputFile);
+ InputStream is = new FileInputStream(iFile);
+ is = new BufferedInputStream(is);
+ InputSource source = new InputSource(is);
+ PmdModel model = xmlRead(source);
+ is.close();
+
+ File oFile = new File(outputFile);
+ trunc(oFile);
+ OutputStream ostream;
+ ostream = new FileOutputStream(oFile, false);
+ ostream = new BufferedOutputStream(ostream);
+ pmdOut(model, ostream);
+ ostream.close();
+
+ return;
+ }
+
+ /**
+ * ファイルサイズを0に切り詰める。
+ * @param file ファイル
+ * @throws IOException 入出力エラー
+ */
+ private static void trunc(File file) throws IOException{
+ if( ! file.exists() ) return;
+ if( ! file.isFile() ) return;
+
+ FileOutputStream foStream = new FileOutputStream(file);
+ FileChannel channnel = foStream.getChannel();
+ channnel.truncate(0);
+
+ channnel.close();
+ foStream.close();
+
+ return;
+ }
+
+ /**
+ * PMDファイルからモデルデータを読み込む。
+ * @param is 入力ストリーム
+ * @return モデルデータ
+ * @throws IOException 入力エラー
+ * @throws MmdFormatException 不正なPMDファイルフォーマット
+ */
+ private static PmdModel pmdRead(InputStream is)
+ throws IOException, MmdFormatException{
+ MmdInputStream source = new MmdInputStream(is);
+ PmdLoader loader = new PmdLoader(source);
+
+ PmdModel model = loader.load();
+
+ return model;
+ }
+
+ /**
+ * XMLファイルからモデルデータを読み込む。
+ * @param source 入力ソース
+ * @return モデルデータ
+ * @throws IOException 入力エラー
+ * @throws ParserConfigurationException XML構成エラー
+ * @throws SAXException XML構文エラー
+ * @throws TogaXmlException 不正なXMLデータ
+ */
+ private static PmdModel xmlRead(InputSource source)
+ throws IOException,
+ ParserConfigurationException,
+ SAXException,
+ TogaXmlException {
+ DocumentBuilder builder =
+ PmdXmlResources.newBuilder(XmlHandler.HANDLER);
+ Xml2PmdLoader loader = new Xml2PmdLoader(builder);
+
+ PmdModel model = loader.parse(source);
+
+ return model;
+ }
+
+ /**
+ * モデルデータをPMDファイルに出力する。
+ * @param model モデルデータ
+ * @param ostream 出力ストリーム
+ * @throws IOException 出力エラー
+ * @throws IllegalPmdDataException 不正なモデルデータ
+ */
+ private static void pmdOut(PmdModel model, OutputStream ostream)
+ throws IOException, IllegalPmdDataException{
+ PmdExporter exporter = new PmdExporter(ostream);
+ exporter.dumpPmdModel(model);
+ ostream.close();
+ return;
+ }
+
+ /**
+ * モデルデータをXMLファイルに出力する。
+ * @param model モデルデータ
+ * @param ostream 出力ストリーム
+ * @throws IOException 出力エラー
+ * @throws IllegalPmdDataException 不正なモデルデータ
+ */
+ private static void xmlOut(PmdModel model, OutputStream ostream)
+ throws IOException, IllegalPmdDataException{
+ PmdXmlExporter exporter = new PmdXmlExporter(ostream);
+ exporter.setNewLine("\r\n");
+ exporter.setGenerator(APPNAME + ' ' + APPVER);
+ exporter.putPmdModel(model);
+ exporter.close();
+ return;
+ }
+
+}