1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.chart.source.table

File MacroContentTableBlockDataSource.java

 

Coverage histogram

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

Code metrics

4
7
1
1
78
38
3
0.43
7
1
3

Classes

Class Line # Actions
MacroContentTableBlockDataSource 49 7 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 14 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.internal.macro.chart.source.table;
21   
22    import java.util.List;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.annotation.InstantiationStrategy;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.block.TableBlock;
32    import org.xwiki.rendering.block.XDOM;
33    import org.xwiki.rendering.block.match.ClassBlockMatcher;
34    import org.xwiki.rendering.macro.MacroContentParser;
35    import org.xwiki.rendering.macro.MacroExecutionException;
36    import org.xwiki.rendering.transformation.MacroTransformationContext;
37   
38    import static org.xwiki.component.descriptor.ComponentInstantiationStrategy.PER_LOOKUP;
39   
40    /**
41    * A data source for building charts from a wiki table defined in the macro content.
42    *
43    * @version $Id: 8b03fd28d7312894725cb3458ad960af568fb8af $
44    * @since 4.2M1
45    */
46    @Component
47    @Named("inline")
48    @InstantiationStrategy(PER_LOOKUP)
 
49    public class MacroContentTableBlockDataSource extends AbstractTableBlockDataSource
50    {
51    /**
52    * Used to parse macro content containing wiki syntax.
53    */
54    @Inject
55    private MacroContentParser macroContentParser;
56   
 
57  14 toggle @Override
58    protected TableBlock getTableBlock(String macroContent, MacroTransformationContext context)
59    throws MacroExecutionException
60    {
61    // Since we are using an inline source the macro content cannot be empty/null.
62  14 if (StringUtils.isEmpty(macroContent)) {
63  2 throw new MacroExecutionException("A Chart Macro using an inline source must have a data table defined in "
64    + "its content.");
65    }
66   
67    // Parse the macro content into an XDOM.
68  12 XDOM xdom = this.macroContentParser.parse(macroContent, context, true, false);
69   
70    // Take the first TableBlock found in the macro content.
71  12 List<TableBlock> tableBlocks = xdom.getBlocks(new ClassBlockMatcher(TableBlock.class), Block.Axes.DESCENDANT);
72  12 if (tableBlocks.size() == 0) {
73  1 throw new MacroExecutionException("Unable to locate a suitable data table.");
74    }
75   
76  11 return tableBlocks.get(0);
77    }
78    }