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

File ConfluenceInternalWikiScannerContext.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

24
78
11
1
205
153
28
0.36
7.09
11
2.55

Classes

Class Line # Actions
ConfluenceInternalWikiScannerContext 36 78 0% 28 28
0.752212475.2%
 

Contributing tests

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