OSDN Git Service

改行コード指定
[jindolf/JinArchiver.git] / src / main / java / jp / sourceforge / jindolf / archiver / TopicData.java
1 /*
2  * topic data
3  *
4  * License : The MIT License
5  * Copyright(c) 2008 olyutorskii
6  */
7
8 package jp.sourceforge.jindolf.archiver;
9
10 import java.io.IOException;
11 import java.io.Writer;
12 import java.util.LinkedList;
13 import java.util.List;
14 import jp.sourceforge.jindolf.parser.DecodedContent;
15
16 /**
17  * テキスト行の集合。
18  */
19 public abstract class TopicData{
20
21     private static final DecodedContent BREAK = new DecodedContent("\n");
22
23     private final List<DecodedContent> lineList =
24             new LinkedList<DecodedContent>();
25
26     /**
27      * コンストラクタ。
28      */
29     protected TopicData(){
30         super();
31         return;
32     }
33
34     /**
35      * 行を追加する。
36      * @param content 行を構成する文字列
37      */
38     public void addLine(DecodedContent content){
39         this.lineList.add(content);
40         return;
41     }
42
43     /**
44      * 行ブレークを追加する。
45      */
46     public void addBreak(){
47         this.lineList.add(BREAK);
48         return;
49     }
50
51     /**
52      * 行数を取得する。
53      * @return 行数
54      */
55     public int getLineNum(){
56         return this.lineList.size();
57     }
58
59     /**
60      * 最初の行を取得する。
61      * @return 最初の行
62      */
63     public DecodedContent get1stLine(){
64         return this.lineList.get(0);
65     }
66
67     /**
68      * 1行li要素をXML出力する。
69      * @param writer 出力先
70      * @throws IOException 出力エラー
71      */
72     public void dumpLines(Writer writer) throws IOException{
73         DecodedContent lastLine = null;
74         DecodedContent lastContent = null;
75
76         for(DecodedContent content : this.lineList){
77             lastContent = content;
78             if(content == BREAK){
79                 if(lastLine != null){
80                     writer.append("</li>\n");
81                     lastLine = null;
82                 }else{
83                     writer.append("<li/>\n");
84                 }
85             }else{
86                 if(lastLine == null){
87                     writer.append("<li>");
88                 }
89                 XmlUtils.dumpDecodedContent(writer, content);
90                 lastLine = content;
91             }
92         }
93
94         if(lastLine != null){
95             writer.append("</li>\n");
96         }else if(lastContent == BREAK){
97             writer.append("<li/>\n");
98         }
99
100         return;
101     }
102
103     /**
104      * 要素をXML出力する。
105      * @param writer 出力先
106      * @throws IOException 出力エラー
107      */
108     public abstract void dumpXml(Writer writer) throws IOException;
109
110 }