1
2
3
4
5
6
7
8
9 package tsukuba_bunko.peko.scenario.text;
10
11 import org.xml.sax.Attributes;
12
13 import tsukuba_bunko.peko.Logger;
14
15 import tsukuba_bunko.peko.scenario.FlagScope;
16 import tsukuba_bunko.peko.scenario.PSMLUtil;
17
18 import tsukuba_bunko.peko.scenario.util.WaitHandler;
19
20
21 /***
22 * <samp>p</samp> 要素の処理を行う <code>ElementHandler</code> です。
23 * @author $Author: ppoi $
24 * @version $Revision: 1.2 $
25 */
26 public class ParagraphHandler extends TextElementHandler {
27
28 /***
29 * テキストバッファ
30 */
31 private StringBuffer _text = null;
32
33 /***
34 * この要素の評価終了後に設定されるフラグ
35 */
36 private String _flagID = null;
37
38 /***
39 * WaitHandler
40 */
41 private WaitHandler _waitHandler = new WaitHandler();
42
43
44 /***
45 * <code>ParagraphHandler</code> のインスタンスを作成します。
46 */
47 public ParagraphHandler()
48 {
49 super();
50 }
51
52
53 /***
54 * パラグラフを表示します。
55 * @return 文章を表示した場合
56 */
57 private boolean performParagraph()
58 {
59 TextCoordinator coordinator = getTextCoordinator();
60 String paragraph = new String( _text );
61 if( paragraph.length() > 0 ) {
62 coordinator.pushText( new String(_text) );
63 _text = new StringBuffer( 48 );
64 return true;
65 }
66 else {
67 return false;
68 }
69 }
70
71
72
73
74
75 public void startDocument()
76 {
77 Logger.debug( "[scene] start paragraph" );
78 _text = new StringBuffer( 48 );
79 _flagID = null;
80 getTextCoordinator().begin();
81 }
82
83 public void endDocument()
84 {
85 Logger.debug( "[scene] end paragraph" );
86 if( performParagraph() ) {
87 stop();
88 }
89 _text = null;
90 getTextCoordinator().commit();
91
92 if( _flagID != null ) {
93 getSceneContext().declareFlag( _flagID, FlagScope.SESSION );
94 }
95 }
96
97 public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
98 throws org.xml.sax.SAXException
99 {
100 if( localName.equals("wait") ) {
101 performParagraph();
102 _waitHandler.waitFor( attrs );
103 }
104 else if( localName.equals("p") ) {
105 _flagID = PSMLUtil.getAttributeValue( attrs, "flag" );
106 }
107 }
108
109 public void endElement( String namespaceURI, String localName, String qName )
110 {
111
112 }
113
114 public void characters( char[] ch, int begin, int length )
115 {
116 _text.append( ch, begin, length );
117 }
118 }