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

File XHTMLChainingRenderer.java

 

Coverage histogram

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

Code metrics

36
159
48
1
559
401
85
0.53
3.31
48
1.77

Classes

Class Line # Actions
XHTMLChainingRenderer 50 159 0% 85 4
0.983539198.4%
 

Contributing tests

This file is covered by 554 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.xhtml;
21   
22    import java.util.LinkedHashMap;
23    import java.util.List;
24    import java.util.Map;
25   
26    import org.xwiki.rendering.internal.renderer.xhtml.image.XHTMLImageRenderer;
27    import org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkRenderer;
28    import org.xwiki.rendering.listener.Format;
29    import org.xwiki.rendering.listener.HeaderLevel;
30    import org.xwiki.rendering.listener.ListType;
31    import org.xwiki.rendering.listener.MetaData;
32    import org.xwiki.rendering.listener.chaining.BlockStateChainingListener;
33    import org.xwiki.rendering.listener.chaining.BlockStateChainingListener.Event;
34    import org.xwiki.rendering.listener.chaining.EmptyBlockChainingListener;
35    import org.xwiki.rendering.listener.chaining.ListenerChain;
36    import org.xwiki.rendering.listener.chaining.MetaDataStateChainingListener;
37    import org.xwiki.rendering.listener.reference.ResourceReference;
38    import org.xwiki.rendering.renderer.AbstractChainingPrintRenderer;
39    import org.xwiki.rendering.renderer.printer.WikiPrinter;
40    import org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter;
41    import org.xwiki.rendering.syntax.Syntax;
42    import org.xwiki.rendering.syntax.SyntaxType;
43   
44    /**
45    * Convert listener events to XHTML.
46    *
47    * @version $Id: a63a17951449f51d0ab1649a86b8c2e900bddbeb $
48    * @since 1.8RC1
49    */
 
50    public class XHTMLChainingRenderer extends AbstractChainingPrintRenderer
51    {
52    private XHTMLLinkRenderer linkRenderer;
53   
54    private XHTMLImageRenderer imageRenderer;
55   
56    private XHTMLWikiPrinter xhtmlWikiPrinter;
57   
58    /**
59    * @param linkRenderer the object to render link events into XHTML. This is done so that it's pluggable because link
60    * rendering depends on how the underlying system wants to handle it. For example for XWiki we check if
61    * the document exists, we get the document URL, etc.
62    * @param imageRenderer the object to render image events into XHTML. This is done so that it's pluggable because
63    * image rendering depends on how the underlying system wants to handle it. For example for XWiki we
64    * check if the image exists as a document attachments, we get its URL, etc.
65    * @param listenerChain the chain of listener filters used to compute various states
66    */
 
67  19600 toggle public XHTMLChainingRenderer(XHTMLLinkRenderer linkRenderer, XHTMLImageRenderer imageRenderer,
68    ListenerChain listenerChain)
69    {
70  19599 setListenerChain(listenerChain);
71   
72  19599 this.linkRenderer = linkRenderer;
73  19597 this.imageRenderer = imageRenderer;
74    }
75   
76    // State
77   
 
78  48138 toggle protected BlockStateChainingListener getBlockState()
79    {
80  48138 return (BlockStateChainingListener) getListenerChain().getListener(BlockStateChainingListener.class);
81    }
82   
 
83  812 toggle protected EmptyBlockChainingListener getEmptyBlockState()
84    {
85  812 return (EmptyBlockChainingListener) getListenerChain().getListener(EmptyBlockChainingListener.class);
86    }
87   
 
88  1296 toggle protected MetaDataStateChainingListener getMetaDataState()
89    {
90  1296 return (MetaDataStateChainingListener) getListenerChain().getListener(MetaDataStateChainingListener.class);
91    }
92   
93    // Printer
94   
 
95  19599 toggle @Override
96    protected void pushPrinter(WikiPrinter wikiPrinter)
97    {
98  19600 super.pushPrinter(wikiPrinter);
99  19599 getXHTMLWikiPrinter().setWikiPrinter(getPrinter());
100    }
101   
 
102  0 toggle @Override
103    protected void popPrinter()
104    {
105  0 super.popPrinter();
106  0 getXHTMLWikiPrinter().setWikiPrinter(getPrinter());
107    }
108   
 
109  109795 toggle protected XHTMLWikiPrinter getXHTMLWikiPrinter()
110    {
111  109795 if (this.xhtmlWikiPrinter == null) {
112  19466 this.xhtmlWikiPrinter = new XHTMLWikiPrinter(getPrinter());
113    }
114  109796 return this.xhtmlWikiPrinter;
115    }
116   
117    // Events
118   
 
119  1539 toggle @Override
120    public void beginGroup(Map<String, String> parameters)
121    {
122  1539 Map<String, String> clonedParameters = new LinkedHashMap<String, String>();
123  1539 clonedParameters.putAll(parameters);
124  1539 getXHTMLWikiPrinter().printXMLStartElement("div", clonedParameters);
125    }
126   
 
127  1539 toggle @Override
128    public void endGroup(Map<String, String> parameters)
129    {
130  1539 getXHTMLWikiPrinter().printXMLEndElement("div");
131    }
132   
 
133  4872 toggle @Override
134    public void beginFormat(Format format, Map<String, String> parameters)
135    {
136  4872 switch (format) {
137  386 case BOLD:
138  386 getXHTMLWikiPrinter().printXMLStartElement("strong");
139  386 break;
140  99 case ITALIC:
141  99 getXHTMLWikiPrinter().printXMLStartElement("em");
142  99 break;
143  6 case STRIKEDOUT:
144  6 getXHTMLWikiPrinter().printXMLStartElement("del");
145  6 break;
146  4 case UNDERLINED:
147  4 getXHTMLWikiPrinter().printXMLStartElement("ins");
148  4 break;
149  5 case SUPERSCRIPT:
150  5 getXHTMLWikiPrinter().printXMLStartElement("sup");
151  5 break;
152  5 case SUBSCRIPT:
153  5 getXHTMLWikiPrinter().printXMLStartElement("sub");
154  5 break;
155  4 case MONOSPACE:
156  4 getXHTMLWikiPrinter().printXMLStartElement("tt");
157  4 break;
158  4363 case NONE:
159  4363 break;
160    }
161  4872 if (!parameters.isEmpty()) {
162  4373 getXHTMLWikiPrinter().printXMLStartElement("span", parameters);
163    }
164    }
165   
 
166  4872 toggle @Override
167    public void endFormat(Format format, Map<String, String> parameters)
168    {
169  4872 if (!parameters.isEmpty()) {
170  187 getXHTMLWikiPrinter().printXMLEndElement("span");
171    }
172  4872 switch (format) {
173  386 case BOLD:
174  386 getXHTMLWikiPrinter().printXMLEndElement("strong");
175  386 break;
176  99 case ITALIC:
177  99 getXHTMLWikiPrinter().printXMLEndElement("em");
178  99 break;
179  6 case STRIKEDOUT:
180  6 getXHTMLWikiPrinter().printXMLEndElement("del");
181  6 break;
182  4 case UNDERLINED:
183  4 getXHTMLWikiPrinter().printXMLEndElement("ins");
184  4 break;
185  5 case SUPERSCRIPT:
186  5 getXHTMLWikiPrinter().printXMLEndElement("sup");
187  5 break;
188  5 case SUBSCRIPT:
189  5 getXHTMLWikiPrinter().printXMLEndElement("sub");
190  5 break;
191  4 case MONOSPACE:
192  4 getXHTMLWikiPrinter().printXMLEndElement("tt");