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

File AbstractBlockRenderer.java

 

Coverage histogram

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

Code metrics

4
9
2
1
76
40
5
0.56
4.5
2
2.5

Classes

Class Line # Actions
AbstractBlockRenderer 42 9 0% 5 4
0.7333333573.3%
 

Contributing tests

This file is covered by 957 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.renderer;
21   
22    import java.io.Flushable;
23    import java.io.IOException;
24    import java.util.Collection;
25    import java.util.Collections;
26   
27    import javax.inject.Inject;
28   
29    import org.slf4j.Logger;
30    import org.xwiki.rendering.block.Block;
31    import org.xwiki.rendering.renderer.BlockRenderer;
32    import org.xwiki.rendering.renderer.PrintRenderer;
33    import org.xwiki.rendering.renderer.PrintRendererFactory;
34    import org.xwiki.rendering.renderer.printer.WikiPrinter;
35   
36    /**
37    * Common code for BlockRender implementation that uses Print Renderer Factory.
38    *
39    * @version $Id: a0b353cd2a3039fb85e693662fd44caef4ec76c7 $
40    * @since 2.0M3
41    */
 
42    public abstract class AbstractBlockRenderer implements BlockRenderer
43    {
44    @Inject
45    protected Logger logger;
46   
47    /**
48    * @return provide the factory to use to create a new {@link PrintRenderer}.
49    */
50    protected abstract PrintRendererFactory getPrintRendererFactory();
51   
 
52  105495 toggle @Override
53    public void render(Block block, WikiPrinter printer)
54    {
55  105491 render(Collections.singletonList(block), printer);
56    }
57   
 
58  105770 toggle @Override
59    public void render(Collection<Block> blocks, WikiPrinter printer)
60    {
61  105773 PrintRenderer renderer = getPrintRendererFactory().createRenderer(printer);
62  105776 for (Block block : blocks) {
63  106393 block.traverse(renderer);
64    }
65   
66  105773 if (renderer instanceof Flushable) {
67  217 try {
68  217 ((Flushable) renderer).flush();
69    } catch (IOException e) {
70  0 if (this.logger != null) {
71  0 this.logger.error("Failed to flush renderer [{}]", renderer, e);
72    }
73    }
74    }
75    }
76    }