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

File AnnotatedXHTMLChainingRenderer.java

 

Coverage histogram

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

Code metrics

2
14
7
1
118
57
8
0.57
2
7
1.14

Classes

Class Line # Actions
AnnotatedXHTMLChainingRenderer 38 14 0% 8 0
1.0100%
 

Contributing tests

This file is covered by 98 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.Map;
24   
25    import org.xwiki.rendering.internal.parser.xhtml.wikimodel.XHTMLXWikiGeneratorListener;
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.MetaData;
29    import org.xwiki.rendering.listener.chaining.ListenerChain;
30   
31    /**
32    * Convert listener events to annotated XHTML. See {@link AnnotatedXHTMLChainingRenderer} for more details on
33    * what Annotated XHTML is.
34    *
35    * @version $Id: fd99be18c0a1ac4879e10a5c86889ff8053ef5c7 $
36    * @since 2.0M2
37    */
 
38    public class AnnotatedXHTMLChainingRenderer extends XHTMLChainingRenderer
39    {
40    /**
41    * Renders a Macro definition into Annotated XHTML.
42    */
43    private XHTMLMacroRenderer macroRenderer;
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
48    * the document 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
51    * check if the 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  122 toggle public AnnotatedXHTMLChainingRenderer(XHTMLLinkRenderer linkRenderer,
55    XHTMLImageRenderer imageRenderer, ListenerChain listenerChain)
56    {
57  122 super(linkRenderer, imageRenderer, listenerChain);
58   
59  122 this.macroRenderer = new XHTMLMacroRenderer();
60    }
61   
 
62  9 toggle @Override
63    public void onMacro(String id, Map<String, String> parameters, String content, boolean inline)
64    {
65    // Do not do any rendering but we still need to save the macro definition in some hidden XHTML
66    // so that the macro can be reconstructed when moving back from XHTML to XDOM.
67  9 this.macroRenderer.render(getXHTMLWikiPrinter(), id, parameters, content);
68    }
69   
 
70  48 toggle @Override
71    public void beginMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
72    {
73    // Do not do any rendering but we still need to save the macro definition in some hidden XHTML
74    // so that the macro can be reconstructed when moving back from XHTML to XDOM.
75  48 this.macroRenderer.beginRender(getXHTMLWikiPrinter(), name, parameters, content);
76    }
77   
 
78  48 toggle @Override
79    public void endMacroMarker(String name, Map<String, String> parameters, String content, boolean isInline)
80    {
81    // Do not do any rendering but we still need to save the macro definition in some hidden XHTML
82    // so that the macro can be reconstructed when moving back from XHTML to XDOM.
83  48 this.macroRenderer.endRender(getXHTMLWikiPrinter());
84    }
85   
86    /**
87    * @return a span element if we are inside an inline macro. Else a div.
88    */
 
89  18 toggle private String getMetadataContainerElement()
90    {
91  18 if (getBlockState().isInLine()) {
92  4 return "span";
93    } else {
94  14 return "div";
95    }
96    }
97   
 
98  9 toggle @Override
99    public void beginMetaData(MetaData metadata)
100    {
101  9 Map<String, String> attributes = new LinkedHashMap<>();
102   
103  9 for (Map.Entry<String, Object> metadataPair : metadata.getMetaData().entrySet()) {
104  9 attributes.put(XHTMLXWikiGeneratorListener.METADATA_ATTRIBUTE_PREFIX + metadataPair.getKey(),
105    metadataPair.getValue().toString());
106    }
107   
108  9 attributes.put("class", XHTMLXWikiGeneratorListener.METADATA_CONTAINER_CLASS);
109   
110  9 this.getXHTMLWikiPrinter().printXMLStartElement(getMetadataContainerElement(), attributes);
111    }
112   
 
113  9 toggle @Override
114    public void endMetaData(MetaData metadata)
115    {
116  9 getXHTMLWikiPrinter().printXMLEndElement(getMetadataContainerElement());
117    }
118    }