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

File AbstractChainingPrintRenderer.java

 

Coverage histogram

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

Code metrics

6
10
5
1
93
40
8
0.8
2
5
1.6

Classes

Class Line # Actions
AbstractChainingPrintRenderer 33 10 0% 8 4
0.809523881%
 

Contributing tests

No tests hitting this source file were found.

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.renderer;
21   
22    import java.util.ArrayDeque;
23    import java.util.Deque;
24   
25    import org.xwiki.rendering.listener.chaining.AbstractChainingListener;
26    import org.xwiki.rendering.listener.chaining.ChainingListener;
27    import org.xwiki.rendering.renderer.printer.WikiPrinter;
28   
29    /**
30    * @version $Id: 93cde196e285213ec5d9e15d0478005adf47e2a6 $
31    * @since 1.8RC1
32    */
 
33    public abstract class AbstractChainingPrintRenderer extends AbstractChainingListener implements PrintRenderer
34    {
35    /**
36    * The printer stack. Can be used to print in a specific printer and then easily return to the previous one.
37    */
38    private Deque<WikiPrinter> printers = new ArrayDeque<WikiPrinter>();
39   
40    /**
41    * @return the main printer.
42    */
 
43  0 toggle public WikiPrinter getMainPrinter()
44    {
45  0 return this.printers.getLast();
46    }
47   
 
48  1273493 toggle @Override
49    public WikiPrinter getPrinter()
50    {
51  1273495 return this.printers.peek();
52    }
53   
54    /**
55    * {@inheritDoc}
56    *
57    * @since 2.0M3
58    */
 
59  215195 toggle @Override
60    public void setPrinter(WikiPrinter printer)
61    {
62  215195 pushPrinter(printer);
63    }
64   
65    /**
66    * Change the current {@link WikiPrinter} with the provided one.
67    *
68    * @param wikiPrinter the new {@link WikiPrinter} to use
69    */
 
70  215295 toggle protected void pushPrinter(WikiPrinter wikiPrinter)
71    {
72  215298 this.printers.push(wikiPrinter);
73   
74    // Since we're setting a new printer to use, make sure that all print renderers in the chain have the new
75    // printer set. Only do this if we're on the top level Print Renderer.
76  215307 if (getListenerChain().indexOf(getClass()) == 0) {
77  107575 ChainingListener nextListener = this;
78  ? while ((nextListener = getListenerChain().getNextListener(nextListener.getClass())) != null) {
79  342406 if (PrintRenderer.class.isAssignableFrom(nextListener.getClass())) {
80  107582 ((PrintRenderer) nextListener).setPrinter(wikiPrinter);
81    }
82    }
83    }
84    }
85   
86    /**
87    * Removes the current {@link WikiPrinter} and instead sets the previous printer as active.
88    */
 
89  115 toggle protected void popPrinter()
90    {
91  115 this.printers.pop();
92    }
93    }