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

File AccumulationXMLFilter.java

 

Coverage histogram

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

Code metrics

4
17
9
1
121
70
11
0.65
1.89
9
1.22

Classes

Class Line # Actions
AccumulationXMLFilter 36 17 0% 11 3
0.990%
 

Contributing tests

This file is covered by 351 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.filter;
21   
22    import org.xml.sax.Attributes;
23    import org.xml.sax.SAXException;
24    import org.xml.sax.XMLReader;
25   
26    /**
27    * SAX parsers are allowed to call the characters() method several times in a
28    * row. Some parsers have a buffer of 8K (Crimson), others of 16K (Xerces) and
29    * others can even call onCharacters() for every single characters! Thus we need
30    * to accumulate the characters in a buffer before we process them. This filter
31    * does exactly this.
32    *
33    * @version $Id: d83fd2e3d7cfa9895dfda6a6365ac76fcaf2e957 $
34    * @since 4.0M1
35    */
 
36    public class AccumulationXMLFilter extends DefaultXMLFilter
37    {
38    private StringBuffer fAccumulationBuffer = new StringBuffer();
39   
 
40  0 toggle public AccumulationXMLFilter()
41    {
42  0 super();
43    }
44   
 
45  433 toggle public AccumulationXMLFilter(XMLReader reader)
46    {
47  433 super(reader);
48    }
49   
50    /**
51    * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
52    */
 
53  1667 toggle @Override
54    public void characters(char[] array, int start, int length)
55    throws SAXException
56    {
57  1667 if (fAccumulationBuffer != null) {
58  1667 fAccumulationBuffer.append(array, start, length);
59    }
60    }
61   
62    /**
63    * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
64    * java.lang.String, java.lang.String, org.xml.sax.Attributes)
65    */
 
66  2340 toggle @Override
67    public void startElement(
68    String uri,
69    String localName,
70    String qName,
71    Attributes attributes) throws SAXException
72    {
73  2340 flushAccumulationBuffer();
74  2340 super.startElement(uri, localName, qName, attributes);
75    }
76   
77    /**
78    * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String,
79    * java.lang.String, java.lang.String)
80    */
 
81  2340 toggle @Override
82    public void endElement(String uri, String localName, String qName)
83    throws SAXException
84    {
85  2340 flushAccumulationBuffer();
86  2340 super.endElement(uri, localName, qName);
87    }
88   
 
89  303 toggle @Override
90    public void comment(char[] array, int start, int length)
91    throws SAXException
92    {
93  303 flushAccumulationBuffer();
94  303 super.comment(array, start, length);
95    }
96   
 
97  3 toggle @Override
98    public void startCDATA() throws SAXException
99    {
100  3 flushAccumulationBuffer();
101  3 super.startCDATA();
102    }
103   
 
104  3 toggle @Override
105    public void endCDATA() throws SAXException
106    {
107  3 flushAccumulationBuffer();
108  3 super.endCDATA();
109    }
110   
 
111  4989 toggle private void flushAccumulationBuffer() throws SAXException
112    {
113  4989 if (fAccumulationBuffer.length() > 0) {
114  1428 super.characters(
115    fAccumulationBuffer.toString().toCharArray(),
116    0,
117    fAccumulationBuffer.length());
118    }
119  4989 fAccumulationBuffer.setLength(0);
120    }
121    }