1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.renderer.html5

File HTML5ChainingRenderer.java

 

Coverage histogram

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

Code metrics

12
27
8
1
146
86
14
0.52
3.38
8
1.75

Classes

Class Line # Actions
HTML5ChainingRenderer 37 27 0% 14 0
1.0100%
 

Contributing tests

This file is covered by 77 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.html5;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.xwiki.rendering.internal.renderer.xhtml.XHTMLChainingRenderer;
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.chaining.ListenerChain;
30   
31    /**
32    * Convert listener events to HTML5.
33    *
34    * @version $Id: f9d8f0befa5161564fd098fc8232403df40590dc $
35    * @since 6.4M3
36    */
 
37    public class HTML5ChainingRenderer extends XHTMLChainingRenderer
38    {
39    private static final String ELEM_SPAN = "span";
40   
41    private static final String ELEM_PRE = "pre";
42   
43    private static final String PROP_CLASS = "class";
44   
45    private static final String FIGURE_TAG = "figure";
46   
47    private static final String FIGURE_CAPTION_TAG = "figcaption";
48   
49    /**
50    * @param linkRenderer the object to render link events into XHTML. This is done so that it's pluggable because link
51    * rendering depends on how the underlying system wants to handle it. For example for XWiki we check if the document
52    * exists, we get the document URL, etc.
53    * @param imageRenderer the object to render image events into XHTML. This is done so that it's pluggable because
54    * image rendering depends on how the underlying system wants to handle it. For example for XWiki we check if the
55    * image exists as a document attachments, we get its URL, etc.
56    * @param listenerChain the chain of listener filters used to compute various states
57    */
 
58  379622 toggle public HTML5ChainingRenderer(XHTMLLinkRenderer linkRenderer,
59    XHTMLImageRenderer imageRenderer,
60    ListenerChain listenerChain)
61    {
62  379533 super(linkRenderer, imageRenderer, listenerChain);
63    }
64   
 
65  56441 toggle @Override
66    public void beginFormat(Format format, Map<String, String> parameters)
67    {
68    // Right now, the only difference with the super class is about the "monospace" format
69  56446 if (format == Format.MONOSPACE) {
70  26727 Map<String, String> attributes = new HashMap<>();
71  26727 attributes.putAll(parameters);
72  26727 String cssClass = "monospace";
73    // The element may already have a class
74  26727 if (attributes.containsKey(PROP_CLASS)) {
75  1 cssClass = String.format("%s %s", cssClass, attributes.get(PROP_CLASS));
76    }
77  26727 attributes.put(PROP_CLASS, cssClass);
78  26727 getXHTMLWikiPrinter().printXMLStartElement(ELEM_SPAN, attributes);
79    } else {
80    // Call the super class
81  29711 super.beginFormat(format, parameters);
82    }
83   
84    }
85   
 
86  56444 toggle @Override
87    public void endFormat(Format format, Map<String, String> parameters)
88    {
89  56446 if (!parameters.isEmpty()) {
90  7664 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
91    }
92    // Right now, the only difference with the super class is about the "monospace" format
93  56447 if (format == Format.MONOSPACE) {
94  26727 if (parameters.isEmpty()) {
95    // if the parameters are not empty, the span element has already been closed
96  26724 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
97    }
98    } else {
99    // Call the super class, with an empty parameters map to avoid closing the span element twice
100  29718 super.endFormat(format, new HashMap<String, String>());
101    }
102    }
103   
 
104  16375 toggle @Override
105    public void onVerbatim(String content, boolean inline, Map<String, String> parameters)
106    {
107  16376 if (inline) {
108    // Note: We generate a span element rather than a pre element since pre elements cannot be located inside
109    // paragraphs for example.
110    // The class is what is expected by wikimodel to understand the span as meaning a verbatim and not a
111    // Monospace element.
112  10189 getXHTMLWikiPrinter().printXMLStartElement(ELEM_SPAN,
113    new String[][] { { PROP_CLASS, "wikimodel-verbatim" } });
114  10189 getXHTMLWikiPrinter().printXML(content);
115  10189 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
116    } else {
117  6186 getXHTMLWikiPrinter().printXMLStartElement(ELEM_PRE, parameters);
118  6187 getXHTMLWikiPrinter().printXML(content);
119  6186 getXHTMLWikiPrinter().printXMLEndElement(ELEM_PRE);
120    }
121    }
122   
 
123  1 toggle @Override
124    public void beginFigure(Map<String, String> parameters)
125    {
126  1 getXHTMLWikiPrinter().printXMLStartElement(FIGURE_TAG, parameters);
127    }
128   
 
129  1 toggle @Override
130    public void beginFigureCaption(Map<String, String> parameters)
131    {
132  1 getXHTMLWikiPrinter().printXMLStartElement(FIGURE_CAPTION_TAG, parameters);
133    }
134   
 
135  1 toggle @Override
136    public void endFigure(Map<String, String> parameters)
137    {
138  1 getXHTMLWikiPrinter().printXMLEndElement(FIGURE_TAG);
139    }
140   
 
141  1 toggle @Override
142    public void endFigureCaption(Map<String, String> parameters)
143    {
144  1 getXHTMLWikiPrinter().printXMLEndElement(FIGURE_CAPTION_TAG);
145    }
146    }