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

File HTMLMacroXHTMLChainingRenderer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

14
20
12
1
150
90
19
0.95
1.67
12
1.58

Classes

Class Line # Actions
HTMLMacroXHTMLChainingRenderer 37 20 0% 19 7
0.8478260684.8%
 

Contributing tests

This file is covered by 10 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.html;
21   
22    import java.util.Map;
23   
24    import org.xwiki.rendering.internal.renderer.xhtml.XHTMLChainingRenderer;
25    import org.xwiki.rendering.internal.renderer.xhtml.image.XHTMLImageRenderer;
26    import org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkRenderer;
27    import org.xwiki.rendering.listener.chaining.ListenerChain;
28   
29    /**
30    * Renderer that generates XHTML from a XDOM resulting from the parsing of text containing HTML mixed with wiki syntax.
31    * We override the default XHTML renderer since we want special behaviors, for example to not escape special symbols
32    * (since we don't want to escape HTML tags for example).
33    *
34    * @version $Id $
35    * @since 1.8.3
36    */
 
37    public class HTMLMacroXHTMLChainingRenderer extends XHTMLChainingRenderer
38    {
39    /**
40    * @param linkRenderer the object to render link events into XHTML. This is done so that it's pluggable because link
41    * rendering depends on how the underlying system wants to handle it. For example for XWiki we check if
42    * the document exists, we get the document URL, etc.
43    * @param imageRenderer the object to render image events into XHTML. This is done so that it's pluggable because
44    * image rendering depends on how the underlying system wants to handle it. For example for XWiki we
45    * check if the image exists as a document attachments, we get its URL, etc.
46    * @param listenerChain the chain of listener filters used to compute various states
47    * @since 2.0M3
48    */
 
49  165 toggle public HTMLMacroXHTMLChainingRenderer(XHTMLLinkRenderer linkRenderer, XHTMLImageRenderer imageRenderer,
50    ListenerChain listenerChain)
51    {
52  165 super(linkRenderer, imageRenderer, listenerChain);
53    }
54   
55    /**
56    * @return true if the current event is generated from a transformation.
57    */
 
58  47453 toggle private boolean isInGeneratedBlock()
59    {
60  47453 return getBlockState().isInMacro();
61    }
62   
 
63  23669 toggle @Override
64    public void onSpecialSymbol(char symbol)
65    {
66  23669 if (!isInGeneratedBlock()) {
67  23600 getPrinter().print("" + symbol);
68    } else {
69  69 super.onSpecialSymbol(symbol);
70    }
71    }
72   
 
73  15166 toggle @Override
74    public void onWord(String word)
75    {
76  15166 if (!isInGeneratedBlock()) {
77  14734 getPrinter().print(word);
78    } else {
79  432 super.onWord(word);
80    }
81    }
82   
 
83  3291 toggle @Override
84    public void onNewLine()
85    {
86  3291 if (!isInGeneratedBlock()) {
87  3291 getPrinter().print("\n");
88    } else {
89  0 super.onNewLine();
90    }
91    }
92   
 
93  4830 toggle @Override
94    public void onSpace()
95    {
96  4830 if (!isInGeneratedBlock()) {
97  4432 getPrinter().print(" ");
98    } else {
99  398 super.onSpace();
100    }
101    }
102   
 
103  3 toggle @Override
104    public void onEmptyLines(int count)
105    {
106  3 if (!isInGeneratedBlock()) {
107    // Don't print anything.
108    } else {
109  1 super.onEmptyLines(count);
110    }
111    }
112   
 
113  247 toggle @Override
114    public void beginParagraph(Map<String, String> parameters)
115    {
116  247 if (!isInGeneratedBlock()) {
117    // Don't print anything.
118    } else {
119  0 super.beginParagraph(parameters);
120    }
121    }
122   
 
123  247 toggle @Override
124    public void endParagraph(Map<String, String> parameters)
125    {
126  247 if (!isInGeneratedBlock()) {
127    // Don't print anything.
128    } else {
129  0 super.endParagraph(parameters);
130    }
131    }
132   
 
133  0 toggle @Override
134    public void onMacro(String id, Map<String, String> parameters, String content, boolean inline)
135    {
136    // Don't print anything since we are already in the html macro.
137    }
138   
 
139  310 toggle @Override
140    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
141    {
142    // Don't print anything since we are already in the html macro.
143    }
144   
 
145  310 toggle @Override
146    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
147    {
148    // Don't print anything since we are already in the html macro.
149    }
150    }