OSDN Git Service

Appendable対応
authorOlyutorskii <olyutorskii@users.osdn.me>
Tue, 21 May 2013 14:10:53 +0000 (23:10 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Tue, 21 May 2013 14:10:53 +0000 (23:10 +0900)
pom.xml
src/main/config/checks.xml
src/main/java/jp/sfjp/mikutoga/pmd/xml/PmdXmlExporter.java [moved from src/main/java/jp/sfjp/mikutoga/pmd/xml/XmlExporter.java with 94% similarity]
src/main/java/jp/sfjp/mikutoga/pmd2xml/Pmd2XmlConv.java

diff --git a/pom.xml b/pom.xml
index afa2a37..c867323 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
-                <version>2.0</version>
+                <version>2.1</version>
                 <executions>
                     <execution>
                         <phase>package</phase>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-site-plugin</artifactId>
-                <version>3.2</version>
+                <version>3.3</version>
                 <configuration>
                     <generateReports>true</generateReports>
                     <locales>ja</locales>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-project-info-reports-plugin</artifactId>
-                <version>2.6</version>
+                <version>2.7</version>
                 <configuration>
                     <linkOnly>true</linkOnly>
                     <offline>true</offline>
index 28c05e5..3d6d80e 100644 (file)
@@ -7,7 +7,7 @@
 <!--
     Checkstyle用チェック項目定義。
 
-    Checkstyle 5.3 以降向けに記述。
+    Checkstyle 5.5 以降向けに記述。
 
     [ http://checkstyle.sourceforge.net/ ]
 
@@ -42,6 +42,7 @@
     <module name="RegexpHeader">
         <property name="header" value="^/\*$\n^ \*( .*)?$\n^ \*/$\n" />
         <property name="multiLines" value="2" />
+        <property name="fileExtensions" value="java" />
     </module>
 
 
@@ -50,7 +51,9 @@
 
 
     <!-- Miscellaneous -->
-    <module name="NewlineAtEndOfFile" />
+    <module name="NewlineAtEndOfFile">
+        <property name="fileExtensions" value="java" />
+    </module>
     <module name="Translation" />
 
 
         <module name="FallThrough" />
         <module name="MultipleStringLiterals" />
         <module name="MultipleVariableDeclarations" />
+        <module name="RequireThis">
+            <property name="checkMethods" value="false" />
+        </module>
         <module name="UnnecessaryParentheses" />
         <module name="OneStatementPerLine" />
 
@@ -9,7 +9,6 @@ package jp.sfjp.mikutoga.pmd.xml;
 
 import java.awt.Color;
 import java.io.IOException;
-import java.io.OutputStream;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -46,7 +45,7 @@ import jp.sourceforge.mikutoga.xml.XmlResourceResolver;
 /**
  * 101009形式XMLでPMDモデルデータを出力する。
  */
-public class XmlExporter extends BasicXmlExporter{
+public class PmdXmlExporter extends BasicXmlExporter{
 
     private static final String TOP_COMMENT =
               "  MikuMikuDance\n"
@@ -102,14 +101,13 @@ public class XmlExporter extends BasicXmlExporter{
 
     /**
      * コンストラクタ。
-     * 文字エンコーディングはUTF-8が用いられる。
-     * @param stream 出力ストリーム
      */
-    public XmlExporter(OutputStream stream){
-        super(stream);
+    public PmdXmlExporter(){
+        super();
         return;
     }
 
+
     /**
      * 出力XMLファイル種別を返す。
      * @return ファイル種別
@@ -171,7 +169,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public XmlExporter ind() throws IOException{
+    public PmdXmlExporter ind() throws IOException{
         super.ind();
         return this;
     }
@@ -182,7 +180,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putUnescapedComment(CharSequence seq)
+    protected PmdXmlExporter putUnescapedComment(CharSequence seq)
             throws IOException{
         if( ! isBasicLatinOnlyOut() ) return this;
         if(hasOnlyBasicLatin(seq)) return this;
@@ -197,7 +195,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putI18nName(I18nText text) throws IOException{
+    protected PmdXmlExporter putI18nName(I18nText text) throws IOException{
         for(String lang639 : text.lang639CodeList()){
             if(lang639.equals(I18nText.CODE639_PRIMARY)) continue;
             String name = text.getI18nText(lang639);
@@ -219,7 +217,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putNumberedIdAttr(CharSequence attrName,
+    protected PmdXmlExporter putNumberedIdAttr(CharSequence attrName,
                                                  CharSequence prefix,
                                                  int num )
             throws IOException{
@@ -237,7 +235,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putNumberedIdAttr(CharSequence attrName,
+    protected PmdXmlExporter putNumberedIdAttr(CharSequence attrName,
                                                  CharSequence prefix,
                                                  SerialNumbered numbered )
             throws IOException{
@@ -251,7 +249,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putPosition(MkPos3D position)
+    protected PmdXmlExporter putPosition(MkPos3D position)
             throws IOException{
         putRawText("<position ");
         putFloatAttr("x", (float) position.getXpos()).sp();
@@ -267,7 +265,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putRadRotation(Rad3d rotation)
+    protected PmdXmlExporter putRadRotation(Rad3d rotation)
             throws IOException{
         putRawText("<radRotation ");
         putFloatAttr("xRad", rotation.getXRad()).sp();
@@ -283,7 +281,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putLocalNameComment(I18nText name)
+    protected PmdXmlExporter putLocalNameComment(I18nText name)
             throws IOException{
         String localName = name.getText();
         if(localName.isEmpty()){
@@ -300,7 +298,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    protected XmlExporter putPrimaryNameAttr(CharSequence attrName,
+    protected PmdXmlExporter putPrimaryNameAttr(CharSequence attrName,
                                                    I18nText name)
             throws IOException{
         String primaryName = name.getPrimaryText();
@@ -311,9 +309,13 @@ public class XmlExporter extends BasicXmlExporter{
     /**
      * PMDモデルデータをXML形式で出力する。
      * @param model PMDモデルデータ
+     * @param xmlOut XML出力先
      * @throws IOException 出力エラー
      */
-    public void putPmdModel(PmdModel model) throws IOException{
+    public void putPmdModel(PmdModel model, Appendable xmlOut)
+            throws IOException{
+        setAppendable(xmlOut);
+
         ind().putRawText("<?xml")
                 .sp().putAttr("version","1.0")
                 .sp().putAttr("encoding","UTF-8")
@@ -384,7 +386,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putModelInfo(PmdModel model)
+    private PmdXmlExporter putModelInfo(PmdModel model)
             throws IOException{
         I18nText modelName = model.getModelName();
         putI18nName(modelName);
@@ -407,7 +409,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putDescription(CharSequence lang639,
+    private PmdXmlExporter putDescription(CharSequence lang639,
                                               CharSequence content)
             throws IOException{
         String text = content.toString();
@@ -469,7 +471,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putMetaInfo(PmdModel model) throws IOException{
+    private PmdXmlExporter putMetaInfo(PmdModel model) throws IOException{
         ind().putRawText("<license>").ln();
         ind().putRawText("</license>").ln(2);
 
@@ -499,7 +501,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putMaterialList(PmdModel model)
+    private PmdXmlExporter putMaterialList(PmdModel model)
             throws IOException{
         ind().putRawText("<materialList>").ln();
 
@@ -526,7 +528,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putMaterial(Material material, int no)
+    private PmdXmlExporter putMaterial(Material material, int no)
             throws IOException{
         String bool;
         if(material.getEdgeAppearance()) bool = "true";
@@ -620,7 +622,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putToonMap(PmdModel model)
+    private PmdXmlExporter putToonMap(PmdModel model)
             throws IOException{
         ind().putRawText("<toonMap>").ln();
         pushNest();
@@ -642,7 +644,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putToon(ToonMap map, int index)
+    private PmdXmlExporter putToon(ToonMap map, int index)
             throws IOException{
         putRawText("<toonDef ");
         putNumberedIdAttr("toonFileId", PFX_TOONFILE, index).sp();
@@ -660,7 +662,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putSurfaceGroupList(PmdModel model)
+    private PmdXmlExporter putSurfaceGroupList(PmdModel model)
             throws IOException{
         ind().putRawText("<surfaceGroupList>").ln();
 
@@ -688,7 +690,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putSurfaceList(List<Surface> surfaceList,
+    private PmdXmlExporter putSurfaceList(List<Surface> surfaceList,
                                               int index)
             throws IOException{
         ind().putRawText("<surfaceGroup ");
@@ -712,7 +714,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putSurface(Surface surface)
+    private PmdXmlExporter putSurface(Surface surface)
             throws IOException{
         ind().putRawText("<surface ");
 
@@ -734,7 +736,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putVertexList(PmdModel model)
+    private PmdXmlExporter putVertexList(PmdModel model)
             throws IOException{
         ind().putRawText("<vertexList>").ln();
 
@@ -759,7 +761,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putVertex(Vertex vertex)
+    private PmdXmlExporter putVertex(Vertex vertex)
             throws IOException{
         String bool;
         if(vertex.getEdgeAppearance()) bool = "true";
@@ -808,7 +810,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putBoneList(PmdModel model)
+    private PmdXmlExporter putBoneList(PmdModel model)
             throws IOException{
         ind().putRawText("<boneList>").ln();
         pushNest();
@@ -834,7 +836,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putBone(BoneInfo bone)
+    private PmdXmlExporter putBone(BoneInfo bone)
             throws IOException{
         I18nText i18nName = bone.getBoneName();
         BoneType type = bone.getBoneType();
@@ -932,7 +934,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putBoneGroupList(PmdModel model)
+    private PmdXmlExporter putBoneGroupList(PmdModel model)
             throws IOException{
         ind().putRawText("<boneGroupList>").ln();
 
@@ -958,7 +960,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putBoneGroup(BoneGroup group)
+    private PmdXmlExporter putBoneGroup(BoneGroup group)
             throws IOException{
         I18nText i18nName = group.getGroupName();
 
@@ -990,7 +992,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putIKChainList(PmdModel model)
+    private PmdXmlExporter putIKChainList(PmdModel model)
             throws IOException{
         ind().putRawText("<ikChainList>").ln();
 
@@ -1015,7 +1017,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putIKChain(IKChain chain)
+    private PmdXmlExporter putIKChain(IKChain chain)
             throws IOException{
         int depth = chain.getIKDepth();
         float weight = chain.getIKWeight();
@@ -1049,7 +1051,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putMorphList(PmdModel model)
+    private PmdXmlExporter putMorphList(PmdModel model)
             throws IOException{
         ind().putRawText("<morphList>").ln();
         pushNest();
@@ -1081,7 +1083,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putMorphPart(MorphPart part)
+    private PmdXmlExporter putMorphPart(MorphPart part)
             throws IOException{
         I18nText i18nName = part.getMorphName();
         String primary = i18nName.getPrimaryText();
@@ -1121,7 +1123,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putRigidList(PmdModel model)
+    private PmdXmlExporter putRigidList(PmdModel model)
             throws IOException{
         ind().putRawText("<rigidList>").ln();
         pushNest();
@@ -1147,7 +1149,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putRigid(RigidInfo rigid)
+    private PmdXmlExporter putRigid(RigidInfo rigid)
             throws IOException{
         BoneInfo linkedBone = rigid.getLinkedBone();
         I18nText i18nName = rigid.getRigidName();
@@ -1203,7 +1205,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putRigidShape(RigidShape shape)
+    private PmdXmlExporter putRigidShape(RigidShape shape)
             throws IOException{
         RigidShapeType type = shape.getShapeType();
 
@@ -1239,7 +1241,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putDynamics(DynamicsInfo dynamics)
+    private PmdXmlExporter putDynamics(DynamicsInfo dynamics)
             throws IOException{
         ind().putRawText("<dynamics").ln();
         pushNest();
@@ -1262,7 +1264,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putRigidGroupList(PmdModel model)
+    private PmdXmlExporter putRigidGroupList(PmdModel model)
             throws IOException{
         ind().putRawText("<rigidGroupList>").ln(2);
         pushNest();
@@ -1315,7 +1317,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putJointList(PmdModel model)
+    private PmdXmlExporter putJointList(PmdModel model)
             throws IOException{
         ind().putRawText("<jointList>").ln();
 
@@ -1340,7 +1342,7 @@ public class XmlExporter extends BasicXmlExporter{
      * @return this本体
      * @throws IOException 出力エラー
      */
-    private XmlExporter putJoint(JointInfo joint)
+    private PmdXmlExporter putJoint(JointInfo joint)
             throws IOException{
         I18nText i18nName = joint.getJointName();
 
index bf1a049..07a24bb 100644 (file)
@@ -7,9 +7,13 @@
 
 package jp.sfjp.mikutoga.pmd2xml;
 
+import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.nio.charset.Charset;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -19,9 +23,9 @@ import jp.sfjp.mikutoga.pmd.IllegalPmdDataException;
 import jp.sfjp.mikutoga.pmd.binio.PmdExporter;
 import jp.sfjp.mikutoga.pmd.binio.PmdLoader;
 import jp.sfjp.mikutoga.pmd.model.PmdModel;
+import jp.sfjp.mikutoga.pmd.xml.PmdXmlExporter;
 import jp.sfjp.mikutoga.pmd.xml.Schema101009;
 import jp.sfjp.mikutoga.pmd.xml.Schema130128;
-import jp.sfjp.mikutoga.pmd.xml.XmlExporter;
 import jp.sfjp.mikutoga.pmd.xml.XmlLoader;
 import jp.sfjp.mikutoga.pmd.xml.XmlModelFileType;
 import jp.sourceforge.mikutoga.xml.BotherHandler;
@@ -37,6 +41,10 @@ import org.xml.sax.SAXException;
  */
 public class Pmd2XmlConv {
 
+    /** デフォルトエンコーディング。 */
+    private static final Charset CS_UTF8 = Charset.forName("UTF-8");
+
+
     private ModelFileType inTypes  = ModelFileType.NONE;
     private ModelFileType outTypes = ModelFileType.NONE;
     private String newLine = "\r\n";
@@ -342,14 +350,18 @@ public class Pmd2XmlConv {
      */
     private void xmlOut(PmdModel model, OutputStream ostream)
             throws IOException, IllegalPmdDataException{
-        XmlExporter exporter = new XmlExporter(ostream);
+        PmdXmlExporter exporter = new PmdXmlExporter();
 
         XmlModelFileType xmlType = this.outTypes.toXmlType();
         exporter.setXmlFileType(xmlType);
         exporter.setNewLine(this.newLine);
         exporter.setGenerator(this.generator);
 
-        exporter.putPmdModel(model);
+        Writer writer;
+        writer = new OutputStreamWriter(ostream, CS_UTF8);
+        writer = new BufferedWriter(writer);
+
+        exporter.putPmdModel(model, writer);
 
         exporter.close();