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

File XHTMLWriter.java

 

Coverage histogram

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

Code metrics

0
6
4
1
77
27
4
0.67
1.5
4
1

Classes

Class Line # Actions
XHTMLWriter 33 6 0% 4 0
1.0100%
 

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.xml.internal.renderer.printer;
21   
22    import java.io.Writer;
23   
24    import org.dom4j.io.OutputFormat;
25    import org.dom4j.io.XMLWriter;
26   
27    /**
28    * XHTMLWriter is an helper to configure XMLWriter to format a DOM4J tree as XHTML.
29    *
30    * @version $Id: be308e952d598a5caa183493fa3e7640ebdb718c $
31    * @since 5.2M1
32    */
 
33    public class XHTMLWriter extends XMLWriter
34    {
35    protected static final OutputFormat DEFAULT_XHTML_FORMAT;
36   
 
37  52 toggle static {
38  52 DEFAULT_XHTML_FORMAT = new OutputFormat();
39  52 DEFAULT_XHTML_FORMAT.setXHTML(true);
40    }
41   
 
42  19599 toggle public XHTMLWriter(Writer writer)
43    {
44  19600 super(writer, DEFAULT_XHTML_FORMAT);
45   
46    // escape all non US-ASCII to have as less encoding problems as possible
47  19599 setMaximumAllowedCharacter(-1);
48    }
49   
50    /**
51    * Escapes a string to be used as an attribute value. Unlike the original method in {@link XMLWriter}, apostrophes
52    * are replaced by a numerical entity &, since ' is not valid in HTML documents.
53    *
54    * @param text the attribute value to escape
55    * @return the text with all occurrences of special XML characters replaced by entity references.
56    */
 
57  14452 toggle @Override
58    protected String escapeAttributeEntities(String text)
59    {
60  14452 return super.escapeAttributeEntities(text).replace("'", "&");
61    }
62   
63    /**
64    * Add left curly to the set of characters that should be encoded. This to prepare the generated html for use
65    * between {{html}} {{/html}} in XWiki 2.x syntax. (The literal string '{{/html}}' must not occur in the generated
66    * html.)
67    *
68    * @param c Character to encode.
69    * @return {@code true} if the character should be encoded.
70    */
 
71  566552 toggle @Override
72    protected boolean shouldEncodeChar(char c)
73    {
74  566553 return super.shouldEncodeChar(c) || c == '{';
75    }
76   
77    }