From ece235c5e686680fd00b6923d48e44b341eb4718 Mon Sep 17 00:00:00 2001 From: Olyutorskii Date: Tue, 21 May 2013 23:10:18 +0900 Subject: [PATCH] =?utf8?q?Appendable=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- src/main/config/checks.xml | 5 +- .../mikutoga/xml/AbstractXmlExporter.java | 47 +++++++++++++--- .../sourceforge/mikutoga/xml/BasicXmlExporter.java | 63 ++++++++++------------ .../sourceforge/mikutoga/xml/ProxyXmlExporter.java | 50 ++++++++++++++--- .../jp/sourceforge/mikutoga/xml/XmlExporter.java | 15 +++--- 6 files changed, 124 insertions(+), 60 deletions(-) diff --git a/pom.xml b/pom.xml index 732123b..3727005 100644 --- a/pom.xml +++ b/pom.xml @@ -243,7 +243,7 @@ org.apache.maven.plugins maven-site-plugin - 3.2 + 3.3 true ja @@ -354,7 +354,7 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 2.6 + 2.7 true true diff --git a/src/main/config/checks.xml b/src/main/config/checks.xml index 445ddf4..3e31cbb 100644 --- a/src/main/config/checks.xml +++ b/src/main/config/checks.xml @@ -42,6 +42,7 @@ + @@ -50,7 +51,9 @@ - + + + diff --git a/src/main/java/jp/sourceforge/mikutoga/xml/AbstractXmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/xml/AbstractXmlExporter.java index 8344b4c..b8e3c5c 100644 --- a/src/main/java/jp/sourceforge/mikutoga/xml/AbstractXmlExporter.java +++ b/src/main/java/jp/sourceforge/mikutoga/xml/AbstractXmlExporter.java @@ -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} diff --git a/src/main/java/jp/sourceforge/mikutoga/xml/BasicXmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/xml/BasicXmlExporter.java index 5e3c1fa..53592d4 100644 --- a/src/main/java/jp/sourceforge/mikutoga/xml/BasicXmlExporter.java +++ b/src/main/java/jp/sourceforge/mikutoga/xml/BasicXmlExporter.java @@ -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); } /** diff --git a/src/main/java/jp/sourceforge/mikutoga/xml/ProxyXmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/xml/ProxyXmlExporter.java index c1934ea..20af5f1 100644 --- a/src/main/java/jp/sourceforge/mikutoga/xml/ProxyXmlExporter.java +++ b/src/main/java/jp/sourceforge/mikutoga/xml/ProxyXmlExporter.java @@ -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 diff --git a/src/main/java/jp/sourceforge/mikutoga/xml/XmlExporter.java b/src/main/java/jp/sourceforge/mikutoga/xml/XmlExporter.java index 9055a5d..fc3436a 100644 --- a/src/main/java/jp/sourceforge/mikutoga/xml/XmlExporter.java +++ b/src/main/java/jp/sourceforge/mikutoga/xml/XmlExporter.java @@ -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 - * XML Schema 1.1 Datatypes integer + * @see + * XML Schema 1.1 Datatypes int * */ XmlExporter putXsdInt(int iVal) throws IOException; /** - * float値をXMLスキーマ準拠の形式で出力する。 + * xsd:float値をXMLスキーマ準拠の形式で出力する。 * @param fVal float値 * @return this本体 * @throws IOException 出力エラー -- 2.11.0