4 * License : The MIT License
5 * Copyright(c) 2013 MikuToga Partners
8 package jp.sfjp.mikutoga.xml;
10 import java.io.Closeable;
11 import java.io.Flushable;
12 import java.io.IOException;
17 public interface XmlExporter extends Appendable, Flushable, Closeable{
23 * @throws IOException 出力エラー
25 public abstract XmlExporter putRawCh(char ch) throws IOException;
31 * @throws IOException 出力エラー
33 public abstract XmlExporter putRawText(CharSequence seq)
39 * @throws IOException 出力エラー
41 public abstract XmlExporter sp() throws IOException;
45 * @param count 空白回数。0以下の場合は何も出力しない。
47 * @throws IOException 出力エラー
49 public abstract XmlExporter sp(int count) throws IOException;
55 public abstract String getNewLine();
59 * @param newLine 改行文字列
60 * @throws NullPointerException 引数がnull
62 public abstract void setNewLine(String newLine)
63 throws NullPointerException;
68 * @throws IOException 出力エラー
70 public abstract XmlExporter ln() throws IOException;
74 * @param count 改行回数。0以下の場合は何も出力しない。
76 * @throws IOException 出力エラー
78 public abstract XmlExporter ln(int count) throws IOException;
84 public abstract String getIndentUnit();
91 * @param indUnit インデント単位文字列。
92 * @throws NullPointerException 引数がnull
94 public abstract void setIndentUnit(String indUnit)
95 throws NullPointerException;
100 public abstract void pushNest();
104 * インデントレベル0の状態をさらに上げようとした場合、何も起こらない。
106 public abstract void popNest();
115 public abstract int getIndentLevel();
119 * インデント単位文字列をネストレベル回数分出力する。
121 * @throws IOException 出力エラー
123 public abstract XmlExporter ind() throws IOException;
126 * BasicLatin文字だけを出力する状態か判定する。
130 * @return BasicLatin文字だけで出力するならtrue
132 public abstract boolean isBasicLatinOnlyOut();
135 * BasicLatin文字だけで出力するか設定する。
137 * <p>BasicLatin以外の文字(≒日本語)を、そのまま出力するか、
142 * @param bool BasicLatin文字だけで出力するならtrue
144 public abstract void setBasicLatinOnlyOut(boolean bool);
147 * 指定された文字を16進2桁の文字参照形式で出力する。
149 * <p>「A」は「&#x41;」になる。
151 * <p>2桁で出力できない場合(>0x00ff)は4桁で出力する。
155 * @throws IOException 出力エラー
156 * @see <a href="http://www.w3.org/TR/xml11/#NT-CharRef">
157 * W3C XML1.1 Character Reference
160 public abstract XmlExporter putCharRef2Hex(char ch) throws IOException;
163 * 指定された文字を16進4桁の文字参照形式で出力する。
165 * <p>「亜」は「&#x4E9C;」になる。
167 * <p>UCS4に伴うサロゲートペアは未サポート
171 * @throws IOException 出力エラー
172 * @see <a href="http://www.w3.org/TR/xml11/#NT-CharRef">
173 * W3C XML1.1 Character Reference
176 public abstract XmlExporter putCharRef4Hex(char ch) throws IOException;
179 * 要素の中身および属性値中身を出力する。
181 * <p>XMLの構文規則を守る上で必要な各種エスケープ処理が行われる。
185 * @throws IOException 出力エラー
187 public abstract XmlExporter putCh(char ch) throws IOException;
190 * 要素の中身および属性値中身を出力する。
192 * <p>必要に応じてXML定義済み実体文字が割り振られた文字、
193 * コントロールコード、および非BasicLatin文字がエスケープされる。
195 * <p>半角円通貨記号U+00A5はバックスラッシュU+005Cに置換される。
197 * <p>連続するスペースU+0020の2文字目以降は文字参照化される。
199 * <p>全角スペースその他空白文字は無条件に文字参照化される。
203 * @throws IOException 出力エラー
205 public abstract XmlExporter putContent(CharSequence content)
211 * <p>コメント中の'\n'記号出現に伴い、
212 * あらかじめ指定された改行文字が出力される。
214 * <p>コメント中の'\n'以外のコントロールコードは
215 * Control Pictures(U+2400〜)で代替される。
217 * <p>それ以外の非BasicLatin文字はそのまま出力される。
219 * <p>連続するハイフン(-)記号間には強制的にスペースが挿入される。
221 * @param comment コメント内容
223 * @throws IOException 出力エラー
224 * <a href="http://www.unicode.org/charts/PDF/U2400.pdf">
225 * Unicode 6.2 Controll Pictures
228 public abstract XmlExporter putCommentContent(CharSequence comment)
233 * コメント内部の頭及び末尾に空白が1つ挿入される。
234 * @param comment コメント内容
236 * @throws IOException 出力エラー
238 public abstract XmlExporter putLineComment(CharSequence comment)
244 * <p>コメント内部の頭の前に改行が出力される。
246 * <p>コメント内部の末尾が改行でない場合、改行が挿入される。
248 * <p>ブロックコメント末尾は改行で終わる。
252 * @param comment コメント内容
254 * @throws IOException 出力エラー
256 public abstract XmlExporter putBlockComment(CharSequence comment)
263 * @throws IOException 出力エラー
265 public abstract XmlExporter putOpenSTag(CharSequence tagName)
271 * @throws IOException 出力エラー
273 public abstract XmlExporter putCloseSTag() throws IOException;
276 * 属性の無いシンプルな開始タグ表記を出力する。
279 * @throws IOException 出力エラー
281 public abstract XmlExporter putSimpleSTag(CharSequence tagName)
288 * @throws IOException 出力エラー
290 public abstract XmlExporter putETag(CharSequence tagName)
297 * @throws IOException 出力エラー
299 public abstract XmlExporter putSimpleEmpty(CharSequence tagName)
305 * @throws IOException 出力エラー
307 public abstract XmlExporter putCloseEmpty() throws IOException;
310 * xsd:int値をXMLスキーマ準拠の形式で出力する。
313 * @throws IOException 出力エラー
314 * @see <a href="http://www.w3.org/TR/xmlschema11-2/#int">
315 * XML Schema 1.1 Datatypes int
318 public abstract XmlExporter putXsdInt(int iVal) throws IOException;
321 * xsd:float値をXMLスキーマ準拠の形式で出力する。
324 * @throws IOException 出力エラー
325 * @see <a href="http://www.w3.org/TR/xmlschema11-2/#sec-lex-float">
326 * XML Schema 1.1 Datatypes float Lexical Mapping
329 public abstract XmlExporter putXsdFloat(float fVal) throws IOException;
333 * @param attrName 属性名
336 * @throws IOException 出力エラー
338 public abstract XmlExporter putIntAttr(CharSequence attrName, int iVal)
343 * @param attrName 属性名
346 * @throws IOException 出力エラー
348 public abstract XmlExporter putFloatAttr(
349 CharSequence attrName, float fVal)
354 * @param attrName 属性名
355 * @param content 属性内容
357 * @throws IOException 出力エラー
359 public abstract XmlExporter putAttr(
360 CharSequence attrName, CharSequence content)