OSDN Git Service

binioパッケージと統合
[mikutoga/TogaGem.git] / src / main / java / jp / sourceforge / mikutoga / pmd / model / binio / PmdExporterExt1.java
1 /*
2  * model exporter for pmd-file(Ext1)
3  *
4  * License : The MIT License
5  * Copyright(c) 2010 MikuToga Partners
6  */
7
8 package jp.sourceforge.mikutoga.pmd.model.binio;
9
10 import java.io.IOException;
11 import java.io.OutputStream;
12 import java.util.List;
13 import java.util.Map;
14 import jp.sourceforge.mikutoga.binio.IllegalTextExportException;
15 import jp.sourceforge.mikutoga.pmd.MorphType;
16 import jp.sourceforge.mikutoga.pmd.model.BoneGroup;
17 import jp.sourceforge.mikutoga.pmd.model.BoneInfo;
18 import jp.sourceforge.mikutoga.pmd.model.MorphPart;
19 import jp.sourceforge.mikutoga.pmd.model.PmdModel;
20 import jp.sourceforge.mikutoga.pmd.parser.PmdLimits;
21
22 /**
23  * PMDファイルのエクスポーター(拡張1:英名対応)。
24  * <p>
25  * 任意のトゥーンファイル名対応以降のPMDファイルフォーマットを
26  * 使いたくない場合はこのエクスポーターを用いて出力せよ。
27  */
28 public class PmdExporterExt1 extends PmdExporterBase{
29
30     /**
31      * コンストラクタ。
32      * @param stream 出力ストリーム
33      * @throws NullPointerException 引数がnull
34      */
35     public PmdExporterExt1(OutputStream stream)
36             throws NullPointerException{
37         super(stream);
38         return;
39     }
40
41     /**
42      * {@inheritDoc}
43      * @param model {@inheritDoc}
44      * @throws IOException {@inheritDoc}
45      * @throws IllegalPmdException {@inheritDoc}
46      */
47     @Override
48     public void dumpPmdModel(PmdModel model)
49             throws IOException, IllegalPmdException{
50         super.dumpPmdModel(model);
51
52         dumpGlobalInfo(model);
53
54         return;
55     }
56
57     /**
58      * 英語名情報を出力する。
59      * @param model モデルデータ
60      * @throws IOException 出力エラー
61      * @throws IllegalPmdTextException 文字列が長すぎる。
62      */
63     private void dumpGlobalInfo(PmdModel model)
64             throws IOException, IllegalPmdException{
65         boolean hasGlobal = model.hasGlobalText();
66         byte globalFlag;
67         if(hasGlobal) globalFlag = 0x01;
68         else          globalFlag = 0x00;
69         dumpByte(globalFlag);
70
71         if(hasGlobal){
72             try{
73                 dumpBasicGlobal(model);
74                 dumpBoneGlobal(model);
75                 dumpMorphGlobal(model);
76                 dumpBoneGroupGlobal(model);
77             }catch(IllegalTextExportException e){
78                 throw new IllegalPmdException(e);
79             }
80         }
81
82         flush();
83
84         return;
85     }
86
87     /**
88      * モデル基本情報を英語で出力する。
89      * @param model モデルデータ
90      * @throws IOException 出力エラー
91      * @throws IllegalPmdTextException 文字列が長すぎる。
92      */
93     private void dumpBasicGlobal(PmdModel model)
94             throws IOException, IllegalTextExportException{
95         String modelName = model.getModelName().getGlobalText();
96         if(modelName == null) modelName = "";
97         dumpText(modelName, PmdLimits.MAXBYTES_MODELNAME);
98
99         String description = model.getDescription().getGlobalText();
100         if(description == null) description = "";
101         dumpText(description, PmdLimits.MAXBYTES_MODELDESC);
102
103         flush();
104     }
105
106     /**
107      * ボーン英語名情報を出力する。
108      * @param model モデルデータ
109      * @throws IOException 出力エラー
110      * @throws IllegalPmdTextException 文字列が長すぎる。
111      */
112     private void dumpBoneGlobal(PmdModel model)
113             throws IOException, IllegalTextExportException{
114         for(BoneInfo bone : model.getBoneList()){
115             String boneName = bone.getBoneName().getGlobalText();
116             if(boneName == null) boneName = "";
117             dumpText(boneName, PmdLimits.MAXBYTES_BONENAME);
118         }
119
120         flush();
121     }
122
123     /**
124      * モーフ英語名情報を出力する。
125      * @param model モデルデータ
126      * @throws IOException 出力エラー
127      * @throws IllegalPmdTextException 文字列が長すぎる。
128      */
129     private void dumpMorphGlobal(PmdModel model)
130             throws IOException, IllegalTextExportException{
131         Map<MorphType, List<MorphPart>> morphMap = model.getMorphMap();
132
133         for(MorphType type : MorphType.values()){
134             if(type.isBase()) continue;
135             List<MorphPart> partList = morphMap.get(type);
136             if(partList == null) continue;
137             for(MorphPart part : partList){
138                 String morphName = part.getMorphName().getGlobalText();
139                 if(morphName == null) morphName = "";
140                 dumpText(morphName, PmdLimits.MAXBYTES_MORPHNAME);
141             }
142         }
143
144         flush();
145     }
146
147     /**
148      * ボーングループ英語名情報を出力する。
149      * @param model モデルデータ
150      * @throws IOException 出力エラー
151      * @throws IllegalPmdTextException 文字列が長すぎる
152      */
153     private void dumpBoneGroupGlobal(PmdModel model)
154             throws IOException, IllegalTextExportException{
155         for(BoneGroup group : model.getBoneGroupList()){
156             if(group.isDefaultBoneGroup()) continue;
157             String groupName = group.getGroupName().getGlobalText();
158             if(groupName == null) groupName = "";
159             dumpText(groupName, PmdLimits.MAXBYTES_BONEGROUPNAME);
160         }
161
162         flush();
163     }
164
165 }