Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart6.png 81% of files have more coverage
41   189   25   2.93
20   134   0.61   7
14     1.79  
2    
 
  ConfluenceExtendedWikiParser       Line # 39 3 0% 2 0 100% 1.0
  ConfluenceExtendedWikiParser.EnhancedListener       Line # 41 38 0% 23 31 55.7% 0.55714285
 
No Tests
 
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.confluence;
21   
22    import java.io.Reader;
23    import java.io.StringReader;
24    import java.util.Stack;
25   
26    import org.xwiki.rendering.wikimodel.CompositeListener;
27    import org.xwiki.rendering.wikimodel.IWemListener;
28    import org.xwiki.rendering.wikimodel.WikiParameters;
29    import org.xwiki.rendering.wikimodel.WikiParserException;
30   
31    /**
32    * <pre>
33    * http://confluence.atlassian.com/renderer/notationhelp.action?section=all
34    * </pre>
35    *
36    * @version $Id: 6b40eaca9bddf1f56364b69310b6c7235ac6a018 $
37    * @since 4.0M1
38    */
 
39    public class ConfluenceExtendedWikiParser extends ConfluenceWikiParser
40    {
 
41    public static class EnhancedListener extends CompositeListener
42    {
43    private Stack<Boolean> fSkipDocument = new Stack<Boolean>();
44   
 
45  5 toggle public EnhancedListener(IWemListener... listeners)
46    {
47  5 super(listeners);
48    }
49   
 
50  5 toggle @Override
51    public void beginDocument(WikiParameters params)
52    {
53  5 if (!skipDocument()) {
54  5 super.beginDocument(params);
55    }
56    }
57   
 
58  7 toggle @Override
59    public void beginSection(
60    int docLevel,
61    int headerLevel,
62    WikiParameters params)
63    {
64  7 if (!skipDocument()) {
65  7 super.beginSection(docLevel, headerLevel, params);
66    }
67    }
68   
 
69  7 toggle @Override
70    public void beginSectionContent(
71    int docLevel,
72    int headerLevel,
73    WikiParameters params)
74    {
75  7 if (!skipDocument()) {
76  7 super.beginSectionContent(docLevel, headerLevel, params);
77    }
78  7 push(false);
79    }
80   
 
81  5 toggle @Override
82    public void endDocument(WikiParameters params)
83    {
84  5 if (!skipDocument()) {
85  5 super.endDocument(params);
86    }
87    }
88   
 
89  7 toggle @Override
90    public void endSection(
91    int docLevel,
92    int headerLevel,
93    WikiParameters params)
94    {
95  7 if (!skipDocument()) {
96  7 super.endSection(docLevel, headerLevel, params);
97    }
98    }
99   
 
100  7 toggle @Override
101    public void endSectionContent(
102    int docLevel,
103    int headerLevel,
104    WikiParameters params)
105    {
106  7 pop();
107  7 if (!skipDocument()) {
108  7 super.endSectionContent(docLevel, headerLevel, params);
109    }
110    }
111   
 
112  0 toggle @Override
113    public void onMacroBlock(
114    String macroName,
115    WikiParameters params,
116    String content)
117    {
118  0 String type = null;
119  0 if ("note".equals(macroName)) {
120  0 type = "N";
121  0 } else if ("tip".equals(macroName)) {
122  0 type = "T";
123    }
124  0 if (type != null) {
125  0 beginInfoBlock(type, params);
126  0 parseContent(content);
127  0 endInfoBlock(type, params);
128    } else {
129  0 super.onMacroBlock(macroName, params, content);
130    }
131    }
132   
133    /**
134    * @param content
135    * @throws WikiParserException
136    */
 
137  0 toggle private void parseContent(String content)
138    {
139  0 try {
140  0 push(true);
141  0 StringReader reader = new StringReader(content);
142  0 ConfluenceWikiParser parser = new ConfluenceWikiParser();
143  0 parser.parse(reader, this);
144  0 pop();
145    } catch (WikiParserException e) {
146  0 throw new RuntimeException(e);
147    }
148    }
149   
 
150  7 toggle private void pop()
151    {
152  7 fSkipDocument.pop();
153    }
154   
 
155  7 toggle private void push(boolean b)
156    {
157  7 fSkipDocument.push(b);
158    }
159   
 
160  38 toggle private boolean skipDocument()
161    {
162  38 if (fSkipDocument.isEmpty()) {
163  30 return false;
164    }
165  8 Boolean peek = fSkipDocument.peek();
166  8 return peek;
167    }
168    }
169   
170    /**
171    *
172    */
 
173  5 toggle public ConfluenceExtendedWikiParser()
174    {
175  5 super();
176    }
177   
178    /**
179    * @see org.xwiki.rendering.wikimodel.IWikiParser#parse(java.io.Reader,
180    * org.xwiki.rendering.wikimodel.IWemListener)
181    */
 
182  5 toggle @Override
183    public void parse(Reader reader, IWemListener listener)
184    throws WikiParserException
185    {
186  5 IWemListener composite = new EnhancedListener(listener);
187  5 super.parse(reader, composite);
188    }
189    }