1. Project Clover database Tue Dec 20 2016 21:24:09 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
23
4
1
118
64
10
0.43
5.75
4
2.5

Classes

Class Line # Actions
HTML5ChainingRenderer 37 23 0% 10 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: 4727c9b2bd43b5f7bec33f4f72ee732efe4b4c37 $
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    /**
46    * @param linkRenderer the object to render link events into XHTML. This is done so that it's pluggable because link
47    * rendering depends on how the underlying system wants to handle it. For example for XWiki we check if the document
48    * exists, we get the document URL, etc.
49    * @param imageRenderer the object to render image events into XHTML. This is done so that it's pluggable because
50    * image rendering depends on how the underlying system wants to handle it. For example for XWiki we check if the
51    * image exists as a document attachments, we get its URL, etc.
52    * @param listenerChain the chain of listener filters used to compute various states
53    */
 
54  18467 toggle public HTML5ChainingRenderer(XHTMLLinkRenderer linkRenderer,
55    XHTMLImageRenderer imageRenderer,
56    ListenerChain listenerChain)
57    {
58  18467 super(linkRenderer, imageRenderer, listenerChain);
59    }
60   
 
61  4624 toggle @Override
62    public void beginFormat(Format format, Map<String, String> parameters)
63    {
64    // Right now, the only difference with the super class is about the "monospace" format
65  4624 if (format == Format.MONOSPACE) {
66  15 Map<String, String> attributes = new HashMap<>();
67  15 attributes.putAll(parameters);
68  15 String cssClass = "monospace";
69    // The element may already have a class
70  15 if (attributes.containsKey(PROP_CLASS)) {
71  3 cssClass = String.format("%s %s", cssClass, attributes.get(PROP_CLASS));
72    }
73  15 attributes.put(PROP_CLASS, cssClass);
74  15 getXHTMLWikiPrinter().printXMLStartElement(ELEM_SPAN, attributes);
75    } else {
76    // Call the super class
77  4609 super.beginFormat(format, parameters);
78    }
79   
80    }
81   
 
82  4624 toggle @Override
83    public void endFormat(Format format, Map<String, String> parameters)
84    {
85  4624 if (!parameters.isEmpty()) {
86  4191 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
87    }
88    // Right now, the only difference with the super class is about the "monospace" format
89  4624 if (format == Format.MONOSPACE) {
90  15 if (parameters.isEmpty()) {
91    // if the parameters are not empty, the span element has already been closed
92  10 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
93    }
94    } else {
95    // Call the super class, with an empty parameters map to avoid closing the span element twice
96  4609 super.endFormat(format, new HashMap<String, String>());
97    }
98    }
99   
 
100  19 toggle @Override
101    public void onVerbatim(String content, boolean inline, Map<String, String> parameters)
102    {
103  19 if (inline) {
104    // Note: We generate a span element rather than a pre element since pre elements cannot be located inside
105    // paragraphs for example.
106    // The class is what is expected by wikimodel to understand the span as meaning a verbatim and not a
107    // Monospace element.
108  9 getXHTMLWikiPrinter().printXMLStartElement(ELEM_SPAN,
109    new String[][] { { PROP_CLASS, "wikimodel-verbatim" } });
110  9 getXHTMLWikiPrinter().printXML(content);
111  9 getXHTMLWikiPrinter().printXMLEndElement(ELEM_SPAN);
112    } else {
113  10 getXHTMLWikiPrinter().printXMLStartElement(ELEM_PRE, parameters);
114  10 getXHTMLWikiPrinter().printXML(content);
115  10 getXHTMLWikiPrinter().printXMLEndElement(ELEM_PRE);
116    }
117    }
118    }