Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
465   1,193   197   3.97
138   977   0.42   58.5
117     1.68  
2    
 
  InternalWikiScannerContext       Line # 37 465 0% 197 63 91.3% 0.9125
  InternalWikiScannerContext.IBlockTypes       Line # 39 0 - 0 0 - -1.0
 
  (967)
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.wikimodel.impl;
21   
22    import java.util.Stack;
23   
24    import org.xwiki.rendering.wikimodel.IWemListener;
25    import org.xwiki.rendering.wikimodel.WikiFormat;
26    import org.xwiki.rendering.wikimodel.WikiParameters;
27    import org.xwiki.rendering.wikimodel.WikiReference;
28    import org.xwiki.rendering.wikimodel.WikiStyle;
29    import org.xwiki.rendering.wikimodel.util.IListListener;
30    import org.xwiki.rendering.wikimodel.util.ListBuilder;
31    import org.xwiki.rendering.wikimodel.util.SectionBuilder;
32   
33    /**
34    * @version $Id: 2153a46de9147f09a5955f5e6e532b142b65fab4 $
35    * @since 4.0M1
36    */
 
37    public class InternalWikiScannerContext implements IWikiScannerContext
38    {
 
39    protected interface IBlockTypes
40    {
41    int HEADER = 1 << 1;
42    int INFO = 1 << 2;
43    int LIST = 1 << 3;
44    int LIST_DL = (1 << 4) | LIST;
45    int LIST_DL_DD = (1 << 5) | LIST_DL;
46    int LIST_DL_DT = (1 << 6) | LIST_DL;
47    int LIST_LI = (1 << 7) | LIST;
48    int NONE = 0;
49    int PARAGRAPH = 1 << 8;
50    int QUOT = 1 << 9;
51    int QUOT_LI = (1 << 10) | QUOT;
52    int TABLE = 1 << 11;
53    int TABLE_ROW = (1 << 12) | TABLE;
54    int TABLE_ROW_CELL = (1 << 13) | TABLE_ROW;
55    }
56   
57    protected int fBlockType = IBlockTypes.NONE;
58   
59    private int fPreBlockType = IBlockTypes.NONE;
60   
61    protected WikiFormat fFormat;
62   
63    protected int fHeaderLevel;
64   
65    protected WikiParameters fInfoParams;
66   
67    protected String fInfoType;
68   
69    protected String fInlineProperty;
70   
71    protected InlineState fInlineState = new InlineState();
72   
73    protected ListBuilder fListBuilder;
74   
75    protected final IWemListener fListener;
76   
77    protected WikiParameters fListParams;
78   
79    protected String fMacroContent = null;
80   
81    protected String fMacroName = null;
82   
83    protected WikiParameters fMacroParameters = WikiParameters.EMPTY;
84   
85    protected WikiFormat fNewFormat = WikiFormat.EMPTY;
86   
87    protected WikiParameters fParagraphParams;
88   
89    protected Stack<Boolean> fPropertyDocStack = new Stack<Boolean>();
90   
91    protected Stack<String> fPropertyStack = new Stack<String>();
92   
93    protected ListBuilder fQuotBuilder;
94   
95    protected int fQuoteDepth = 0;
96   
97    protected WikiParameters fQuotParams;
98   
99    protected SectionBuilder<WikiParameters> fSectionBuilder;
100   
101    protected int fTableCellCounter = -1;
102   
103    protected WikiParameters fTableCellParams = WikiParameters.EMPTY;
104   
105    protected boolean fTableHead;
106   
107    protected WikiParameters fTableParams;
108   
109    protected int fTableRowCounter = -1;
110   
111    protected WikiParameters fTableRowParams;
112   
113    protected String fVerbatimContent = null;
114   
115    protected WikiParameters fVerbatimParameters = WikiParameters.EMPTY;
116   
 
117  5412 toggle public InternalWikiScannerContext(
118    SectionBuilder<WikiParameters> sectionBuilder,
119    IWemListener listener)
120    {
121  5412 fListener = listener;
122  5412 fSectionBuilder = sectionBuilder;
123    }
124   
 
125  2660 toggle public void beginDocument()
126    {
127  2660 beginDocument(WikiParameters.EMPTY);
128    }
129   
 
130  2796 toggle public void beginDocument(WikiParameters params)
131    {
132  2796 fSectionBuilder.beginDocument(params);
133  2796 fInlineState.set(InlineState.BEGIN_FORMAT);
134    }
135   
 
136  78 toggle public void beginFormat(WikiParameters params)
137    {
138  78 closeFormat(false);
139  78 fNewFormat = fNewFormat.setParameters(params.toList());
140  78 fInlineState.set(InlineState.BEGIN_FORMAT);
141    }
142   
 
143  88 toggle public void beginFormat(WikiStyle wikiStyle)
144    {
145  88 closeFormat(false);
146  88 fNewFormat = fNewFormat.addStyle(wikiStyle);
147  88 fInlineState.set(InlineState.BEGIN_FORMAT);
148    }
149   
 
150  54 toggle public void beginHeader(int level)
151    {
152  54 beginHeader(level, WikiParameters.EMPTY);
153    }
154   
 
155  380 toggle public void beginHeader(int level, WikiParameters params)
156    {
157  380 if (level < 1) {
158  0 level = 1;
159  380 } else if (level > 6) {
160  3 level = 6;
161    }
162  380 if (fBlockType != IBlockTypes.HEADER) {
163  380 closeBlock();
164  380 fBlockType = IBlockTypes.HEADER;
165  380 fHeaderLevel = level;
166  380 fSectionBuilder.beginHeader(fHeaderLevel, params);
167    }
168  380 beginStyleContainer();
169    }
170   
 
171  7 toggle public void beginInfo(String type, WikiParameters params)
172    {
173  7 if ((fBlockType & IBlockTypes.INFO) != IBlockTypes.INFO) {
174  7 closeBlock();
175  7 fInfoType = type;
176  7 fInfoParams = params != null ? params : WikiParameters.EMPTY;
177  7 fListener.beginInfoBlock(fInfoType, fInfoParams);
178  7 fBlockType = IBlockTypes.INFO;
179    }
180  7 beginStyleContainer();
181    }
182   
 
183  972 toggle public void beginList()
184    {
185  972 if ((fBlockType & IBlockTypes.LIST) != IBlockTypes.LIST) {
186  287 closeBlock();
187  287 if (fListParams == null) {
188  46 fListParams = WikiParameters.EMPTY;
189    }
190  287 IListListener listener = new IListListener()
191    {
192    private Stack<WikiParameters> fListParamsStack = new Stack<WikiParameters>();
193   
 
194  696 toggle public void beginRow(char treeType, char rowType)
195    {
196  696 if (rowType == ':') {
197  114 fBlockType = IBlockTypes.LIST_DL_DD;
198  114 fListener.beginDefinitionDescription();
199  582 } else if (rowType == ';') {
200  110 fBlockType = IBlockTypes.LIST_DL_DT;
201  110 fListener.beginDefinitionTerm();
202    } else {
203  472 fBlockType = IBlockTypes.LIST_LI;
204  472 fListener.beginListItem();
205    }
206  696 beginStyleContainer();
207    }
208   
 
209  477 toggle public void beginTree(char type)
210    {
211  477 fListParamsStack.push(fListParams);
212   
213  477 closeFormat();
214  477 switch (type) {
215  59 case '#':
216  59 fListener.beginList(fListParams, true);
217  59 fBlockType = IBlockTypes.LIST;
218  59 break;
219  138 case 'd':
220  138 fListener.beginDefinitionList(fListParams);
221  138 fBlockType = IBlockTypes.LIST_DL;
222  138 break;
223  280 default:
224  280 fListener.beginList(fListParams, false);
225  280 fBlockType = IBlockTypes.LIST;
226  280 break;
227    }
228   
229  477 fListParams = WikiParameters.EMPTY;
230    }
231   
 
232  696 toggle public void endRow(char treeType, char rowType)
233    {
234  696 closeFormat();
235  696 endStyleContainer();
236  696 if (rowType == ':') {
237  114 fListener.endDefinitionDescription();
238  114 fBlockType = IBlockTypes.LIST_DL;
239  582 } else if (rowType == ';') {
240  110 if ((fBlockType & IBlockTypes.LIST_DL_DT) == IBlockTypes.LIST_DL_DT) {
241  89 fListener.endDefinitionTerm();
242    } else {
243  21 fListener.endDefinitionDescription();
244    }
245  110 fBlockType = IBlockTypes.LIST_DL;
246    } else {
247  472 fListener.endListItem();
248  472 fBlockType = IBlockTypes.LIST;
249    }
250    }
251   
 
252  477 toggle public void endTree(char type)
253    {
254  477 switch (type) {
255  59 case '#':
256  59 fListener.endList(fListParamsStack.peek(), true);
257  59 fBlockType = IBlockTypes.LIST;
258  59 break;
259  138 case 'd':
260  138 fListener
261    .endDefinitionList(fListParamsStack.peek());
262  138 fBlockType = IBlockTypes.LIST;
263  138 break;
264  280 default:
265  280 fListener.endList(fListParamsStack.peek(), false);
266  280 fBlockType = IBlockTypes.LIST;
267  280 break;
268    }
269   
270  477 fListParamsStack.pop();
271    }
272    };
273  287 fListBuilder = new ListBuilder(listener)
274    {
 
275  926 toggle @Override
276    protected char getTreeType(char rowType)
277    {
278  926 if (rowType == ';' || rowType == ':') {
279  254 return 'd';
280    }
281  672 return rowType;
282    }
283    };
284  287 fBlockType = IBlockTypes.LIST;
285    }
286    }
287   
 
288  265 toggle public void beginList(WikiParameters params)
289    {
290  265 fListParams = params;
291  265 beginList();
292    }
293   
 
294  282 toggle public void beginListItem(String item)
295    {
296  282 beginListItem(item, WikiParameters.EMPTY);
297    }
298   
 
299  692 toggle public void beginListItem(String item, WikiParameters params)
300    {
301  692 beginList();
302   
303  692 if (fListParams == WikiParameters.EMPTY) {
304  573 fListParams = params;
305    }
306   
307  692 item = trimLineBreaks(item);
308  692 item = replace(item, ";:", ":");
309    // Definitions can not have subitems...
310  692 int idx = item.indexOf(';');
311  692 if (idx >= 0) {
312  110 item = item.substring(0, idx + 1);
313    }
314  692 fListBuilder.alignContext(item);
315    }
316   
 
317  2141 toggle public void beginParagraph()
318    {
319  2141 if (fBlockType != IBlockTypes.PARAGRAPH) {
320  2141 closeBlock();
321  2141 if (fParagraphParams == null) {
322  651 fParagraphParams = WikiParameters.EMPTY;
323    }
324  2141 fListener.beginParagraph(fParagraphParams);
325  2141 fBlockType = IBlockTypes.PARAGRAPH;
326  2141 beginStyleContainer();
327    }
328    }
329   
 
330  1339 toggle public void beginParagraph(WikiParameters params)
331    {
332  1339 fParagraphParams = params;
333  1339 beginParagraph();
334    }
335   
 
336  39 toggle public void beginPropertyBlock(String property, boolean doc)
337    {
338  39 closeBlock();
339  39 fPropertyStack.push(property);
340  39 fPropertyDocStack.push(doc);
341  39 fListener.beginPropertyBlock(property, doc);
342    }
343   
 
344  4 toggle public void beginPropertyInline(String str)
345    {
346  4 closeFormat();
347  4 beginStyleContainer();
348  4 fInlineProperty = str;
349  4 fListener.beginPropertyInline(fInlineProperty);
350    }
351   
 
352  209 toggle public void beginQuot()
353    {
354  209 if ((fBlockType & IBlockTypes.QUOT) != IBlockTypes.QUOT) {
355  74 closeBlock();
356  74 if (fQuotParams == null) {
357  21 fQuotParams = WikiParameters.EMPTY;
358    }
359  74 IListListener listener = new IListListener()
360    {
 
361  135 toggle public void beginRow(char treeType, char rowType)
362    {
363  135 fBlockType = IBlockTypes.QUOT_LI;
364  135 fListener.beginQuotationLine();
365  135 beginStyleContainer();
366    }
367   
 
368  93 toggle public void beginTree(char type)
369    {
370  93 closeFormat();
371  93 fListener.beginQuotation(fQuotParams);
372  93 fBlockType = IBlockTypes.QUOT;
373    }
374   
 
375  135 toggle public void endRow(char treeType, char rowType)
376    {
377  135 closeFormat();
378  135 endStyleContainer();
379  135 fListener.endQuotationLine();
380  135 fBlockType = IBlockTypes.QUOT;
381    }
382   
 
383  93 toggle public void endTree(char type)
384    {
385  93 closeFormat();
386  93 fListener.endQuotation(fQuotParams);
387  93 fBlockType = IBlockTypes.QUOT;
388    }
389    };
390  74 fQuotBuilder = new ListBuilder(listener);
391  74 fBlockType = IBlockTypes.QUOT;
392    }
393    }
394   
 
395  48 toggle public void beginQuot(WikiParameters params)
396    {
397  48 fQuotParams = params;
398  48 beginQuot();
399    }
400   
401    /**
402    * @see IWikiScannerContext#beginQuotLine(int)
403    */
 
404  135 toggle public void beginQuotLine(int depth)
405    {
406  135 beginQuot();
407  135 StringBuffer buf = new StringBuffer();
408  326 for (int i = 0; i < depth; i++) {
409  191 buf.append(" ");
410    }
411  135 buf.append("*");
412  135 fQuoteDepth = depth;
413  135 fQuotBuilder.alignContext(buf.toString());
414    }
415   
 
416  4032 toggle protected void beginStyleContainer()
417    {
418  4032 fInlineState.set(InlineState.BEGIN);
419    }
420   
 
421  524 toggle public void beginTable()
422    {
423  524 if ((fBlockType & IBlockTypes.TABLE) != IBlockTypes.TABLE) {
424  203 closeBlock();
425  203 if (fTableParams == null) {
426  24 fTableParams = WikiParameters.EMPTY;
427    }
428  203 fTableRowCounter = 0;
429  203 fListener.beginTable(fTableParams);
430  203 fBlockType = IBlockTypes.TABLE;
431    }
432    }
433   
 
434  179 toggle public void beginTable(WikiParameters params)
435    {
436  179 fTableParams = params;
437  179 beginTable();
438    }
439   
 
440  31 toggle public void beginTableCell(boolean headCell)
441    {
442  31 beginTableCell(headCell, fTableCellParams);
443    }
444   
 
445  608 toggle public void beginTableCell(boolean headCell, WikiParameters params)
446    {
447  608 if ((fBlockType & IBlockTypes.TABLE_ROW_CELL) != IBlockTypes.TABLE_ROW_CELL) {
448  608 beginTableRow(null);
449  608 fTableHead = headCell;
450  608 fTableCellParams = params != null ? params : WikiParameters.EMPTY;
451  608 fListener.beginTableCell(fTableHead, fTableCellParams);
452  608 fBlockType = IBlockTypes.TABLE_ROW_CELL;
453  608 beginStyleContainer();
454    }
455    }
456   
 
457  36 toggle public void beginTableRow(boolean headCell)
458    {
459  36 if (beginTableRowInternal((WikiParameters) null)) {
460  36 beginTableCell(headCell, null);
461    }
462    }
463   
 
464  217 toggle public void beginTableRow(
465    boolean head,
466    WikiParameters rowParams,
467    WikiParameters cellParams)
468    {
469  217 if (beginTableRowInternal(rowParams)) {
470  217 beginTableCell(head, cellParams);
471    }
472    }
473   
 
474  668 toggle public void beginTableRow(WikiParameters rowParams)
475    {
476  668 beginTableRowInternal(rowParams);
477    }
478   
 
479  921 toggle private boolean beginTableRowInternal(WikiParameters rowParams)
480    {
481  921 boolean result = false;
482  921 if ((fBlockType & IBlockTypes.TABLE_ROW) != IBlockTypes.TABLE_ROW) {
483  322 beginTable();
484  322 fBlockType = IBlockTypes.TABLE_ROW;
485  322 fTableCellCounter = 0;
486  322 fTableRowParams = rowParams != null
487    ? rowParams
488    : WikiParameters.EMPTY;
489  322 fListener.beginTableRow(fTableRowParams);
490  322 result = true;
491    }
492  921 return result;
493    }
494   
 
495  59 toggle public boolean canApplyDefintionSplitter()
496    {
497  59 return fBlockType == IBlockTypes.LIST_DL_DT;
498    }
499   
 
500  3378 toggle void checkBlockContainer()
501    {
502  3378 if (isInTable()) {
503  54 checkTableCell();
504  3324 } else if (isInList()) {
505  0 checkListItem();
506  3324 } else if (!isInTableCell() && !isInListItem()) {
507  3311 closeBlock();
508  13 } else if (isInQuotation()) {
509  0 checkQuotationLine();
510    }
511    }
512   
 
513  28 toggle public boolean checkFormatStyle(WikiStyle style)
514    {
515  28 return style != null && fFormat != null && fFormat.hasStyle(style);
516    }
517   
 
518  0 toggle private void checkListItem()
519    {
520  0 if (!isInListItem()) {
521  0 beginListItem("*");
522    }
523    }
524   
 
525  24336 toggle private void checkMacro(boolean inline)
526    {
527  24336 if (fMacroName != null) {
528  289 if (!inline) {
529  268 fListener.onMacroBlock(
530    fMacroName,
531    fMacroParameters,
532    fMacroContent);
533    } else {
534  21 fListener.onMacroInline(
535    fMacroName,
536    fMacroParameters,
537    fMacroContent);
538    }
539   
540  289 fMacroName = null;
541  289 fMacroParameters = WikiParameters.EMPTY;
542  289 fMacroContent = null;
543    }
544    }
545   
 
546  149 toggle private void checkParagraph()
547    {
548  149 if (!isInParagraph()) {
549  149 beginParagraph();
550    }
551    }
552   
 
553  2 toggle private void checkQuotationLine()
554    {
555  2 if (!isInQuotationLine()) {
556  2 beginQuotLine(fQuoteDepth);
557    }
558    }
559   
 
560  14904 toggle protected void checkStyleOpened()
561    {
562  14904 if (isInTable()) {
563  2082 checkTableCell();
564  12822 } else if (isInList()) {
565  0 checkListItem();
566  12822 } else if (isInQuotation()) {
567  2 checkQuotationLine();
568  12820 } else if (isNoBlockElements()) {
569  149 String verbatimContent = fVerbatimContent;
570  149 String macroName = fMacroName;
571  149 fVerbatimContent = null;
572  149 fMacroName = null;
573  149 checkParagraph();
574  149 fMacroName = macroName;
575  149 fVerbatimContent = verbatimContent;
576    }
577  14904 openFormat();
578  14904 checkVerbatim(true);
579  14904 checkMacro(true);
580    }
581   
 
582  2204 toggle private void checkTableCell()
583    {
584  2204 if (!isInTableCell()) {
585  16 beginTableCell(fTableHead);
586    }
587    }
588   
 
589  24336 toggle private void checkVerbatim(boolean inline)
590    {
591  24336 if (fVerbatimContent != null) {
592  81 if (!inline) {
593  69 fListener
594    .onVerbatimBlock(fVerbatimContent, fVerbatimParameters);
595    } else {
596  12 fListener.onVerbatimInline(
597    fVerbatimContent,
598    fVerbatimParameters);
599    }
600   
601  81 fVerbatimContent = null;
602  81 fVerbatimParameters = WikiParameters.EMPTY;
603    }
604    }
605   
 
606  9432 toggle public void closeBlock()
607    {
608  9432 checkVerbatim(false);
609  9432 checkMacro(false);
610   
611  9432 switch (fBlockType) {
612  9313 case IBlockTypes.NONE:
613  9313 break;
614  0 case IBlockTypes.HEADER:
615  0 endHeader();
616  0 break;
617  116 case IBlockTypes.PARAGRAPH:
618  116 endParagraph();
619  116 break;
620  1 case IBlockTypes.INFO:
621  1 endInfo();
622  1 break;
623  2 default:
624  2 if ((fBlockType & IBlockTypes.TABLE) != 0) {
625  2 endTable();
626  0 } else if ((fBlockType & IBlockTypes.LIST) != 0) {
627  0 endList();
628  0 } else if ((fBlockType & IBlockTypes.QUOT) != 0) {
629  0 endQuot();
630    }
631  2 break;
632    }
633    }
634   
 
635  12041 toggle public void closeFormat()
636    {
637  12041 closeFormat(true);
638    }
639   
 
640  13127 toggle private void closeFormat(boolean resetNewStyle)
641    {
642  13127 if (fFormat != null) {
643  4419 fListener.endFormat(fFormat);
644  4419 fFormat = null;
645    }
646  13127 if (resetNewStyle) {
647  12041 fNewFormat = WikiFormat.EMPTY;
648    }
649    }
650   
 
651  2796 toggle public void endDocument()
652    {
653  2796 closeBlock();
654  2796 fSectionBuilder.endDocument();
655    }
656   
 
657  63 toggle public void endFormat(WikiParameters params)
658    {
659  63 closeFormat(false);
660  63 fNewFormat = fNewFormat.setParameters(params.toList());
661  63 fInlineState.set(InlineState.BEGIN_FORMAT);
662    }
663   
 
664  87 toggle public void endFormat(WikiStyle wikiStyle)
665    {
666  87 closeFormat(false);
667  87 fNewFormat = fNewFormat.removeStyle(wikiStyle);
668  87 fInlineState.set(InlineState.BEGIN_FORMAT);
669    }
670   
 
671  380 toggle public void endHeader()
672    {
673  380 if ((fBlockType & IBlockTypes.HEADER) != 0) {
674  380 closeFormat();
675  380 endStyleContainer();
676  380 fHeaderLevel = -1;
677  380 fBlockType = IBlockTypes.NONE;
678  380 fSectionBuilder.endHeader();
679    }
680    }
681   
 
682  8 toggle public void endInfo()
683    {
684  8 if ((fBlockType & IBlockTypes.INFO) != 0) {
685  7 closeFormat();
686  7 endStyleContainer();
687  7 fListener.endInfoBlock(fInfoType, fInfoParams);
688  7 fInfoType = "";
689  7 fInfoParams = null;
690  7 fBlockType = IBlockTypes.NONE;
691    }
692    }
693   
 
694  287 toggle public void endList()
695    {
696  287 if ((fBlockType & IBlockTypes.LIST) != 0) {
697  287 fListBuilder.alignContext("");
698  287 fListBuilder = null;
699  287 fBlockType = IBlockTypes.NONE;
700    }
701    }
702   
 
703  578 toggle public void endListItem()
704    {
705    }
706   
 
707  2646 toggle public void endParagraph()
708    {
709  2646 if ((fBlockType & IBlockTypes.PARAGRAPH) != 0) {
710  2141 closeFormat();
711  2141 endStyleContainer();
712  2141 fListener.endParagraph(fParagraphParams);
713  2141 fBlockType = IBlockTypes.NONE;
714  2141 fParagraphParams = WikiParameters.EMPTY;
715    }
716    }
717   
 
718  39 toggle public void endPropertyBlock()
719    {
720  39 closeBlock();
721  39 String property = fPropertyStack.pop();
722  39 boolean doc = fPropertyDocStack.pop();
723  39 fListener.endPropertyBlock(property, doc);
724    }
725   
 
726  4 toggle public void endPropertyInline()
727    {
728  4 closeFormat();
729  4 endStyleContainer();
730  4 fListener.endPropertyInline(fInlineProperty);
731  4 fInlineProperty = null;
732    }
733   
 
734  74 toggle public void endQuot()
735    {
736  74 if ((fBlockType & IBlockTypes.QUOT) != 0) {
737  74 closeFormat();
738  74 if (fQuotBuilder != null) {
739  74 fQuotBuilder.alignContext("");
740    }
741  74 fQuotBuilder = null;
742  74 fBlockType = IBlockTypes.NONE;
743    }
744    }
745   
 
746  126 toggle public void endQuotLine()
747    {
748  126 fQuoteDepth--;
749  126 if (fQuoteDepth < 0) {
750  10 fQuoteDepth = 0;
751    }
752  126 fBlockType = IBlockTypes.QUOT;
753    }
754   
 
755  4032 toggle protected void endStyleContainer()
756    {
757  4032 fInlineState.set(InlineState.BEGIN);
758    }
759   
 
760  203 toggle public void endTable()
761    {
762  203 if ((fBlockType & IBlockTypes.TABLE) == IBlockTypes.TABLE) {
763  203 endTableRow();
764  203 fListener.endTable(fTableParams);
765  203 fTableRowCounter = -1;
766  203 fBlockType = IBlockTypes.NONE;
767    }
768    }
769   
 
770  667 toggle public void endTableCell()
771    {
772  667 if ((fBlockType & IBlockTypes.TABLE_ROW_CELL) == IBlockTypes.TABLE_ROW_CELL) {
773  608 closeFormat();
774  608 endStyleContainer();
775  608 fListener.endTableCell(fTableHead, fTableCellParams);
776  608 fTableCellCounter++;
777  608 fBlockType = IBlockTypes.TABLE_ROW;
778  608 fTableCellParams = WikiParameters.EMPTY;
779    }
780    }
781   
 
782  0 toggle public void endTableExplicit()
783    {
784  0 endTable();
785    }
786   
 
787  516 toggle public void endTableRow()
788    {
789  516 if ((fBlockType & IBlockTypes.TABLE_ROW) == IBlockTypes.TABLE_ROW) {
790  322 if (fTableCellCounter <= 0) {
791  68 checkTableCell();
792    }
793  322 endTableCell();
794  322 fListener.endTableRow(fTableRowParams);
795  322 fBlockType = IBlockTypes.TABLE;
796  322 fTableHead = false;
797  322 fTableCellCounter = -1;
798  322 fTableRowCounter++;
799    }
800    }
801   
 
802  28 toggle public InlineState getInlineState()
803    {
804  28 return fInlineState;
805    }
806   
807    /**
808    * Returns the tableCellCounter.
809    *
810    * @return the tableCellCounter.
811    */
 
812  4 toggle public int getTableCellCounter()
813    {
814  4 return fTableCellCounter;
815    }
816   
817    /**
818    * Returns the tableRowCounter.
819    *
820    * @return the tableRowCounter.
821    */
 
822  21 toggle public int getTableRowCounter()
823    {
824  21 return fTableRowCounter;
825    }
826   
827    /**
828    * Returns the inDefinitionList.
829    *
830    * @return the inDefinitionList.
831    */
 
832  0 toggle public boolean isInDefinitionList()
833    {
834  0 return (fBlockType & IBlockTypes.LIST_DL) == IBlockTypes.LIST_DL;
835    }
836   
 
837  0 toggle public boolean isInDefinitionTerm()
838    {
839  0 return fBlockType == IBlockTypes.LIST_DL_DT;
840    }
841   
842    /**
843    * Returns the inHeader.
844    *
845    * @return the inHeader.
846    */
 
847  60 toggle public boolean isInHeader()
848    {
849  60 return fHeaderLevel > 0;
850    }
851   
 
852  6 toggle public boolean isInInlineProperty()
853    {
854  6 return fInlineProperty != null;
855    }
856   
857    /**
858    * Returns the inList.
859    *
860    * @return the inList.
861    */
 
862  16146 toggle public boolean isInList()
863    {
864  16146 return fBlockType == IBlockTypes.LIST;
865    }
866   
 
867  3324 toggle private boolean isInListItem()
868    {
869  3324 return (fBlockType & IBlockTypes.LIST_LI) == IBlockTypes.LIST_LI;
870    }
871   
 
872  149 toggle private boolean isInParagraph()
873    {
874  149 return fBlockType == IBlockTypes.PARAGRAPH;
875    }
876   
 
877  12835 toggle public boolean isInQuotation()
878    {
879  12835 return fBlockType == IBlockTypes.QUOT;
880    }
881   
 
882  2 toggle private boolean isInQuotationLine()
883    {
884  2 return (fBlockType & IBlockTypes.QUOT_LI) == IBlockTypes.QUOT_LI;
885    }
886   
 
887  18438 toggle public boolean isInTable()
888    {
889  18438 return ((fBlockType & IBlockTypes.TABLE) == IBlockTypes.TABLE);
890    }
891   
 
892  5528 toggle public boolean isInTableCell()
893    {
894  5528 return (fBlockType & IBlockTypes.TABLE_ROW_CELL) == IBlockTypes.TABLE_ROW_CELL;
895    }
896   
 
897  0 toggle public boolean isInTableRow()
898    {
899  0 return (fBlockType & IBlockTypes.TABLE_ROW) == IBlockTypes.TABLE_ROW;
900    }
901   
 
902  12820 toggle private boolean isNoBlockElements()
903    {
904  12820 return (fBlockType == IBlockTypes.NONE);
905    }
906   
 
907  21 toggle public void onDefinitionListItemSplit()
908    {
909  21 closeFormat();
910  21 if ((fBlockType & IBlockTypes.LIST_DL_DT) == IBlockTypes.LIST_DL_DT) {
911  21 closeFormat();
912  21 endStyleContainer();
913  21 fListener.endDefinitionTerm();
914  0 } else if ((fBlockType & IBlockTypes.LIST_DL_DD) == IBlockTypes.LIST_DL_DD) {
915  0 closeFormat();
916  0 endStyleContainer();
917  0 fListener.endDefinitionDescription();
918    }
919  21 fBlockType = IBlockTypes.LIST_DL_DD;
920  21 fListener.beginDefinitionDescription();
921  21 beginStyleContainer();
922    }
923   
 
924  63 toggle public void onEmptyLines(int count)
925    {
926  63 closeBlock();
927  63 fListener.onEmptyLines(count);
928    }
929   
 
930  28 toggle public void onEscape(String str)
931    {
932  28 checkStyleOpened();
933  28 fListener.onEscape(str);
934  28 fInlineState.set(InlineState.ESCAPE);
935    }
936   
 
937  14 toggle public void onExtensionBlock(String extensionName, WikiParameters params)
938    {
939  14 fListener.onExtensionBlock(extensionName, params);
940    }
941   
 
942  6 toggle public void onExtensionInline(String extensionName, WikiParameters params)
943    {
944  6 fListener.onExtensionInline(extensionName, params);
945  6 fInlineState.set(InlineState.EXTENSION);
946    }
947   
 
948  95 toggle public void onFormat(WikiParameters params)
949    {
950  95 closeFormat(false);
951  95 fNewFormat = fNewFormat.setParameters(params.toList());
952  95 fInlineState.set(InlineState.BEGIN_FORMAT);
953    }
954   
 
955  653 toggle public void onFormat(WikiStyle wikiStyle)
956    {
957  653 onFormat(wikiStyle, false);
958    }
959   
 
960  675 toggle public void onFormat(WikiStyle wikiStyle, boolean forceClose)
961    {
962  675 closeFormat(false);
963  675 if (forceClose) {
964  11 fNewFormat = fNewFormat.removeStyle(wikiStyle);
965    } else {
966  664 fNewFormat = fNewFormat.switchStyle(wikiStyle);
967    }
968  675 fInlineState.set(InlineState.BEGIN_FORMAT);
969    }
970   
 
971  8 toggle public void onHorizontalLine()
972    {
973  8 onHorizontalLine(WikiParameters.EMPTY);
974    }
975   
 
976  80 toggle public void onHorizontalLine(WikiParameters params)
977    {
978  80 closeBlock();
979  80 fListener.onHorizontalLine(params);
980    }
981   
 
982  64 toggle public void onImage(String ref)
983    {
984  64 checkStyleOpened();
985  64 fListener.onImage(ref);
986  64 fInlineState.set(InlineState.IMAGE);
987    }
988   
 
989  68 toggle public void onImage(WikiReference ref)
990    {
991  68 checkStyleOpened();
992  68 fListener.onImage(ref);
993  68 fInlineState.set(InlineState.IMAGE);
994    }
995   
 
996  68 toggle public void onLineBreak()
997    {
998  68 checkStyleOpened();
999  68 fListener.onLineBreak();
1000  68 fInlineState.set(InlineState.LINE_BREAK);
1001    }
1002   
1003    /**
1004    * Waiting for following events to know if the macro is inline or not.
1005    */
 
1006  289 toggle public void onMacro(String name, WikiParameters params, String content)
1007    {
1008  289 checkBlockContainer();
1009   
1010  289 fMacroName = name;
1011  289 fMacroParameters = params;
1012  289 fMacroContent = content;
1013    }
1014   
 
1015  0 toggle public void onMacro(
1016    String macroName,
1017    WikiParameters params,
1018    String content,
1019    boolean inline)
1020    {
1021  0 if (inline) {
1022  0 onMacroInline(macroName, params, content);
1023    } else {
1024  0 onMacroBlock(macroName, params, content);
1025    }
1026    }
1027   
 
1028  161 toggle public void onMacroBlock(
1029    String macroName,
1030    WikiParameters params,
1031    String content)
1032    {
1033  161 checkBlockContainer();
1034  161 fListener.onMacroBlock(macroName, params, content);
1035    }
1036   
 
1037  168 toggle public void onMacroInline(
1038    String macroName,
1039    WikiParameters params,
1040    String content)
1041    {
1042  168 checkStyleOpened();
1043  168 fListener.onMacroInline(macroName, params, content);
1044  168 fInlineState.set(InlineState.MACRO);
1045    }
1046   
 
1047  472 toggle public void onNewLine()
1048    {
1049  472 checkStyleOpened();
1050  472 fListener.onNewLine();
1051  472 fInlineState.set(InlineState.NEW_LINE);
1052    }
1053   
 
1054  0 toggle public void onQuotLine(int depth)
1055    {
1056  0 endQuotLine();
1057  0 beginQuotLine(depth);
1058    }
1059   
 
1060  77 toggle public void onReference(String ref)
1061    {
1062  77 checkStyleOpened();
1063  77 fListener.onReference(ref);
1064  77 fInlineState.set(InlineState.REFERENCE);
1065    }
1066   
 
1067  340 toggle public void onReference(WikiReference ref)
1068    {
1069  340 checkStyleOpened();
1070  340 fListener.onReference(ref);
1071  340 fInlineState.set(InlineState.REFERENCE);
1072    }
1073   
 
1074  4161 toggle public void onSpace(String str)
1075    {
1076  4161 checkStyleOpened();
1077  4161 fListener.onSpace(str);
1078  4161 fInlineState.set(InlineState.SPACE);
1079    }
1080   
 
1081  1677 toggle public void onSpecialSymbol(String str)
1082    {
1083  1677 checkStyleOpened();
1084  1677 fListener.onSpecialSymbol(str);
1085  1677 fInlineState.set(InlineState.SPECIAL_SYMBOL);
1086    }
1087   
 
1088  1 toggle public void onTableCaption(String str)
1089    {
1090  1 beginTable();
1091  1 fListener.onTableCaption(str);
1092    }
1093   
 
1094  52 toggle public void onTableCell(boolean headCell)
1095    {
1096  52 onTableCell(headCell, null);
1097    }
1098   
 
1099  224 toggle public void onTableCell(boolean head, WikiParameters params)
1100    {
1101  224 checkStyleOpened();
1102  224 endTableCell();
1103  224 fTableHead = head;
1104  224 fTableCellParams = params != null ? params : WikiParameters.EMPTY;
1105  224 beginTableCell(head, params);
1106    }
1107   
 
1108  8 toggle public void onTableRow(WikiParameters params)
1109    {
1110  8 endTableRow();
1111  8 beginTableRow(params);
1112    }
1113   
 
1114  80 toggle public void onVerbatim(String str, boolean inline)
1115    {
1116  80 onVerbatim(str, inline, WikiParameters.EMPTY);
1117    }
1118   
 
1119  128 toggle public void onVerbatim(String str, boolean inline, WikiParameters params)
1120    {
1121  128 if (!inline) {
1122  51 checkBlockContainer();
1123  51 fListener.onVerbatimBlock(str, params);
1124    } else {
1125  77 checkStyleOpened();
1126  77 fListener.onVerbatimInline(str, params);
1127  77 fInlineState.set(InlineState.VERBATIM);
1128    }
1129    }
1130   
1131    /**
1132    * Waiting for following events to know if the verbatim is inline or not.
1133    */
 
1134  81 toggle public void onVerbatim(String str, WikiParameters params)
1135    {
1136  81 checkBlockContainer();
1137   
1138  81 fVerbatimContent = str;
1139  81 fVerbatimParameters = params;
1140    }
1141   
 
1142  7455 toggle public void onWord(String str)
1143    {
1144  7455 checkStyleOpened();
1145  7455 fListener.onWord(str);
1146  7455 fInlineState.set(InlineState.WORD);
1147    }
1148   
 
1149  14904 toggle private void openFormat()
1150    {
1151  14904 if (!fNewFormat.equals(fFormat)) {
1152  4419 WikiFormat newFormat = fNewFormat;
1153  4419 closeFormat();
1154  4419 fFormat = newFormat;
1155  4419 fNewFormat = newFormat;
1156  4419 fListener.beginFormat(fFormat);
1157    }
1158  14904 fInlineState.set(InlineState.BEGIN_FORMAT);
1159    }
1160   
 
1161  692 toggle private String replace(String item, String from, String to)
1162    {
1163  692 int pos = 0;
1164  692 int prevPos = pos;
1165  692 StringBuffer buf = new StringBuffer();
1166  692 while (true) {
1167  704 pos = item.indexOf(from, pos);
1168  704 if (pos < 0) {
1169  692 pos = item.length();
1170  692 break;
1171    }
1172  12 buf.append(item.substring(prevPos, pos));
1173  12 buf.append(to);
1174  12 pos += from.length();
1175  12 prevPos = pos;
1176    }
1177  692 buf.append(item.substring(prevPos, pos));
1178  692 return buf.toString();
1179    }
1180   
 
1181  692 toggle private String trimLineBreaks(String item)
1182    {
1183  692 StringBuffer buf = new StringBuffer();
1184  692 char[] array = item.toCharArray();
1185  692 for (char ch : array) {
1186  1193 if (ch == '\n' || ch == '\r') {
1187  88 continue;
1188    }
1189  1105 buf.append(ch);
1190    }
1191  692 return buf.toString();
1192    }
1193    }