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

File LookaheadWikiPrinter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
14
10
1
96
52
11
0.79
1.4
10
1.1

Classes

Class Line # Actions
LookaheadWikiPrinter 31 14 0% 11 10
0.6153846461.5%
 

Contributing tests

This file is covered by 278 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.renderer.printer;
21   
22    /**
23    * Wiki printer that allows deferring printing text and that instead can save it in some internal buffer. This allows
24    * accumulating some content before it's flushed. This feature is used for example in the XWiki Syntax Renderer to
25    * accumulate text so that it be reviewed and escaped before printed (indeed some text has some characters that need to
26    * be escaped or they'd have a wiki meaning otherwise).
27    *
28    * @version $Id: 782b20abbf121e905e63b58a221ee6a21bb2f9fe $
29    * @since 1.7
30    */
 
31    public class LookaheadWikiPrinter extends WrappingWikiPrinter
32    {
33    private StringBuffer buffer = new StringBuffer();
34   
 
35  451 toggle public LookaheadWikiPrinter(WikiPrinter printer)
36    {
37  451 super(printer);
38    }
39   
 
40  2475 toggle protected void printInternal(String text)
41    {
42  2475 super.print(text);
43    }
44   
 
45  0 toggle protected void printlnInternal(String text)
46    {
47  0 super.println(text);
48    }
49   
 
50  1795 toggle @Override
51    public void print(String text)
52    {
53  1795 flush();
54  1795 printInternal(text);
55    }
56   
 
57  0 toggle @Override
58    public void println(String text)
59    {
60  0 flush();
61  0 printlnInternal(text);
62    }
63   
 
64  1946 toggle public void printDelayed(String text)
65    {
66  1946 getBuffer().append(text);
67    }
68   
 
69  0 toggle public void printlnDelayed(String text)
70    {
71  0 getBuffer().append(text).append(getEOL());
72    }
73   
 
74  8186 toggle public StringBuffer getBuffer()
75    {
76  8186 return this.buffer;
77    }
78   
 
79  680 toggle public void flush()
80    {
81  680 if (getBuffer().length() > 0) {
82  680 printInternal(getBuffer().toString());
83  680 getBuffer().setLength(0);
84    }
85    }
86   
87    /**
88    * This method is protected to allow classes extending this one to define what a new line is.
89    *
90    * @return a new line symbols
91    */
 
92  0 toggle protected String getEOL()
93    {
94  0 return "\n";
95    }
96    }