1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimodel.impl

File InternalWikiScannerContext.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

138
465
117
2
1,195
979
197
0.42
3.97
58.5
1.68

Classes

Class Line # Actions
InternalWikiScannerContext 39 465 0% 197 60
0.916666791.7%
InternalWikiScannerContext.IBlockTypes 41 0 - 0 0
-1.0 -
 

Contributing tests

This file is covered by 1473 tests. .

Source view

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