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

File PreserveTagHandler.java

 

Coverage histogram

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

Code metrics

0
15
10
2
104
67
10
0.67
1.5
5
1

Classes

Class Line # Actions
PreserveTagHandler 30 9 0% 4 0
1.0100%
PreserverListener 65 6 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 322 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.xhtml.handler;
21   
22    import org.xwiki.rendering.wikimodel.EmptyWemListener;
23    import org.xwiki.rendering.wikimodel.impl.WikiScannerContext;
24    import org.xwiki.rendering.wikimodel.xhtml.impl.TagContext;
25   
26    /**
27    * @version $Id: 18c7f129150e17ac85bd7ea52032d09d87f13fb9 $
28    * @since 4.0M1
29    */
 
30    public class PreserveTagHandler extends TagHandler
31    {
 
32  481 toggle public PreserveTagHandler()
33    {
34  481 super(true);
35    }
36   
 
37  88 toggle @Override
38    protected void begin(TagContext context)
39    {
40    // filter content of the <pre> element
41  88 context.getTagStack().pushScannerContext(
42    new WikiScannerContext(new PreserverListener()));
43  88 context.getScannerContext().beginDocument();
44    }
45   
 
46  88 toggle @Override
47    protected void end(TagContext context)
48    {
49  88 context.getScannerContext().endDocument();
50  88 PreserverListener preserverListener = (PreserverListener) context
51    .getTagStack().popScannerContext().getfListener();
52  88 sendEmptyLines(context);
53   
54  88 String preservedContent = preserverListener.toString();
55  88 handlePreservedContent(context, preservedContent);
56    }
57   
 
58  14 toggle protected void handlePreservedContent(TagContext context, String preservedContent)
59    {
60  14 context.getScannerContext().onVerbatim(preservedContent,
61    false, context.getParams());
62    }
63    }
64   
 
65    class PreserverListener extends EmptyWemListener
66    {
67    StringBuffer buffer = new StringBuffer();
68   
 
69  99 toggle @Override
70    public String toString()
71    {
72  99 return this.buffer.toString();
73    }
74   
 
75  247 toggle @Override
76    public void onWord(String str)
77    {
78  247 this.buffer.append(str);
79    }
80   
 
81  28 toggle @Override
82    public void onSpecialSymbol(String str)
83    {
84  28 this.buffer.append(str);
85    }
86   
 
87  158 toggle @Override
88    public void onSpace(String str)
89    {
90  158 this.buffer.append(str);
91    }
92   
 
93  11 toggle @Override
94    public void onLineBreak()
95    {
96  11 this.buffer.append("\n");
97    }
98   
 
99  4 toggle @Override
100    public void onNewLine()
101    {
102  4 this.buffer.append("\n");
103    }
104    }