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 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
public class ParagraphHandler extends TextElementHandler { |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
0 |
private StringBuffer _text = null; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
0 |
private String _flagID = null; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
0 |
private WaitHandler _waitHandler = new WaitHandler(); |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public ParagraphHandler() |
48 |
|
{ |
49 |
0 |
super(); |
50 |
0 |
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private boolean performParagraph() |
58 |
|
{ |
59 |
0 |
TextCoordinator coordinator = getTextCoordinator(); |
60 |
0 |
String paragraph = new String( _text ); |
61 |
0 |
if( paragraph.length() > 0 ) { |
62 |
0 |
coordinator.pushText( new String(_text) ); |
63 |
0 |
_text = new StringBuffer( 48 ); |
64 |
0 |
return true; |
65 |
|
} |
66 |
|
else { |
67 |
0 |
return false; |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
public void startDocument() |
76 |
|
{ |
77 |
0 |
Logger.debug( "[scene] start paragraph" ); |
78 |
0 |
_text = new StringBuffer( 48 ); |
79 |
0 |
_flagID = null; |
80 |
0 |
getTextCoordinator().begin(); |
81 |
0 |
} |
82 |
|
|
83 |
|
public void endDocument() |
84 |
|
{ |
85 |
0 |
Logger.debug( "[scene] end paragraph" ); |
86 |
0 |
if( performParagraph() ) { |
87 |
0 |
stop(); |
88 |
|
} |
89 |
0 |
_text = null; |
90 |
0 |
getTextCoordinator().commit(); |
91 |
|
|
92 |
0 |
if( _flagID != null ) { |
93 |
0 |
getSceneContext().declareFlag( _flagID, FlagScope.SESSION ); |
94 |
|
} |
95 |
0 |
} |
96 |
|
|
97 |
|
public void startElement( String namespaceURI, String localName, String qName, Attributes attrs ) |
98 |
|
throws org.xml.sax.SAXException |
99 |
|
{ |
100 |
0 |
if( localName.equals("wait") ) { |
101 |
0 |
performParagraph(); |
102 |
0 |
_waitHandler.waitFor( attrs ); |
103 |
0 |
} |
104 |
0 |
else if( localName.equals("p") ) { |
105 |
0 |
_flagID = PSMLUtil.getAttributeValue( attrs, "flag" ); |
106 |
|
} |
107 |
0 |
} |
108 |
|
|
109 |
|
public void endElement( String namespaceURI, String localName, String qName ) |
110 |
|
{ |
111 |
|
|
112 |
0 |
} |
113 |
|
|
114 |
|
public void characters( char[] ch, int begin, class="keyword">int length ) |
115 |
|
{ |
116 |
0 |
_text.append( ch, begin, length ); |
117 |
0 |
} |
118 |
|
} |