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 XmlExporter putRawCh(char ch) throws IOException;
31 * @throws IOException 出力エラー
33 XmlExporter putRawText(CharSequence seq) throws IOException;
38 * @throws IOException 出力エラー
40 XmlExporter sp() throws IOException;
44 * @param count 空白回数。0以下の場合は何も出力しない。
46 * @throws IOException 出力エラー
48 XmlExporter sp(int count) throws IOException;
58 * @param newLine 改行文字列
59 * @throws NullPointerException 引数がnull
61 void setNewLine(String newLine) throws NullPointerException;
66 * @throws IOException 出力エラー
68 XmlExporter ln() throws IOException;
72 * @param count 改行回数。0以下の場合は何も出力しない。
74 * @throws IOException 出力エラー
76 XmlExporter ln(int count) throws IOException;
82 String getIndentUnit();
89 * @param indUnit インデント単位文字列。
90 * @throws NullPointerException 引数がnull
92 void setIndentUnit(String indUnit) throws NullPointerException;
101 * インデントレベル0の状態をさらに上げようとした場合、何も起こらない。
112 int getIndentLevel();
116 * インデント単位文字列をネストレベル回数分出力する。
118 * @throws IOException 出力エラー
120 XmlExporter ind() throws IOException;
123 * BasicLatin文字だけを出力する状態か判定する。
127 * @return BasicLatin文字だけで出力するならtrue
129 boolean isBasicLatinOnlyOut();
132 * BasicLatin文字だけで出力するか設定する。
134 * <p>BasicLatin以外の文字(≒日本語)を、そのまま出力するか、
139 * @param bool BasicLatin文字だけで出力するならtrue
141 void setBasicLatinOnlyOut(boolean bool);
144 * 指定された文字を16進2桁の文字参照形式で出力する。
146 * <p>「A」は「&#x41;」になる。
148 * <p>2桁で出力できない場合(>0x00ff)は4桁で出力する。
152 * @throws IOException 出力エラー
153 * @see <a href="http://www.w3.org/TR/xml11/#NT-CharRef">
154 * W3C XML1.1 Character Reference
157 XmlExporter putCharRef2Hex(char ch) throws IOException;
160 * 指定された文字を16進4桁の文字参照形式で出力する。
162 * <p>「亜」は「&#x4E9C;」になる。
164 * <p>UCS4に伴うサロゲートペアは未サポート
168 * @throws IOException 出力エラー
169 * @see <a href="http://www.w3.org/TR/xml11/#NT-CharRef">
170 * W3C XML1.1 Character Reference
173 XmlExporter putCharRef4Hex(char ch) throws IOException;
176 * 要素の中身および属性値中身を出力する。
178 * <p>XMLの構文規則を守る上で必要な各種エスケープ処理が行われる。
182 * @throws IOException 出力エラー
184 XmlExporter putCh(char ch) throws IOException;
187 * 要素の中身および属性値中身を出力する。
189 * <p>必要に応じてXML定義済み実体文字が割り振られた文字、
190 * コントロールコード、および非BasicLatin文字がエスケープされる。
192 * <p>半角円通貨記号U+00A5はバックスラッシュU+005Cに置換される。
194 * <p>連続するスペースU+0020の2文字目以降は文字参照化される。
196 * <p>全角スペースその他空白文字は無条件に文字参照化される。
200 * @throws IOException 出力エラー
202 XmlExporter putContent(CharSequence content) throws IOException;
207 * <p>コメント中の'\n'記号出現に伴い、
208 * あらかじめ指定された改行文字が出力される。
210 * <p>コメント中の'\n'以外のコントロールコードは
211 * Control Pictures(U+2400〜)で代替される。
213 * <p>それ以外の非BasicLatin文字はそのまま出力される。
215 * <p>連続するハイフン(-)記号間には強制的にスペースが挿入される。
217 * @param comment コメント内容
219 * @throws IOException 出力エラー
220 * <a href="http://www.unicode.org/charts/PDF/U2400.pdf">
221 * Unicode 6.2 Controll Pictures
224 XmlExporter putCommentContent(CharSequence comment) throws IOException;
228 * コメント内部の頭及び末尾に空白が1つ挿入される。
229 * @param comment コメント内容
231 * @throws IOException 出力エラー
233 XmlExporter putLineComment(CharSequence comment) throws IOException;
238 * <p>コメント内部の頭の前に改行が出力される。
240 * <p>コメント内部の末尾が改行でない場合、改行が挿入される。
242 * <p>ブロックコメント末尾は改行で終わる。
246 * @param comment コメント内容
248 * @throws IOException 出力エラー
250 XmlExporter putBlockComment(CharSequence comment) throws IOException;
256 * @throws IOException 出力エラー
258 XmlExporter putOpenSTag(CharSequence tagName) throws IOException;
263 * @throws IOException 出力エラー
265 XmlExporter putCloseSTag() throws IOException;
268 * 属性の無いシンプルな開始タグ表記を出力する。
271 * @throws IOException 出力エラー
273 XmlExporter putSimpleSTag(CharSequence tagName) throws IOException;
279 * @throws IOException 出力エラー
281 XmlExporter putETag(CharSequence tagName) throws IOException;
287 * @throws IOException 出力エラー
289 XmlExporter putSimpleEmpty(CharSequence tagName) throws IOException;
294 * @throws IOException 出力エラー
296 XmlExporter putCloseEmpty() throws IOException;
299 * xsd:int値をXMLスキーマ準拠の形式で出力する。
302 * @throws IOException 出力エラー
303 * @see <a href="http://www.w3.org/TR/xmlschema11-2/#int">
304 * XML Schema 1.1 Datatypes int
307 XmlExporter putXsdInt(int iVal) throws IOException;
310 * xsd:float値をXMLスキーマ準拠の形式で出力する。
313 * @throws IOException 出力エラー
314 * @see <a href="http://www.w3.org/TR/xmlschema11-2/#sec-lex-float">
315 * XML Schema 1.1 Datatypes float Lexical Mapping
318 XmlExporter putXsdFloat(float fVal) throws IOException;
322 * @param attrName 属性名
325 * @throws IOException 出力エラー
327 XmlExporter putIntAttr(CharSequence attrName, int iVal)
332 * @param attrName 属性名
335 * @throws IOException 出力エラー
337 XmlExporter putFloatAttr(CharSequence attrName, float fVal)
342 * @param attrName 属性名
343 * @param content 属性内容
345 * @throws IOException 出力エラー
347 XmlExporter putAttr(CharSequence attrName, CharSequence content)