1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| package com.unitesk.atp.tree.generation; |
33 |
| |
34 |
| import java.util.Stack; |
35 |
| |
36 |
| import com.unitesk.atp.tree.Node; |
37 |
| import com.unitesk.atp.text.generation.BasicGenerator; |
38 |
| import com.unitesk.atp.text.filters.TextReceiver; |
39 |
| import com.unitesk.atp.text.filters.LineSplitFilter; |
40 |
| import com.unitesk.atp.text.filters.IndentFilter; |
41 |
| |
42 |
| |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| |
48 |
| public class TextGeneratorServer extends BasicGenerator implements TextGenerator |
49 |
| { |
50 |
| |
51 |
| |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
0
| public TextGeneratorServer( TextReceiver client )
|
57 |
| { |
58 |
0
| this( client, IndentFilter.DEFAULT_INDENT_STEP );
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
0
| public TextGeneratorServer( TextReceiver client, int indentStep )
|
68 |
| { |
69 |
0
| super( new LineSplitFilter( new IndentFilter( client, indentStep ) ) );
|
70 |
| |
71 |
0
| lineSplitFilter = (LineSplitFilter)this.client;
|
72 |
0
| indentFilter = (IndentFilter)lineSplitFilter.getClient();
|
73 |
0
| out = client;
|
74 |
| |
75 |
0
| setFunction( DEFAULT_NAME, new TreeDefaultFunction() );
|
76 |
| } |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
0
| public void pushNode( Node node )
|
82 |
| { |
83 |
0
| setVariable( DEFAULT_NAME, node );
|
84 |
0
| nodeStack.push( node );
|
85 |
| } |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
0
| public Node getNode()
|
91 |
| { |
92 |
| |
93 |
0
| return (Node)nodeStack.peek();
|
94 |
| } |
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
0
| public void popNode()
|
100 |
| { |
101 |
0
| nodeStack.pop();
|
102 |
| |
103 |
0
| if( nodeStack.empty() )
|
104 |
| { |
105 |
0
| setVariable( DEFAULT_NAME, null );
|
106 |
| } else { |
107 |
0
| setVariable( DEFAULT_NAME, nodeStack.peek() );
|
108 |
| } |
109 |
| } |
110 |
| |
111 |
| |
112 |
| |
113 |
| |
114 |
0
| public void pushIndent( int indent )
|
115 |
| { |
116 |
0
| indentFilter.pushIndent( indent );
|
117 |
| } |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
0
| public int getIndent()
|
123 |
| { |
124 |
0
| return indentFilter.getIndent();
|
125 |
| } |
126 |
| |
127 |
| |
128 |
| |
129 |
| |
130 |
0
| public void incIndent()
|
131 |
| { |
132 |
0
| indentFilter.pushIndent( indentFilter.getIndent()
|
133 |
| + indentFilter.getIndentStep() |
134 |
| ); |
135 |
| } |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
0
| public void decIndent()
|
141 |
| { |
142 |
0
| indentFilter.pushIndent( indentFilter.getIndent()
|
143 |
| - indentFilter.getIndentStep() |
144 |
| ); |
145 |
| } |
146 |
| |
147 |
| |
148 |
| |
149 |
| |
150 |
0
| public void popIndent()
|
151 |
| { |
152 |
0
| indentFilter.popIndent();
|
153 |
| } |
154 |
| |
155 |
| |
156 |
| |
157 |
| |
158 |
0
| public void list( String index
|
159 |
| , int start |
160 |
| , int end |
161 |
| , String str |
162 |
| , String separator |
163 |
| ) |
164 |
| { |
165 |
0
| int from;
|
166 |
0
| int to;
|
167 |
0
| int step;
|
168 |
| |
169 |
0
| if( start < end )
|
170 |
| { |
171 |
0
| from = start;
|
172 |
0
| to = end;
|
173 |
0
| step = 1;
|
174 |
| } else |
175 |
0
| if( end < start )
|
176 |
| { |
177 |
0
| from = start - 1;
|
178 |
0
| to = end - 1;
|
179 |
0
| step = -1;
|
180 |
| } else { |
181 |
0
| return;
|
182 |
| } |
183 |
0
| for( int i = from; i != to; i += step )
|
184 |
| { |
185 |
0
| Object old_var = setVariable( index, new Integer( i ) );
|
186 |
| |
187 |
0
| txt( str );
|
188 |
| |
189 |
0
| if( i + step != to && separator != null )
|
190 |
| { |
191 |
0
| txt( separator );
|
192 |
| } |
193 |
| |
194 |
0
| setVariable( index, old_var );
|
195 |
| } |
196 |
| } |
197 |
| |
198 |
| |
199 |
| |
200 |
| |
201 |
0
| public void nl()
|
202 |
| { |
203 |
0
| lineSplitFilter.nl();
|
204 |
| } |
205 |
| |
206 |
| |
207 |
| |
208 |
| |
209 |
| |
210 |
| |
211 |
| |
212 |
0
| public void txtAsIs( String str )
|
213 |
| { |
214 |
0
| indentFilter.txt( str );
|
215 |
| } |
216 |
| |
217 |
| |
218 |
| |
219 |
| |
220 |
| protected LineSplitFilter lineSplitFilter; |
221 |
| |
222 |
| |
223 |
| |
224 |
| protected IndentFilter indentFilter; |
225 |
| |
226 |
| |
227 |
| |
228 |
| |
229 |
| protected TextReceiver out; |
230 |
| |
231 |
| |
232 |
| |
233 |
| |
234 |
| private Stack nodeStack = new Stack(); |
235 |
| } |