OSDN Git Service

Appendable対応
authorOlyutorskii <olyutorskii@users.osdn.me>
Tue, 21 May 2013 14:10:18 +0000 (23:10 +0900)
committerOlyutorskii <olyutorskii@users.osdn.me>
Tue, 21 May 2013 14:10:18 +0000 (23:10 +0900)
pom.xml
src/main/config/checks.xml
src/main/java/jp/sourceforge/mikutoga/xml/AbstractXmlExporter.java
src/main/java/jp/sourceforge/mikutoga/xml/BasicXmlExporter.java
src/main/java/jp/sourceforge/mikutoga/xml/ProxyXmlExporter.java
src/main/java/jp/sourceforge/mikutoga/xml/XmlExporter.java

diff --git a/pom.xml b/pom.xml
index 732123b..3727005 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <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 445ddf4..3e31cbb 100644 (file)
@@ -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" />
 
 
index 8344b4c..b8e3c5c 100644 (file)
@@ -13,7 +13,7 @@ import java.util.regex.Pattern;
 import javax.xml.bind.DatatypeConverter;
 
 /**
- * XMLエクスポータの半実装。
+ * Appendable実装に依存したXMLエクスポータの半実装。
  * UCS4は未サポート。
  */
 abstract class AbstractXmlExporter implements XmlExporter{
@@ -109,6 +109,36 @@ abstract class AbstractXmlExporter implements XmlExporter{
 
     /**
      * {@inheritDoc}
+     * @param ch {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public abstract Appendable append(char ch) throws IOException;
+
+    /**
+     * {@inheritDoc}
+     * @param seq {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public abstract Appendable append(CharSequence seq) throws IOException;
+
+    /**
+     * {@inheritDoc}
+     * @param seq {@inheritDoc}
+     * @param start {@inheritDoc}
+     * @param end {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public abstract Appendable append(CharSequence seq, int start, int end)
+            throws IOException;
+
+    /**
+     * {@inheritDoc}
      * @throws IOException {@inheritDoc}
      */
     @Override
@@ -121,6 +151,7 @@ abstract class AbstractXmlExporter implements XmlExporter{
     @Override
     public abstract void close() throws IOException;
 
+
     /**
      * {@inheritDoc}
      * @param ch {@inheritDoc}
@@ -128,8 +159,10 @@ abstract class AbstractXmlExporter implements XmlExporter{
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public abstract XmlExporter putRawCh(char ch)
-            throws IOException;
+    public XmlExporter putRawCh(char ch) throws IOException{
+        append(ch);
+        return this;
+    }
 
     /**
      * {@inheritDoc}
@@ -138,9 +171,11 @@ abstract class AbstractXmlExporter implements XmlExporter{
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public abstract XmlExporter putRawText(CharSequence seq)
-            throws IOException;
-
+    public XmlExporter putRawText(CharSequence seq)
+            throws IOException{
+        append(seq);
+        return this;
+    }
 
     /**
      * {@inheritDoc}
index 5e3c1fa..53592d4 100644 (file)
@@ -7,83 +7,74 @@
 
 package jp.sourceforge.mikutoga.xml;
 
-import java.io.BufferedWriter;
 import java.io.Closeable;
 import java.io.Flushable;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.nio.charset.Charset;
 
 /**
  * Appendable用XMLエクスポータ実装。
  */
 public class BasicXmlExporter extends AbstractXmlExporter{
 
-    /** デフォルトエンコーディング。 */
-    private static final Charset CS_UTF8 = Charset.forName("UTF-8");
-
-
-    private final Appendable appendable;
+    private Appendable appendable = null;
 
 
     /**
      * コンストラクタ。
-     * 文字エンコーディングはUTF-8が用いられる。
-     * @param stream 出力ストリーム
      */
-    public BasicXmlExporter(OutputStream stream){
-        this(stream, CS_UTF8);
+    public BasicXmlExporter(){
+        super();
         return;
     }
 
+
     /**
-     * コンストラクタ
-     * @param stream 出力ストリーム
-     * @param charSet 文字エンコーディング指定
+     * 出力先アペンダを指定する
+     * @param app 出力先
+     * @throws NullPointerException 引数がnull
      */
-    public BasicXmlExporter(OutputStream stream, Charset charSet){
-        this(
-            new BufferedWriter(
-                new OutputStreamWriter(stream, charSet)
-            )
-        );
+    public void setAppendable(Appendable app) throws NullPointerException{
+        if(app == null) throw new NullPointerException();
+
+        this.appendable = app;
+
         return;
     }
 
     /**
-     * コンストラクタ。
-     * @param appendable 文字列出力
+     * {@inheritDoc}
+     * @param ch {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
      */
-    public BasicXmlExporter(Appendable appendable){
-        super();
-        this.appendable = appendable;
-        return;
+    @Override
+    public Appendable append(char ch) throws IOException{
+        return this.appendable.append(ch);
     }
 
-
     /**
      * {@inheritDoc}
-     * @param ch {@inheritDoc}
+     * @param seq {@inheritDoc}
      * @return {@inheritDoc}
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public BasicXmlExporter putRawCh(char ch) throws IOException{
-        this.appendable.append(ch);
-        return this;
+    public Appendable append(CharSequence seq) throws IOException{
+        return this.appendable.append(seq);
     }
 
     /**
      * {@inheritDoc}
      * @param seq {@inheritDoc}
+     * @param start {@inheritDoc}
+     * @param end {@inheritDoc}
      * @return {@inheritDoc}
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public BasicXmlExporter putRawText(CharSequence seq) throws IOException{
-        this.appendable.append(seq);
-        return this;
+    public Appendable append(CharSequence seq, int start, int end)
+            throws IOException{
+        return this.appendable.append(seq, start, end);
     }
 
     /**
index c1934ea..20af5f1 100644 (file)
@@ -19,11 +19,11 @@ public class ProxyXmlExporter extends AbstractXmlExporter{
 
     /**
      * コンストラクタ。
-     * @param proxy 委譲先
+     * @param delegate 委譲先
      */
-    public ProxyXmlExporter(XmlExporter proxy){
+    public ProxyXmlExporter(XmlExporter delegate){
         super();
-        this.delegate = proxy;
+        this.delegate = delegate;
         return;
     }
 
@@ -35,8 +35,8 @@ public class ProxyXmlExporter extends AbstractXmlExporter{
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public XmlExporter putRawCh(char ch) throws IOException{
-        return this.delegate.putRawCh(ch);
+    public Appendable append(char ch) throws IOException{
+        return this.delegate.append(ch);
     }
 
     /**
@@ -46,8 +46,22 @@ public class ProxyXmlExporter extends AbstractXmlExporter{
      * @throws IOException {@inheritDoc}
      */
     @Override
-    public XmlExporter putRawText(CharSequence seq) throws IOException{
-        return this.delegate.putRawText(seq);
+    public Appendable append(CharSequence seq) throws IOException{
+        return this.delegate.append(seq);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @param seq {@inheritDoc}
+     * @param start {@inheritDoc}
+     * @param end {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public Appendable append(CharSequence seq, int start, int end)
+            throws IOException{
+        return this.delegate.append(seq, start, end);
     }
 
     /**
@@ -72,6 +86,28 @@ public class ProxyXmlExporter extends AbstractXmlExporter{
 
     /**
      * {@inheritDoc}
+     * @param ch {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public XmlExporter putRawCh(char ch) throws IOException{
+        return this.delegate.putRawCh(ch);
+    }
+
+    /**
+     * {@inheritDoc}
+     * @param seq {@inheritDoc}
+     * @return {@inheritDoc}
+     * @throws IOException {@inheritDoc}
+     */
+    @Override
+    public XmlExporter putRawText(CharSequence seq) throws IOException{
+        return this.delegate.putRawText(seq);
+    }
+
+    /**
+     * {@inheritDoc}
      * @return {@inheritDoc}
      */
     @Override
index 9055a5d..fc3436a 100644 (file)
@@ -14,10 +14,10 @@ import java.io.IOException;
 /**
  * XMLエクスポータ基本機能のセット。
  */
-public interface XmlExporter extends Flushable, Closeable{
+public interface XmlExporter extends Appendable, Flushable, Closeable{
 
     /**
-     * 1文字出力する。
+     * 1文字を生出力する。
      * @param ch 文字
      * @return this本体
      * @throws IOException 出力エラー
@@ -25,7 +25,7 @@ public interface XmlExporter extends Flushable, Closeable{
     XmlExporter putRawCh(char ch) throws IOException;
 
     /**
-     * 文字列を出力する。
+     * 文字列を出力する。
      * @param seq 文字列
      * @return this本体
      * @throws IOException 出力エラー
@@ -264,19 +264,18 @@ public interface XmlExporter extends Flushable, Closeable{
     XmlExporter putCloseEmpty() throws IOException;
 
     /**
-     * int値をXMLスキーマ準拠の形式で出力する。
+     * xsd:int値をXMLスキーマ準拠の形式で出力する。
      * @param iVal int値
      * @return this本体
      * @throws IOException 出力エラー
-     * @see java.lang.Integer#toString(int)
-     * @see <a href="http://www.w3.org/TR/xmlschema11-2/#integer">
-     * XML Schema 1.1 Datatypes integer
+     * @see <a href="http://www.w3.org/TR/xmlschema11-2/#int">
+     * XML Schema 1.1 Datatypes int
      * </a>
      */
     XmlExporter putXsdInt(int iVal) throws IOException;
 
     /**
-     * float値をXMLスキーマ準拠の形式で出力する。
+     * xsd:float値をXMLスキーマ準拠の形式で出力する。
      * @param fVal float値
      * @return this本体
      * @throws IOException 出力エラー