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

File WikiScannerContext.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
132
99
1
612
470
104
0.79
1.33
99
1.05

Classes

Class Line # Actions
WikiScannerContext 36 132 0% 104 27
0.887966888.8%
 

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   
25    import org.xwiki.rendering.wikimodel.IWemListener;
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.SectionBuilder;
30    import org.xwiki.rendering.wikimodel.util.SectionListener;
31   
32    /**
33    * @version $Id: 8102556b1a32ae2336a97da36d535c1fc3f32d24 $
34    * @since 4.0M1
35    */
 
36    public class WikiScannerContext implements IWikiScannerContext
37    {
38    protected final IWemListener fListener;
39   
40    protected SectionBuilder<WikiParameters> fSectionBuilder;
41   
42    protected final Deque<IWikiScannerContext> fStack = new ArrayDeque<IWikiScannerContext>();
43   
 
44  24823 toggle public WikiScannerContext(IWemListener listener)
45    {
46  24822 fListener = listener;
47  24818 fSectionBuilder = new SectionBuilder<WikiParameters>(
48    new SectionListener<WikiParameters>()
49    {
 
50  26352 toggle @Override
51    public void beginDocument(IPos<WikiParameters> pos)
52    {
53  26353 WikiParameters params = pos.getData();
54  26358 fListener.beginDocument(params);
55  26360 beginSection(pos);
56  26357 beginSectionContent(pos);
57    }
58   
 
59  27928 toggle @Override
60    public void beginSection(IPos<WikiParameters> pos)
61    {
62  27928 WikiParameters params = pos.getData();
63  27931 int docLevel = pos.getDocumentLevel();
64  27931 int headerLevel = pos.getHeaderLevel();
65  27932 fListener.beginSection(docLevel, headerLevel, params);
66    }
67   
 
68  27926 toggle @Override
69    public void beginSectionContent(IPos<WikiParameters> pos)
70    {
71  27930 fListener.beginSectionContent(pos.getDocumentLevel(), pos
72    .getHeaderLevel(), pos.getData());
73    }
74   
 
75  1207 toggle @Override
76    public void beginSectionHeader(IPos<WikiParameters> pos)
77    {
78  1207 fListener.beginHeader(pos.getHeaderLevel(), pos.getData());
79    }
80   
 
81  26352 toggle @Override
82    public void endDocument(IPos<WikiParameters> pos)
83    {
84  26352 endSectionContent(pos);
85  26357 endSection(pos);
86  26355 WikiParameters params = pos.getData();
87  26356 fListener.endDocument(params);
88    }
89   
 
90  27923 toggle @Override
91    public void endSection(IPos<WikiParameters> pos)
92    {
93  27925 WikiParameters params = pos.getData();
94  27931 int docLevel = pos.getDocumentLevel();
95  27932 int headerLevel = pos.getHeaderLevel();
96  27933 fListener.endSection(docLevel, headerLevel, params);
97    }
98   
 
99  27925 toggle @Override
100    public void endSectionContent(IPos<WikiParameters> pos)
101    {
102  27927 fListener.endSectionContent(pos.getDocumentLevel(), pos
103    .getHeaderLevel(), pos.getData());
104    }
105   
 
106  1207 toggle @Override
107    public void endSectionHeader(IPos<WikiParameters> pos)
108    {
109  1207 fListener.endHeader(pos.getHeaderLevel(), pos.getData());
110    }
111    });
112    }
113   
 
114  121 toggle public IWemListener getfListener()
115    {
116  121 return this.fListener;
117    }
118   
 
119  24876 toggle public void beginDocument()
120    {
121  24877 InternalWikiScannerContext context = pushContext();
122  24875 context.beginDocument();
123    }
124   
 
125  1482 toggle public void beginDocument(WikiParameters params)
126    {
127  1482 InternalWikiScannerContext context = pushContext();
128  1482 context.beginDocument(params);
129    }
130   
 
131  232 toggle public void beginFormat(WikiParameters params)
132    {
133  232 getContext().beginFormat(params);
134    }
135   
 
136  137 toggle public void beginFormat(WikiStyle wikiStyle)
137    {
138  137 getContext().beginFormat(wikiStyle);
139    }
140   
 
141  55 toggle public void beginHeader(int level)
142    {
143  55 getContext().beginHeader(level);
144    }
145   
 
146  1152 toggle public void beginHeader(int level, WikiParameters params)
147    {
148  1152 getContext().beginHeader(level, params);
149    }
150   
 
151  7 toggle public void beginInfo(String type, WikiParameters params)
152    {
153  7 getContext().beginInfo(type, params);
154    }
155   
 
156  40 toggle public void beginList()
157    {
158  40 getContext().beginList();
159    }
160   
 
161  984 toggle public void beginList(WikiParameters params)
162    {
163  984 getContext().beginList(params);
164    }
165   
 
166  500 toggle public void beginListItem(String item)
167    {
168  500 getContext().beginListItem(item);
169    }
170   
 
171  6151 toggle public void beginListItem(String item, WikiParameters params)
172    {
173  6151 getContext().beginListItem(item, params);
174    }
175   
 
176  627 toggle public void beginParagraph()
177    {
178  627 getContext().beginParagraph();
179    }
180   
 
181  9405 toggle public void beginParagraph(WikiParameters params)
182    {
183  9405 getContext().beginParagraph(params);
184    }
185   
 
186  39 toggle public void beginPropertyBlock(String property, boolean doc)
187    {
188  39 getContext().beginPropertyBlock(property, doc);
189    }
190   
 
191  4 toggle public void beginPropertyInline(String str)
192    {
193  4 getContext().beginPropertyInline(str);
194    }
195   
 
196  16 toggle public void beginQuot()
197    {
198  16 getContext().beginQuot();
199    }
200   
 
201  48 toggle public void beginQuot(WikiParameters params)
202    {
203  48 getContext().beginQuot(params);
204    }
205   
 
206  122 toggle public void beginQuotLine(int depth)
207    {
208  122 getContext().beginQuotLine(depth);
209    }
210   
 
211  24 toggle public void beginTable()
212    {
213  24 getContext().beginTable();
214    }
215   
 
216  281 toggle public void beginTable(WikiParameters params)
217    {
218  281 getContext().beginTable(params);
219    }
220   
 
221  0 toggle public void beginTableCell(boolean headCell)
222    {
223  0 getContext().beginTableCell(headCell);
224    }
225   
 
226  163 toggle public void beginTableCell(boolean headCell, WikiParameters params)
227    {
228  163 getContext().beginTableCell(headCell, params);
229    }
230   
 
231  42 toggle public void beginTableRow(boolean headCell)
232    {
233  42 getContext().beginTableRow(headCell);
234    }
235   
 
236  525 toggle public void beginTableRow(boolean head, WikiParameters rowParams,
237    WikiParameters cellParams)
238    {
239  525 getContext().beginTableRow(head, rowParams, cellParams);
240    }
241   
 
242  73 toggle public void beginTableRow(WikiParameters rowParams)
243    {
244  73 getContext().beginTableRow(rowParams);
245    }
246   
 
247  40 toggle public boolean canApplyDefintionSplitter()
248    {
249  40 return getContext().canApplyDefintionSplitter();
250    }
251   
 
252  30 toggle public boolean checkFormatStyle(WikiStyle style)
253    {
254  30 return getContext().checkFormatStyle(style);
255    }
256   
 
257  0 toggle public void closeBlock()
258    {
259  0 getContext().closeBlock();
260    }
261   
 
262  26357 toggle public void endDocument()
263    {
264  26355 getContext().endDocument();
265  26356 fStack.pop();
266    }
267   
 
268  183 toggle public void endFormat(WikiParameters params)
269    {
270  183 getContext().endFormat(params);
271    }
272   
 
273  136 toggle public void endFormat(WikiStyle wikiStyle)
274    {
275  136 getContext().endFormat(wikiStyle);
276    }
277   
 
278  1207 toggle public void endHeader()
279    {
280  1207 getContext().endHeader();
281    }
282   
 
283  7 toggle public void endInfo()
284    {
285  7 getContext().endInfo();
286    }
287   
 
288  959 toggle public void endList()
289    {
290  959 getContext().endList();
291    }
292   
 
293  6288 toggle public void endListItem()
294    {
295  6288 getContext().endListItem();
296    }
297   
 
298  21512 toggle public void endParagraph()
299    {
300  21511 getContext().endParagraph();
301    }
302   
 
303  39 toggle public void endPropertyBlock()
304    {
305  39 getContext().endPropertyBlock();
306    }
307   
 
308  4 toggle public void endPropertyInline()
309    {
310  4 getContext().endPropertyInline();
311    }
312   
 
313  64 toggle public void endQuot()
314    {
315  64 getContext().endQuot();
316    }
317   
 
318  114 toggle public void endQuotLine()
319    {
320  114 getContext().endQuotLine();
321    }
322   
 
323  305 toggle public void endTable()
324    {
325  305 getContext().endTable();
326    }
327   
 
328  163 toggle public void endTableCell()
329    {
330  163 getContext().endTableCell();
331    }
332   
 
333  0 toggle public void endTableExplicit()
334    {
335  0 getContext().endTableExplicit();
336    }
337   
 
338  640 toggle public void endTableRow()
339    {
340  640 getContext().endTableRow();
341    }
342   
 
343  678349 toggle public IWikiScannerContext getContext()
344    {
345  678347 if (!fStack.isEmpty()) {
346  653824 return fStack.peek();
347    }
348  24522 InternalWikiScannerContext context = newInternalContext();
349  24524 fStack.push(context);
350  24524 return context;
351    }
352   
 
353  30 toggle public InlineState getInlineState()
354    {
355  30 return getContext().getInlineState();
356    }
357   
 
358  4 toggle public int getTableCellCounter()
359    {
360  4 return getContext().getTableCellCounter();
361    }
362   
 
363  21 toggle public int getTableRowCounter()
364    {
365  21 return getContext().getTableRowCounter();
366    }
367   
 
368  0 toggle public boolean isInDefinitionList()
369    {
370  0 return getContext().isInDefinitionList();
371    }
372   
 
373  0 toggle public boolean isInDefinitionTerm()
374    {
375  0 return getContext().isInDefinitionTerm();
376    }
377   
 
378  46 toggle public boolean isInHeader()
379    {
380  46 return getContext().isInHeader();
381    }
382   
 
383  6 toggle public boolean isInInlineProperty()
384    {
385  6 return getContext().isInInlineProperty();
386    }
387   
 
388  0 toggle public boolean isInList()
389    {
390  0 return getContext().isInList();
391    }
392   
 
393  73 toggle public boolean isInTable()
394    {
395  73 return getContext().isInTable();
396    }
397   
 
398  0 toggle public boolean isInTableCell()
399    {
400  0 return getContext().isInTableCell();
401    }
402   
 
403  0 toggle public boolean isInTableRow()
404    {
405  0 return getContext().isInTableRow();
406    }
407   
408    /**
409    * @return
410    */
 
411  50579 toggle protected InternalWikiScannerContext newInternalContext()
412    {
413  50581 InternalWikiScannerContext context = new InternalWikiScannerContext(
414    fSectionBuilder,
415    fListener);
416  50584 return context;
417    }
418   
 
419  7 toggle public void onDefinitionListItemSplit()
420    {
421  7 getContext().onDefinitionListItemSplit();
422    }
423   
 
424  264 toggle public void onEmptyLines(int count)
425    {
426  264 getContext().onEmptyLines(count);
427    }
428   
 
429  20 toggle public void onEscape(String str)
430    {
431  20 getContext().onEscape(str);
432    }
433   
 
434  14 toggle public void onExtensionBlock(String extensionName, WikiParameters params)
435    {
436  14 getContext().onExtensionBlock(extensionName, params);
437    }
438   
 
439  6 toggle public void onExtensionInline(String extensionName, WikiParameters params)
440    {
441  6 getContext().onExtensionInline(extensionName, params);
442    }
443   
 
444  4659 toggle public void onFormat(WikiParameters params)
445    {
446  4659 getContext().onFormat(params);
447    }
448   
 
449  2610 toggle public void onFormat(WikiStyle wikiStyle)
450    {
451  2610 getContext().onFormat(wikiStyle);
452    }
453   
454    /**
455    * @see WikiScannerContext#onFormat(org.xwiki.rendering.wikimodel.WikiStyle,
456    * boolean)
457    */
 
458  0 toggle public void onFormat(WikiStyle wikiStyle, boolean forceClose)
459    {
460  0 getContext().onFormat(wikiStyle, forceClose);
461    }
462   
 
463  11 toggle public void onHorizontalLine()
464    {
465  11 getContext().onHorizontalLine();
466    }
467   
 
468  69 toggle public void onHorizontalLine(WikiParameters params)
469    {
470  69 getContext().onHorizontalLine(params);
471    }
472   
 
473  86 toggle public void onImage(String ref)
474    {
475  86 getContext().onImage(ref);
476    }
477   
 
478  542 toggle public void onImage(WikiReference ref)
479    {
480  542 getContext().onImage(ref);
481    }
482   
 
483  67 toggle public void onLineBreak()
484    {
485  67 getContext().onLineBreak();
486    }
487   
 
488  7086 toggle public void onMacro(String name, WikiParameters params, String content)
489    {
490  7087 getContext().onMacro(name, params, content);
491    }
492   
 
493  4566 toggle public void onMacro(String macroName, WikiParameters params,
494    String content, boolean inline)
495    {
496  4566 if (inline) {
497  4566 onMacroInline(macroName, params, content);
498    } else {
499  0 onMacroBlock(macroName, params, content);
500    }
501    }
502   
 
503  158 toggle public void onMacroBlock(String macroName, WikiParameters params,
504    String content)
505    {
506  158 getContext().onMacroBlock(macroName, params, content);
507    }
508   
 
509  4595 toggle public void onMacroInline(String macroName, WikiParameters params,
510    String content)
511    {
512  4595 getContext().onMacroInline(macroName, params, content);
513    }
514   
 
515  4253 toggle public void onNewLine()
516    {
517  4253 getContext().onNewLine();
518    }
519   
 
520  0 toggle public void onQuotLine(int depth)
521    {
522  0 getContext().onQuotLine(depth);
523    }
524   
 
525  87 toggle public void onReference(String ref)
526    {
527  87 getContext().onReference(ref);
528    }
529   
 
530  1221 toggle public void onReference(WikiReference ref)
531    {
532  1221 getContext().onReference(ref);
533    }
534   
 
535  93356 toggle public void onSpace(String str)
536    {
537  93356 getContext().onSpace(str);
538    }
539   
 
540  250686 toggle public void onSpecialSymbol(String str)
541    {
542    // Extract white spaces from special characters
543  501481 for (int i = 0; i < str.length(); i++) {
544  250795 char c = str.charAt(i);
545  250795 if (c == ' ') {
546  18 getContext().onSpace(" ");
547    } else {
548  250777 getContext().onSpecialSymbol(String.valueOf(c));
549    }
550    }
551    }
552   
 
553  0 toggle public void onTableCaption(String str)
554    {
555  0 getContext().onTableCaption(str);
556    }
557   
 
558  42 toggle public void onTableCell(boolean headCell)
559    {
560  42 getContext().onTableCell(headCell);
561    }
562   
 
563  767 toggle public void onTableCell(boolean head, WikiParameters cellParams)
564    {
565  767 getContext().onTableCell(head, cellParams);
566    }
567   
568    /**
569    * @see WikiScannerContext#onTableRow(org.xwiki.rendering.wikimodel.WikiParameters)
570    */
 
571  0 toggle public void onTableRow(WikiParameters params)
572    {
573  0 getContext().onTableRow(params);
574    }
575   
576    /**
577    * @see WikiScannerContext#onVerbatim(java.lang.String,
578    * boolean)
579    */
 
580  81 toggle public void onVerbatim(String str, boolean inline)
581    {
582  81 getContext().onVerbatim(str, inline);
583    }
584   
 
585  84 toggle public void onVerbatim(String str, boolean inline, WikiParameters params)
586    {
587  84 getContext().onVerbatim(str, inline, params);
588    }
589   
 
590  89 toggle public void onVerbatim(String str, WikiParameters params)
591    {
592  89 getContext().onVerbatim(str, params);
593    }
594   
 
595  204668 toggle public void onWord(String str)
596    {
597  204668 getContext().onWord(str);
598    }
599   
 
600  26360 toggle private InternalWikiScannerContext pushContext()
601    {
602  26359 InternalWikiScannerContext context = (InternalWikiScannerContext) getContext();
603  26358 if (context != null) {
604  26357 context.checkBlockContainer();
605  26357 context.closeFormat();
606    }
607  26355 context = newInternalContext();
608  26358 fStack.push(context);
609   
610  26358 return context;
611    }
612    }