Skip to content

Package: XhtmlMarkupSerializer

XhtmlMarkupSerializer

nameinstructionbranchcomplexitylinemethod
XhtmlMarkupSerializer(Writer)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
characters(String)
M: 6 C: 17
74%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 2 C: 6
75%
M: 0 C: 1
100%
characters(char[], int, int)
M: 27 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getEntityRef(int)
M: 0 C: 10
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 1
100%
M: 0 C: 1
100%
shouldOmitCDATA()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.core.impl.util;
28:
29: import java.util.Arrays;
30: import java.io.IOException;
31: import java.io.Writer;
32: import com.sun.org.apache.xml.internal.serialize.OutputFormat;
33: import org.xml.sax.SAXException;
34: import it.tidalwave.northernwind.core.impl.patches.XHTMLSerializer;
35:
36: /***********************************************************************************************************************
37: *
38: * @author Fabrizio Giudici
39: *
40: **********************************************************************************************************************/
41: // FIXME: it makes use of a deprecated class but it's needed by NW-96.
42: public class XhtmlMarkupSerializer extends XHTMLSerializer
43: {
44: private static final OutputFormat outputFormat = new OutputFormat("xhtml", "UTF-8", false);
45:
46: static
47: {
48: outputFormat.setPreserveSpace(true);
49: outputFormat.setOmitXMLDeclaration(true);
50: }
51:
52: public XhtmlMarkupSerializer (final Writer writer)
53: {
54: super(writer, outputFormat);
55: }
56:
57: @Override
58: public void characters (final char[] chars, final int start, final int length)
59: throws SAXException
60: {
61: try
62: {
63:• if (shouldOmitCDATA())
64: {
65: content(); // flushes element start
66: printText(chars, start, length, true, true);
67: }
68: else
69: {
70: super.characters(chars, start, length);
71: }
72: }
73: catch (IOException e)
74: {
75: throw new SAXException(e);
76: }
77: }
78:
79: @Override
80: protected void characters (final String text)
81: {
82: try
83: {
84:• if (shouldOmitCDATA())
85: {
86: content(); // flushes element start
87: printText(text, true, true);
88: }
89: else
90: {
91: super.characters(text);
92: }
93: }
94: catch (IOException e)
95: {
96: throw new RuntimeException(e);
97: }
98: }
99:
100: private boolean shouldOmitCDATA()
101: {
102: return Arrays.asList("script", "style").contains(getElementState().rawName);
103: }
104:
105: @Override
106: protected String getEntityRef (final int ch)
107: {
108:• return ((ch == '\n') || (ch == '\r')) ? "#10" : null;
109: }
110: }