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

File PrintInlineListener.java

 

Coverage histogram

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

Code metrics

14
33
16
1
229
142
23
0.7
2.06
16
1.44

Classes

Class Line # Actions
PrintInlineListener 34 33 0% 23 8
0.873015987.3%
 

Contributing tests

This file is covered by 132 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.wikimodel.xhtml;
21   
22    import org.xwiki.rendering.wikimodel.IWikiPrinter;
23    import org.xwiki.rendering.wikimodel.PrintTextListener;
24    import org.xwiki.rendering.wikimodel.ReferenceHandler;
25    import org.xwiki.rendering.wikimodel.WikiFormat;
26    import org.xwiki.rendering.wikimodel.WikiPageUtil;
27    import org.xwiki.rendering.wikimodel.WikiParameters;
28    import org.xwiki.rendering.wikimodel.util.WikiEntityUtil;
29   
30    /**
31    * @version $Id: e09ee63f427e3ca9184e3ce49a6aae3990341b6d $
32    * @since 4.0M1
33    */
 
34    public class PrintInlineListener extends PrintTextListener
35    {
36    /**
37    *
38    */
 
39  4 toggle public PrintInlineListener(IWikiPrinter printer)
40    {
41  4 super(printer);
42    }
43   
 
44  1337 toggle public PrintInlineListener(IWikiPrinter printer, boolean supportImage, boolean supportDownload)
45    {
46  1337 super(printer, supportImage, supportDownload);
47    }
48   
49    /**
50    * @see org.xwiki.rendering.wikimodel.IWemListener#beginFormat(org.xwiki.rendering.wikimodel.WikiFormat)
51    */
 
52  2009 toggle @Override
53    public void beginFormat(WikiFormat format)
54    {
55  2009 print(format.getTags(true));
56  2009 if (format.getParams().size() > 0) {
57  25 print("<span class='wikimodel-parameters'" + format.getParams() + ">");
58    }
59    }
60   
61    /**
62    * @see org.xwiki.rendering.wikimodel.IWemListener#beginPropertyInline(java.lang.String)
63    */
 
64  4 toggle @Override
65    public void beginPropertyInline(String str)
66    {
67  4 print("<span class='wikimodel-property' url='"
68    + WikiPageUtil.escapeXmlAttribute(str)
69    + "'>");
70    }
71   
72    /**
73    * @see org.xwiki.rendering.wikimodel.IWemListener#endFormat(org.xwiki.rendering.wikimodel.WikiFormat)
74    */
 
75  2009 toggle @Override
76    public void endFormat(WikiFormat format)
77    {
78  2009 if (format.getParams().size() > 0) {
79  25 print("</span>");
80    }
81  2009 print(format.getTags(false));
82    }
83   
84    /**
85    * @see org.xwiki.rendering.wikimodel.IWemListener#endPropertyInline(java.lang.String)
86    */
 
87  4 toggle @Override
88    public void endPropertyInline(String inlineProperty)
89    {
90  4 print("</span>");
91    }
92   
93    /**
94    * Returns an HTML/XML entity corresponding to the specified special symbol.
95    * Depending on implementation it can be real entities (like &amp;amp;
96    * &amp;lt; &amp;gt; or the corresponding digital codes (like &amp;#38;,
97    * &amp;#&amp;#38; or &amp;#8250;). Digital entity representation is better
98    * for generation of XML files.
99    *
100    * @param str the special string to convert to an HTML/XML entity
101    * @return an HTML/XML entity corresponding to the specified special symbol.
102    */
 
103  599 toggle protected String getSymbolEntity(String str)
104    {
105  599 String entity = null;
106  599 if (isHtmlEntities()) {
107  599 entity = WikiEntityUtil.getHtmlSymbol(str);
108    } else {
109  0 int code = WikiEntityUtil.getHtmlCodeByWikiSymbol(str);
110  0 if (code > 0) {
111  0 entity = "#" + Integer.toString(code);
112    }
113    }
114  599 if (entity != null) {
115  6 entity = "&" + entity + ";";
116  6 if (str.startsWith(" --")) {
117  0 entity = "&#160;" + entity + " ";
118    }
119    }
120  599 return entity;
121    }
122   
123    /**
124    * Returns <code>true</code> if special Wiki entities should be represented
125    * as the corresponding HTML entities or they should be visualized using the
126    * corresponding XHTML codes (like &amp;amp; and so on). This method can be
127    * overloaded in subclasses to re-define the visualization style.
128    *
129    * @return <code>true</code> if special Wiki entities should be represented
130    * as the corresponding HTML entities or they should be visualized
131    * using the corresponding XHTML codes (like &amp;amp; and so on).
132    */
 
133  599 toggle protected boolean isHtmlEntities()
134    {
135  599 return true;
136    }
137   
 
138  1341 toggle @Override
139    protected ReferenceHandler newReferenceHandler()
140    {
141  1341 return new ReferenceHandler(isSupportImage(), isSupportDownload())
142    {
 
143  1 toggle @Override
144    protected void handleImage(
145    String ref,
146    String label,
147    WikiParameters params)
148    {
149  1 print("<img src='"
150    + WikiPageUtil.escapeXmlAttribute(ref)
151    + "'"
152    + params
153    + "/>");
154    }
155   
 
156  125 toggle @Override
157    protected void handleReference(
158    String ref,
159    String label,
160    WikiParameters params)
161    {
162  125 print("<a href='"
163    + WikiPageUtil.escapeXmlAttribute(ref)
164    + "'"
165    + params
166    + ">"
167    + WikiPageUtil.escapeXmlString(label)
168    + "</a>");
169    }
170    };
171    }
172   
173    /**
174    * @see org.xwiki.rendering.wikimodel.IWemListener#onEscape(java.lang.String)
175    */
 
176  20 toggle @Override
177    public void onEscape(String str)
178    {
179  20 print("<span class='wikimodel-escaped'>"
180    + WikiPageUtil.escapeXmlString(str)
181    + "</span>");
182    }
183   
 
184  6 toggle @Override
185    public void onExtensionInline(String extensionName, WikiParameters params)
186    {
187  6 print("<span class='wikimodel-extension' extension='"
188    + extensionName
189    + "'"
190    + params
191    + "/>");
192    }
193   
194    /**
195    * @see org.xwiki.rendering.wikimodel.IWemListener#onLineBreak()
196    */
 
197  8 toggle @Override
198    public void onLineBreak()
199    {
200  8 print("<br />");
201    }
202   
203    /**
204    * @see org.xwiki.rendering.wikimodel.IWemListener#onSpecialSymbol(java.lang.String)
205    */
 
206  599 toggle @Override
207    public void onSpecialSymbol(String str)
208    {
209  599 String entity = getSymbolEntity(str);
210  599 if (entity == null) {
211  593 entity = WikiPageUtil.escapeXmlString(str);
212    }
213  599 print(entity);
214    }
215   
216    /**
217    * @see org.xwiki.rendering.wikimodel.IWemListener#onVerbatimInline(java.lang.String,
218    * WikiParameters)
219    */
 
220  59 toggle @Override
221    public void onVerbatimInline(String str, WikiParameters params)
222    {
223  59 print("<tt class=\"wikimodel-verbatim\""
224    + params
225    + ">"
226    + WikiPageUtil.escapeXmlString(str)
227    + "</tt>");
228    }
229    }