Lines 10-17
Link Here
|
10 |
******************************************************************************/ |
10 |
******************************************************************************/ |
11 |
package org.eclipse.equinox.bidi.custom; |
11 |
package org.eclipse.equinox.bidi.custom; |
12 |
|
12 |
|
13 |
import org.eclipse.equinox.bidi.STextEngine; |
|
|
14 |
import org.eclipse.equinox.bidi.STextEnvironment; |
13 |
import org.eclipse.equinox.bidi.STextEnvironment; |
|
|
14 |
import org.eclipse.equinox.bidi.STextHandler; |
15 |
import org.eclipse.equinox.bidi.internal.STextImpl; |
15 |
import org.eclipse.equinox.bidi.internal.STextImpl; |
16 |
|
16 |
|
17 |
/** |
17 |
/** |
Lines 23-32
Link Here
|
23 |
* <ul> |
23 |
* <ul> |
24 |
* <li>Processor instances may be accessed simultaneously by |
24 |
* <li>Processor instances may be accessed simultaneously by |
25 |
* several threads. They should have no instance variables.</li> |
25 |
* several threads. They should have no instance variables.</li> |
26 |
* <li>All the user methods in {@link STextEngine} implement a logic |
26 |
* <li>All the user methods in {@link STextHandler} implement a logic |
27 |
* common to all processors, located in {@link STextImpl}. |
27 |
* common to all processors, located in {@link STextImpl}. |
28 |
* These methods all have a first argument which is a processor |
|
|
29 |
* instance. |
30 |
* The common logic uses processor methods to query the |
28 |
* The common logic uses processor methods to query the |
31 |
* characteristics of the specific processor: |
29 |
* characteristics of the specific processor: |
32 |
* <ul> |
30 |
* <ul> |
Lines 49-63
Link Here
|
49 |
* method, the common logic will repeatedly invoke the processor's |
47 |
* method, the common logic will repeatedly invoke the processor's |
50 |
* {@link #indexOfSpecial indexOfSpecial} method to let it signal the |
48 |
* {@link #indexOfSpecial indexOfSpecial} method to let it signal the |
51 |
* presence of special strings which may further delimit the source text.</li> |
49 |
* presence of special strings which may further delimit the source text.</li> |
52 |
* <li>When such a special case is signalled by the processor, the common |
50 |
* <li>When such a special case is signaled by the processor, the common |
53 |
* logic will call the processor's {@link #processSpecial processSpecial} |
51 |
* logic will call the processor's {@link #processSpecial processSpecial} |
54 |
* method to give it the opportunity to handle it as needed. Typical |
52 |
* method to give it the opportunity to handle it as needed. Typical |
55 |
* actions that the processor may perform are to add directional marks |
53 |
* actions that the processor may perform are to add directional marks |
56 |
* inconditionally (by calling {@link #insertMark insertMark} or |
54 |
* unconditionally (by calling {@link #insertMark insertMark} or |
57 |
* conditionally (by calling {@link #processSeparator processSeparator}).</li> |
55 |
* conditionally (by calling {@link #processSeparator processSeparator}).</li> |
58 |
* </ul> |
56 |
* </ul> |
59 |
* |
57 |
* |
60 |
* @see STextEngine |
58 |
* @see STextHandler |
61 |
* @author Matitiahu Allouche |
59 |
* @author Matitiahu Allouche |
62 |
*/ |
60 |
*/ |
63 |
public class STextProcessor { |
61 |
public class STextProcessor { |
Lines 65-389
Link Here
|
65 |
final private String separators; |
63 |
final private String separators; |
66 |
|
64 |
|
67 |
/** |
65 |
/** |
68 |
* Creates a new instance of the STextProcessor class. |
66 |
* Creates a new instance of the STextProcessor class. |
69 |
*/ |
67 |
*/ |
70 |
public STextProcessor() { |
68 |
public STextProcessor() { |
71 |
separators = ""; //$NON-NLS-1$ |
69 |
separators = ""; //$NON-NLS-1$ |
72 |
} |
70 |
} |
73 |
|
71 |
|
74 |
/** |
72 |
/** |
75 |
* Creates a new instance of the STextProcessor class. |
73 |
* Creates a new instance of the STextProcessor class. |
76 |
* @param separators string consisting of characters that split the text into fragments |
74 |
* |
|
|
75 |
* @param separators string consisting of characters that split |
76 |
* the text into fragments |
77 |
*/ |
77 |
*/ |
78 |
public STextProcessor(String separators) { |
78 |
public STextProcessor(String separators) { |
79 |
this.separators = separators; |
79 |
this.separators = separators; |
80 |
} |
80 |
} |
81 |
|
81 |
|
82 |
/** |
82 |
/** |
83 |
* Locate occurrences of special strings within a structured text |
83 |
* Locate occurrences of special strings within a structured text |
84 |
* and return their indexes one after the other in successive calls. |
84 |
* and return their indexes one after the other in successive calls. |
85 |
* <p> |
85 |
* <p> |
86 |
* This method is called repeatedly from the code implementing |
86 |
* This method is called repeatedly from the code implementing |
87 |
* {@link STextEngine#leanToFullText} if the number of special cases |
87 |
* {@link STextHandler#leanToFullText} if the number of special cases |
88 |
* returned by {@link #getSpecialsCount} is greater than zero. |
88 |
* returned by {@link #getSpecialsCount} is greater than zero. |
89 |
* </p><p> |
89 |
* </p><p> |
90 |
* A processor handling special cases must override this method. |
90 |
* A processor handling special cases must override this method. |
91 |
* </p> |
91 |
* </p> |
92 |
* @param environment the current environment, which may affect the behavior of |
92 |
* @param procData is a group of data accessible by the processor. |
93 |
* the processor. This parameter may be specified as |
|
|
94 |
* <code>null</code>, in which case the |
95 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
96 |
* environment should be assumed. |
97 |
* |
93 |
* |
98 |
* @param text is the structured text string before |
94 |
* @param caseNumber is the number of the special case to locate. |
99 |
* addition of any directional formatting characters. |
95 |
* This number varies from 1 to the number of special cases |
100 |
* |
96 |
* returned by {@link #getSpecialsCount getSpecialsCount} |
101 |
* @param dirProps is a parameter received by <code>indexOfSpecial</code> |
97 |
* for this processor. |
102 |
* uniquely to be used as argument for calls to methods which |
98 |
* The meaning of this number is internal to the class |
103 |
* need it. |
99 |
* implementing <code>indexOfSpecial</code>. |
104 |
* |
|
|
105 |
* @param offsets is a parameter received by <code>indexOfSpecial</code> |
106 |
* uniquely to be used as argument for calls to methods which |
107 |
* need it. |
108 |
* |
109 |
* @param caseNumber number of the special case to locate. |
110 |
* This number varies from 1 to the number of special cases |
111 |
* returned by {@link #getSpecialsCount getSpecialsCount} |
112 |
* for this processor. |
113 |
* The meaning of this number is internal to the class |
114 |
* implementing <code>indexOfSpecial</code>. |
115 |
* |
100 |
* |
116 |
* @param fromIndex the index within <code>text</code> to start |
101 |
* @param fromIndex is the index within <code>text</code> to start |
117 |
* the search from. |
102 |
* the search from. |
118 |
* |
103 |
* |
119 |
* @return the position where the start of the special case |
104 |
* @return the position where the start of the special case |
120 |
* corresponding to <code>caseNumber</code> was located. |
105 |
* corresponding to <code>caseNumber</code> was located. |
121 |
* The method must return the first occurrence of whatever |
106 |
* The method must return the first occurrence of whatever |
122 |
* identifies the start of the special case starting from |
107 |
* identifies the start of the special case starting from |
123 |
* <code>fromIndex</code>. The method does not have to check if |
108 |
* <code>fromIndex</code>. The method does not have to check if |
124 |
* this occurrence appears within the scope of another special |
109 |
* this occurrence appears within the scope of another special |
125 |
* case (e.g. a comment starting delimiter within the scope of |
110 |
* case (e.g. a comment starting delimiter within the scope of |
126 |
* a literal or vice-versa). |
111 |
* a literal or vice-versa). |
127 |
* <br>If no occurrence is found, the method must return -1. |
112 |
* <br>If no occurrence is found, the method must return -1. |
128 |
* |
113 |
* |
129 |
* @throws IllegalStateException If not overridden, this method throws an |
114 |
* @throws IllegalStateException If not overridden, this method throws an |
130 |
* <code>IllegalStateException</code>. This is appropriate behavior |
115 |
* <code>IllegalStateException</code>. This is appropriate behavior |
131 |
* (and does not need to be overridden) for processors whose |
116 |
* (and does not need to be overridden) for processors whose |
132 |
* number of special cases is zero, which means that |
117 |
* number of special cases is zero, which means that |
133 |
* <code>indexOfSpecial</code> should never be called for them. |
118 |
* <code>indexOfSpecial</code> should never be called for them. |
134 |
*/ |
119 |
*/ |
135 |
public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes dirProps, int[] offsets, int caseNumber, int fromIndex) { |
120 |
public int indexOfSpecial(STextProcessorData procData, int caseNumber, int fromIndex) { |
136 |
// This method must be overridden by all subclasses with special cases. |
121 |
// This method must be overridden by all subclasses with special cases. |
137 |
throw new IllegalStateException("A processor with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$ |
122 |
throw new IllegalStateException("A processor with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$ |
138 |
} |
123 |
} |
139 |
|
124 |
|
140 |
/** |
125 |
/** |
141 |
* This method handles special cases specific to this processor. |
126 |
* This method handles special cases specific to this processor. |
142 |
* It is called by {@link STextEngine#leanToFullText} when a special case occurrence |
127 |
* It is called by {@link STextHandler#leanToFullText} when a special case occurrence |
143 |
* is located by {@link #indexOfSpecial}. |
128 |
* is located by {@link #indexOfSpecial}. |
144 |
* <p> |
129 |
* <p> |
145 |
* If a special processing cannot be completed within a current call to |
130 |
* If a special processing cannot be completed within a current call to |
146 |
* <code>processSpecial</code> (for instance, a comment has been started |
131 |
* <code>processSpecial</code> (for instance, a comment has been started |
147 |
* in the current line but its end appears in a following line), |
132 |
* in the current line but its end appears in a following line), |
148 |
* <code>processSpecial</code> should specify a final state by |
133 |
* <code>processSpecial</code> should specify a final <b>state</b> by |
149 |
* putting its value in the first element of the <code>state</code> |
134 |
* calling {@link STextHandler#setState}. |
150 |
* parameter. |
135 |
* The meaning of this <b>state</b> is internal to the processor. |
151 |
* The meaning of this state is internal to the processor. |
136 |
* On a later call to {@link STextHandler#leanToFullText}, |
152 |
* On a later call to {@link STextEngine#leanToFullText} specifying that |
137 |
* <code>processSpecial</code> will be called with that value |
153 |
* state value, <code>processSpecial</code> will be called with that value |
138 |
* for parameter <code>caseNumber</code> and <code>-1</code> for parameter |
154 |
* for parameter <code>caseNumber</code> and <code>-1</code> for parameter |
139 |
* <code>separLocation</code> and should perform whatever initializations are required |
155 |
* <code>separLocation</code> and should perform whatever initializations are required |
140 |
* depending on the <b>state</b>. |
156 |
* depending on the state. |
141 |
* </p><p> |
157 |
* </p><p> |
142 |
* A processor handling special cases (with a number of |
158 |
* A processor handling special cases (with a number of |
143 |
* special cases greater than zero) must override this method. |
159 |
* special cases greater than zero) must override this method. |
144 |
* </p> |
160 |
* </p> |
145 |
* @param procData is a group of data accessible to the processor. |
161 |
* @param environment the current environment, which may affect the behavior of |
|
|
162 |
* the processor. This parameter may be specified as |
163 |
* <code>null</code>, in which case the |
164 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
165 |
* environment should be assumed. |
166 |
* |
167 |
* @param text is the structured text string before |
168 |
* addition of any directional formatting characters. |
169 |
* |
170 |
* @param dirProps is a parameter received by <code>processSpecial</code> |
171 |
* uniquely to be used as argument for calls to methods which |
172 |
* need it. |
173 |
* |
174 |
* @param offsets is a parameter received by <code>processSpecial</code> |
175 |
* uniquely to be used as argument for calls to methods which |
176 |
* need it. |
177 |
* |
178 |
* @param state is an integer array with at least one element. |
179 |
* If the processor needs to signal the occurrence of a |
180 |
* special case which must be passed to the next call to |
181 |
* <code>leanToFullText</code> (for instance, a comment or a |
182 |
* literal started but not closed in the current |
183 |
* <code>text</code>), it must put a value in the first element |
184 |
* of the <code>state</code> parameter. |
185 |
* This number must be >= 1 and less or equal to the number of special |
186 |
* cases returned by {@link #getSpecialsCount getSpecialsCount} |
187 |
* by this processor. |
188 |
* This number is passed back to the caller |
189 |
* and should be specified as <code>state</code> argument |
190 |
* in the next call to <code>leanToFullText</code> together |
191 |
* with the continuation text. |
192 |
* The meaning of this number is internal to the processor. |
193 |
* |
146 |
* |
194 |
* @param caseNumber number of the special case to handle. |
147 |
* @param caseNumber number of the special case to handle. |
195 |
* |
148 |
* |
196 |
* @param separLocation the position returned by |
149 |
* @param separLocation the position returned by |
197 |
* {@link #indexOfSpecial indexOfSpecial}. In calls to |
150 |
* {@link #indexOfSpecial indexOfSpecial}. In calls to |
198 |
* {@link STextEngine#leanToFullText leanToFullText} and other |
151 |
* {@link STextHandler#leanToFullText leanToFullText} and other |
199 |
* methods of {@link STextEngine} specifying a non-null |
152 |
* methods of {@link STextHandler} setting a non-null |
200 |
* <code>state</code> parameter, <code>processSpecial</code> is |
153 |
* <b>state</b> value, <code>processSpecial</code> is |
201 |
* called when initializing the processing with the value of |
154 |
* called when initializing the processing with the value of |
202 |
* <code>caseNumber</code> equal to the value returned in the |
155 |
* <code>caseNumber</code> equal to the value returned |
203 |
* first element of <code>state</code> and the value of |
156 |
* as <b>state</b> and the value of |
204 |
* <code>separLocation</code> equal to <code>-1</code>. |
157 |
* <code>separLocation</code> equal to <code>-1</code>. |
205 |
* |
158 |
* |
206 |
* @return the position after the scope of the special case ends. |
159 |
* @return the position after the scope of the special case ends. |
207 |
* For instance, the position after the end of a comment, |
160 |
* For instance, the position after the end of a comment, |
208 |
* the position after the end of a literal. |
161 |
* the position after the end of a literal. |
209 |
* <br>A value greater or equal to the length of <code>text</code> |
162 |
* <br>A value greater or equal to the length of <code>text</code> |
210 |
* means that there is no further occurrence of this case in the |
163 |
* means that there is no further occurrence of this case in the |
211 |
* current structured text. |
164 |
* current structured text. |
212 |
* |
165 |
* |
213 |
* @throws IllegalStateException If not overridden, this method throws an |
166 |
* @throws IllegalStateException If not overridden, this method throws an |
214 |
* <code>IllegalStateException</code>. This is appropriate behavior |
167 |
* <code>IllegalStateException</code>. This is appropriate behavior |
215 |
* (and does not need to be overridden) for processors whose |
168 |
* (and does not need to be overridden) for processors whose |
216 |
* number of special cases is zero, which means that |
169 |
* number of special cases is zero, which means that |
217 |
* <code>processSpecial</code> should never be called for them. |
170 |
* <code>processSpecial</code> should never be called for them. |
218 |
*/ |
171 |
*/ |
219 |
public int processSpecial(STextEnvironment environment, String text, STextCharTypes dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) { |
172 |
public int processSpecial(STextProcessorData procData, int caseNumber, int separLocation) { |
220 |
// This method must be overridden by all subclasses with any special case. |
173 |
// This method must be overridden by all subclasses with any special case. |
221 |
throw new IllegalStateException("A processor with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$ |
174 |
throw new IllegalStateException("A processor with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$ |
222 |
} |
175 |
} |
223 |
|
176 |
|
224 |
/** |
177 |
/** |
225 |
* This method can be called from within {@link #indexOfSpecial} or |
178 |
* This method can be called from within {@link #indexOfSpecial} or |
226 |
* {@link #processSpecial} in extensions of <code>STextProcessor</code> |
179 |
* {@link #processSpecial} in extensions of <code>STextProcessor</code> |
227 |
* to specify that a mark character must be added before the character |
180 |
* to specify that a mark character must be added before the character |
228 |
* at the specified position of the <i>lean</i> text when generating the |
181 |
* at the specified position of the <i>lean</i> text when generating the |
229 |
* <i>full</i> text. The mark character will be LRM for structured text |
182 |
* <i>full</i> text. The mark character will be LRM for structured text |
230 |
* with a LTR base direction, and RLM for structured text with RTL |
183 |
* with a LTR base direction, and RLM for structured text with RTL |
231 |
* base direction. The mark character is not added physically by this |
184 |
* base direction. The mark character is not added physically by this |
232 |
* method, but its position is noted and will be used when generating |
185 |
* method, but its position is noted and will be used when generating |
233 |
* the <i>full</i> text. |
186 |
* the <i>full</i> text. |
234 |
* |
187 |
* |
235 |
* @param text is the structured text string received as |
188 |
* @param procData is a group of data accessible to the processor. |
236 |
* parameter to <code>indexOfSpecial</code> or |
|
|
237 |
* <code>processSpecial</code>. |
238 |
* |
189 |
* |
239 |
* @param dirProps is a parameter received by <code>indexOfSpecial</code> |
190 |
* @param offset position of the character in the <i>lean</i> text. |
240 |
* or <code>processSpecial</code>, uniquely to be used as argument |
191 |
* It must be a non-negative number smaller than the length |
241 |
* for calls to <code>insertMark</code> and other methods used |
192 |
* of the <i>lean</i> text. |
242 |
* by processors. |
193 |
* For the benefit of efficiency, it is better to insert |
243 |
* |
194 |
* multiple marks in ascending order of the offsets. |
244 |
* @param offsets is a parameter received by <code>indexOfSpecial</code> |
|
|
245 |
* or <code>processSpecial</code>, uniquely to be used as argument |
246 |
* for calls to <code>insertMark</code> and other methods used |
247 |
* by processors. |
248 |
* |
249 |
* @param offset position of the character in the <i>lean</i> text. |
250 |
* It must be a non-negative number smaller than the length |
251 |
* of the <i>lean</i> text. |
252 |
* For the benefit of efficiency, it is better to insert |
253 |
* multiple marks in ascending order of the offsets. |
254 |
*/ |
195 |
*/ |
255 |
public static final void insertMark(String text, STextCharTypes dirProps, int[] offsets, int offset) { |
196 |
public static final void insertMark(STextProcessorData procData, int offset) { |
256 |
STextImpl.insertMark(text, dirProps, offsets, offset); |
197 |
procData.offsets.insertOffset(procData, offset); |
257 |
} |
198 |
} |
258 |
|
199 |
|
259 |
/** |
200 |
/** |
260 |
* This method can be called from within {@link #indexOfSpecial} or |
201 |
* This method can be called from within {@link #indexOfSpecial} or |
261 |
* {@link #processSpecial} in extensions of <code>STextProcessor</code> to add |
202 |
* {@link #processSpecial} in extensions of <code>STextProcessor</code> to add |
262 |
* a directional mark before a separator if needed for correct display, |
203 |
* a directional mark before a separator if needed for correct display, |
263 |
* depending on the base direction of the text and on the class of the |
204 |
* depending on the base direction of the text and on the type of the |
264 |
* characters in the <i>lean</i> text preceding and following the separator itself. |
205 |
* characters in the <i>lean</i> text preceding and following the separator itself. |
265 |
* <p> |
206 |
* <p> |
266 |
* The logic implemented in this method considers the text before |
207 |
* The logic implemented in this method considers the text before |
267 |
* <code>separLocation</code> and the text following it. If, and only if, |
208 |
* <code>separLocation</code> and the text following it. If, and only if, |
268 |
* a directional mark is needed to insure that the two parts of text |
209 |
* a directional mark is needed to insure that the two parts of text |
269 |
* will be laid out according to the base direction, a mark will be |
210 |
* will be laid out according to the base direction, a mark will be |
270 |
* added when generating the <i>full</i> text. |
211 |
* added when generating the <i>full</i> text. |
271 |
* </p> |
212 |
* </p> |
272 |
* @param text is the structured text string received as |
213 |
* @param procData is a group of data accessible to the processor. |
273 |
* parameter to <code>indexOfSpecial</code> or |
|
|
274 |
* <code>processSpecial</code>. |
275 |
* |
276 |
* @param dirProps is a parameter received by <code>indexOfSpecial</code> |
277 |
* or <code>processSpecial</code>, uniquely to be used as argument |
278 |
* for calls to <code>processSeparator</code> and other methods used |
279 |
* by processors. |
280 |
* |
281 |
* @param offsets is a parameter received by <code>indexOfSpecial</code> |
282 |
* or <code>processSpecial</code>, uniquely to be used as argument |
283 |
* for calls to <code>processSeparator</code> and other methods used |
284 |
* by processors. |
285 |
* |
214 |
* |
286 |
* @param separLocation offset of the separator in the <i>lean</i> text. |
215 |
* @param separLocation offset of the separator in the <i>lean</i> text. |
287 |
* It must be a non-negative number smaller than the length |
216 |
* It must be a non-negative number smaller than the length |
288 |
* of the <i>lean</i> text. |
217 |
* of the <i>lean</i> text. |
289 |
*/ |
218 |
*/ |
290 |
public static final void processSeparator(String text, STextCharTypes dirProps, int[] offsets, int separLocation) { |
219 |
public static final void processSeparator(STextProcessorData procData, int separLocation) { |
291 |
STextImpl.processSeparator(text, dirProps, offsets, separLocation); |
220 |
STextImpl.processSeparator(procData, separLocation); |
292 |
} |
221 |
} |
293 |
|
222 |
|
294 |
/** |
223 |
/** |
295 |
* Indicate the separators to use for the current processor. |
224 |
* Indicate the separators to use for the current processor. |
296 |
* This method is invoked before starting the processing. |
225 |
* This method is invoked before starting the processing. |
297 |
* <p> |
226 |
* <p> |
298 |
* If no separators are specified, this method returns an empty string. |
227 |
* If no separators are specified, this method returns an empty string. |
299 |
* </p> |
228 |
* </p> |
300 |
* @param environment the current environment, which may affect the behavior of |
229 |
* @param environment the current environment, which may affect the behavior of |
301 |
* the processor. This parameter may be specified as |
230 |
* the processor. This parameter may be specified as |
302 |
* <code>null</code>, in which case the |
231 |
* <code>null</code>, in which case the |
303 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
232 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
304 |
* environment should be assumed. |
233 |
* environment should be assumed. |
305 |
* |
234 |
* |
306 |
* @return a string grouping one-character separators which separate |
235 |
* @return a string grouping one-character separators which separate |
307 |
* the structured text into tokens. |
236 |
* the structured text into tokens. |
308 |
*/ |
237 |
*/ |
309 |
public String getSeparators(STextEnvironment environment) { |
238 |
public String getSeparators(STextEnvironment environment) { |
310 |
return separators; |
239 |
return separators; |
311 |
} |
240 |
} |
312 |
|
241 |
|
313 |
/** |
242 |
/** |
314 |
* Indicate the base text direction appropriate for an instance of structured text. |
243 |
* Indicate the base text direction appropriate for an instance of structured text. |
315 |
* This method is invoked before starting the processing. |
244 |
* This method is invoked before starting the processing. |
316 |
* <p> |
245 |
* <p> |
317 |
* If not overridden, this method returns <code>DIR_LTR</code>. |
246 |
* If not overridden, this method returns <code>DIR_LTR</code>. |
318 |
* </p> |
247 |
* </p> |
319 |
* @param environment the current environment, which may affect the behavior of |
248 |
* @param environment the current environment, which may affect the behavior of |
320 |
* the processor. This parameter may be specified as |
249 |
* the processor. This parameter may be specified as |
321 |
* <code>null</code>, in which case the |
250 |
* <code>null</code>, in which case the |
322 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
251 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
323 |
* environment should be assumed. |
252 |
* environment should be assumed. |
324 |
* |
253 |
* |
325 |
* @param text is the structured text string to process. |
254 |
* @param text is the structured text string to process. |
326 |
* |
255 |
* |
327 |
* @return the base direction of the structured text. This direction |
256 |
* @return the base direction of the structured text. This direction |
328 |
* may not be the same depending on the environment and on |
257 |
* may not be the same depending on the environment and on |
329 |
* whether the structured text contains Arabic or Hebrew |
258 |
* whether the structured text contains Arabic or Hebrew |
330 |
* letters.<br> |
259 |
* letters.<br> |
331 |
* The value returned is either |
260 |
* The value returned is either |
332 |
* {@link STextEngine#DIR_LTR DIR_LTR} or {@link STextEngine#DIR_RTL DIR_RTL}. |
261 |
* {@link STextHandler#DIR_LTR DIR_LTR} or {@link STextHandler#DIR_RTL DIR_RTL}. |
333 |
*/ |
262 |
*/ |
334 |
public int getDirection(STextEnvironment environment, String text) { |
263 |
public int getDirection(STextEnvironment environment, String text) { |
335 |
return STextEngine.DIR_LTR; |
264 |
return STextHandler.DIR_LTR; |
336 |
} |
265 |
} |
337 |
|
266 |
|
338 |
/** |
267 |
/** |
339 |
* Indicate the base text direction appropriate for an instance of structured text. |
268 |
* Indicate the base text direction appropriate for an instance of structured text. |
340 |
* This method is invoked before starting the processing. |
269 |
* This method is invoked before starting the processing. |
341 |
* <p> |
270 |
* <p> |
342 |
* If not overridden, this method returns <code>DIR_LTR</code>. |
271 |
* If not overridden, this method returns <code>DIR_LTR</code>. |
343 |
* </p> |
272 |
* </p> |
344 |
* @param environment the current environment, which may affect the behavior of |
273 |
* @param environment the current environment, which may affect the behavior of |
345 |
* the processor. This parameter may be specified as |
274 |
* the processor. This parameter may be specified as |
346 |
* <code>null</code>, in which case the |
275 |
* <code>null</code>, in which case the |
347 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
276 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
348 |
* environment should be assumed. |
277 |
* environment should be assumed. |
349 |
* |
278 |
* |
350 |
* @param text is the structured text string to process. |
279 |
* @param text is the structured text string to process. |
351 |
* |
280 |
* |
352 |
* @param dirProps is a parameter received uniquely to be used as argument |
281 |
* @param dirProps is a parameter received uniquely to be used as argument |
353 |
* for calls to <code>getDirProp</code> and other methods used |
282 |
* for calls to {@link STextCharTypes#getBidiTypeAt} |
354 |
* by processors. |
283 |
* and other methods used by processors. |
355 |
* |
284 |
* |
356 |
* @return the base direction of the structured text. This direction |
285 |
* @return the base direction of the structured text. This direction |
357 |
* may not be the same depending on the environment and on |
286 |
* may not be the same depending on the environment and on |
358 |
* whether the structured text contains Arabic or Hebrew |
287 |
* whether the structured text contains Arabic or Hebrew |
359 |
* letters.<br> |
288 |
* letters.<br> |
360 |
* The value returned is either |
289 |
* The value returned is either |
361 |
* {@link STextEngine#DIR_LTR DIR_LTR} or {@link STextEngine#DIR_RTL DIR_RTL}. |
290 |
* {@link STextHandler#DIR_LTR DIR_LTR} or {@link STextHandler#DIR_RTL DIR_RTL}. |
362 |
*/ |
291 |
*/ |
363 |
public int getDirection(STextEnvironment environment, String text, STextCharTypes dirProps) { |
292 |
public int getDirection(STextEnvironment environment, String text, STextCharTypes dirProps) { |
364 |
return STextEngine.DIR_LTR; |
293 |
return STextHandler.DIR_LTR; |
365 |
} |
294 |
} |
366 |
|
295 |
|
367 |
/** |
296 |
/** |
368 |
* Indicate the number of special cases handled by the current processor. |
297 |
* Indicate the number of special cases handled by the current processor. |
369 |
* This method is invoked before starting the processing. |
298 |
* This method is invoked before starting the processing. |
370 |
* If the number returned is zero, {@link #indexOfSpecial} and |
299 |
* If the number returned is zero, {@link #indexOfSpecial} and |
371 |
* {@link #processSpecial} will not be invoked. |
300 |
* {@link #processSpecial} will not be invoked. |
372 |
* <p> |
301 |
* <p> |
373 |
* If not overridden, this method returns <code>zero</code>. |
302 |
* If not overridden, this method returns <code>zero</code>. |
374 |
* </p> |
303 |
* </p> |
375 |
* @param environment the current environment, which may affect the behavior of |
304 |
* @param environment the current environment, which may affect the behavior of |
376 |
* the processor. This parameter may be specified as |
305 |
* the processor. This parameter may be specified as |
377 |
* <code>null</code>, in which case the |
306 |
* <code>null</code>, in which case the |
378 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
307 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
379 |
* environment should be assumed. |
308 |
* environment should be assumed. |
380 |
* |
309 |
* |
381 |
* @return the number of special cases for the associated processor. |
310 |
* @return the number of special cases for the associated processor. |
382 |
* Special cases exist for some types of structured text |
311 |
* Special cases exist for some types of structured text |
383 |
* processors. They are implemented by overriding methods |
312 |
* processors. They are implemented by overriding methods |
384 |
* {@link STextProcessor#indexOfSpecial} and {@link STextProcessor#processSpecial}. |
313 |
* {@link STextProcessor#indexOfSpecial} and {@link STextProcessor#processSpecial}. |
385 |
* Examples of special cases are comments, literals, or |
314 |
* Examples of special cases are comments, literals, or |
386 |
* anything which is not identified by a one-character separator. |
315 |
* anything which is not identified by a one-character separator. |
387 |
* |
316 |
* |
388 |
*/ |
317 |
*/ |
389 |
public int getSpecialsCount(STextEnvironment environment) { |
318 |
public int getSpecialsCount(STextEnvironment environment) { |
Lines 391-422
Link Here
|
391 |
} |
320 |
} |
392 |
|
321 |
|
393 |
/** |
322 |
/** |
394 |
* Checks if there is a need for processing structured text. |
323 |
* Checks if there is a need for processing structured text. |
395 |
* This method is invoked before starting the processing. If the |
324 |
* This method is invoked before starting the processing. If the |
396 |
* processor returns <code>true</code>, no directional formatting |
325 |
* processor returns <code>true</code>, no directional formatting |
397 |
* characters are added to the <i>lean</i> text and the processing |
326 |
* characters are added to the <i>lean</i> text and the processing |
398 |
* is shortened. |
327 |
* is shortened. |
399 |
* <p> |
328 |
* <p> |
400 |
* If not overridden, this method returns <code>false</code>. |
329 |
* If not overridden, this method returns <code>false</code>. |
401 |
* </p> |
330 |
* </p> |
402 |
* @param environment the current environment, which may affect the behavior of |
331 |
|
403 |
* the processor. This parameter may be specified as |
332 |
* @return a flag indicating if there is no need to process the structured |
404 |
* <code>null</code>, in which case the |
333 |
* text to add directional formatting characters. |
405 |
* {@link STextEnvironment#DEFAULT DEFAULT} |
|
|
406 |
* environment should be assumed. |
407 |
* |
408 |
* @param text is the structured text string to process. |
409 |
* |
410 |
* @param dirProps is a parameter received uniquely to be used as argument |
411 |
* for calls to <code>getDirProp</code> and other methods used |
412 |
* by processors. |
413 |
* |
414 |
* @return a flag indicating if there is no need to process the structured |
415 |
* text to add directional formatting characters. |
416 |
* |
334 |
* |
417 |
*/ |
335 |
*/ |
418 |
public boolean skipProcessing(STextEnvironment environment, String text, STextCharTypes dirProps) { |
336 |
public boolean skipProcessing(STextProcessorData procData) { |
419 |
return false; |
337 |
return false; |
420 |
} |
338 |
} |
421 |
|
|
|
422 |
} |
339 |
} |