Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../img/srcFileCovDistChart8.png 68% of files have more coverage
78   204   28   7.09
24   152   0.36   11
11     2.55  
1    
 
  ConfluenceInternalWikiScannerContext       Line # 35 78 0% 28 28 75.2% 0.7522124
 
  (2)
 
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.util.Stack;
23   
24    import org.xwiki.rendering.wikimodel.IWemListener;
25    import org.xwiki.rendering.wikimodel.WikiParameters;
26    import org.xwiki.rendering.wikimodel.impl.InternalWikiScannerContext;
27    import org.xwiki.rendering.wikimodel.util.IListListener;
28    import org.xwiki.rendering.wikimodel.util.ListBuilder;
29    import org.xwiki.rendering.wikimodel.util.SectionBuilder;
30   
31    /**
32    * @version $Id: c240d2e0e8ec648de9637fe6225b764985a853f9 $
33    * @since 4.0M1
34    */
 
35    public class ConfluenceInternalWikiScannerContext extends
36    InternalWikiScannerContext
37    {
38    private int fPreBlockType = IBlockTypes.NONE;
39   
 
40  562 toggle public ConfluenceInternalWikiScannerContext(
41    SectionBuilder<WikiParameters> sectionBuilder, IWemListener listener)
42    {
43  562 super(sectionBuilder, listener);
44    }
45   
46    /**
47    * {@inheritDoc}
48    * <p>
49    * Modified to make sure last empty cell of a row is not taken into account.
50    *
51    * @see org.xwiki.rendering.wikimodel.impl.InternalWikiScannerContext#onTableCell(boolean,
52    * org.xwiki.rendering.wikimodel.WikiParameters)
53    */
 
54  21 toggle @Override
55    public void onTableCell(boolean head, WikiParameters params)
56    {
57  21 checkStyleOpened();
58  21 checkListOpened();
59  21 endTableCell();
60  21 fTableHead = head;
61  21 fTableCellParams = params != null ? params : WikiParameters.EMPTY;
62   
63    // Commented because we don't want last empty cell of a row to be taken
64    // into account
65    // beginTableCell(head, params);
66    }
67   
 
68  48 toggle @Override
69    public void beginList()
70    {
71  48 if ((fBlockType & IBlockTypes.LIST) != IBlockTypes.LIST) {
72  16 if (!isInTable()) {
73  12 closeBlock();
74    } else {
75  4 checkStyleOpened();
76  4 fPreBlockType = fBlockType;
77    }
78  16 if (fListParams == null) {
79  14 fListParams = WikiParameters.EMPTY;
80    }
81  16 IListListener listener = new IListListener()
82    {
83    private Stack<WikiParameters> fListParamsStack = new Stack<WikiParameters>();
84   
 
85  40 toggle public void beginRow(char treeType, char rowType)
86    {
87  40 if (rowType == ':') {
88  0 fBlockType = IBlockTypes.LIST_DL_DD;
89  0 fListener.beginDefinitionDescription();
90  40 } else if (rowType == ';') {
91  0 fBlockType = IBlockTypes.LIST_DL_DT;
92  0 fListener.beginDefinitionTerm();
93    } else {
94  40 fBlockType = IBlockTypes.LIST_LI;
95  40 fListener.beginListItem();
96    }
97  40 beginStyleContainer();
98    }
99   
 
100  32 toggle public void beginTree(char type)
101    {
102  32 fListParamsStack.push(fListParams);
103   
104  32 closeFormat();
105  32 switch (type) {
106  8 case '#':
107  8 fListener.beginList(fListParams, true);
108  8 fBlockType = IBlockTypes.LIST;
109  8 break;
110  0 case 'd':
111  0 fListener.beginDefinitionList(fListParams);
112  0 fBlockType = IBlockTypes.LIST_DL;
113  0 break;
114  24 default:
115  24 fListener.beginList(fListParams, false);
116  24 fBlockType = IBlockTypes.LIST;
117  24 break;
118    }
119   
120  32 fListParams = WikiParameters.EMPTY;
121    }
122   
 
123  40 toggle public void endRow(char treeType, char rowType)
124    {
125  40 closeFormat();
126  40 endStyleContainer();
127  40 if (rowType == ':') {
128  0 fListener.endDefinitionDescription();
129  0 fBlockType = IBlockTypes.LIST_DL;
130  40 } else if (rowType == ';') {
131  0 if ((fBlockType & IBlockTypes.LIST_DL_DT) == IBlockTypes.LIST_DL_DT) {
132  0 fListener.endDefinitionTerm();
133    } else {
134  0 fListener.endDefinitionDescription();
135    }
136  0 fBlockType = IBlockTypes.LIST_DL;
137    } else {
138  40 fListener.endListItem();
139  40 fBlockType = IBlockTypes.LIST;
140    }
141    }
142   
 
143  32 toggle public void endTree(char type)
144    {
145  32 switch (type) {
146  8 case '#':
147  8 fListener.endList(fListParamsStack.peek(), true);
148  8 fBlockType = IBlockTypes.LIST;
149  8 break;
150  0 case 'd':
151  0 fListener
152    .endDefinitionList(fListParamsStack.peek());
153  0 fBlockType = IBlockTypes.LIST;
154  0 break;
155  24 default:
156  24 fListener.endList(fListParamsStack.peek(), false);
157  24 fBlockType = IBlockTypes.LIST;
158  24 break;
159    }
160   
161  32 fListParamsStack.pop();
162    }
163    };
164  16 fListBuilder = new ListBuilder(listener)
165    {
 
166  54 toggle @Override
167    protected char getTreeType(char rowType)
168    {
169  54 if (rowType == ';' || rowType == ':') {
170  0 return 'd';
171    }
172  54 return rowType;
173    }
174    };
175  16 fBlockType = IBlockTypes.LIST;
176    }
177    }
178   
 
179  36 toggle @Override
180    public void endList()
181    {
182  36 if ((fBlockType & IBlockTypes.LIST) != 0) {
183  16 fListBuilder.alignContext("");
184  16 fListBuilder = null;
185   
186  16 fBlockType = fPreBlockType;
187  16 fPreBlockType = IBlockTypes.NONE;
188    }
189    }
190   
 
191  43 toggle public boolean isExplicitInTable()
192    {
193  43 return super.isInTable()
194    || (((fPreBlockType & IBlockTypes.TABLE) == IBlockTypes.TABLE) &&
195    (fBlockType & IBlockTypes.LIST) == IBlockTypes.LIST);
196    }
197   
 
198  21 toggle private void checkListOpened()
199    {
200  21 if (isExplicitInTable()) {
201  21 endList();
202    }
203    }
204    }