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

File AccumulationXMLFilter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% 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 322 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  437 toggle public AccumulationXMLFilter(XMLReader reader)
46    {
47  437 super(reader);
48    }
49   
50    /**
51    * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
52    */
 
53  2969 toggle @Override
54    public void characters(char[] array, int start, int length)
55    throws SAXException
56    {
57  2969 if (fAccumulationBuffer != null) {
58  2969 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  4800 toggle @Override
67    public void startElement(
68    String uri,
69    String localName,
70    String qName,
71    Attributes attributes) throws SAXException
72    {
73  4800 flushAccumulationBuffer();
74  4800 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  4794 toggle @Override
82    public void endElement(String uri, String localName, String qName)
83    throws SAXException
84    {
85  4794 flushAccumulationBuffer();
86  4794 super.endElement(uri, localName, qName);
87    }
88   
 
89  257 toggle @Override
90    public void comment(char[] array, int start, int length)
91    throws SAXException
92    {
93  257 flushAccumulationBuffer();
94  257 super.comment(array, start, length);
95    }
96   
 
97  34 toggle @Override
98    public void startCDATA() throws SAXException
99    {
100  34 flushAccumulationBuffer();
101  34 super.startCDATA();
102    }
103   
 
104  34 toggle @Override
105    public void endCDATA() throws SAXException
106    {
107  34 flushAccumulationBuffer();
108  34 super.endCDATA();
109    }
110   
 
111  9919 toggle private void flushAccumulationBuffer() throws SAXException
112    {
113  9919 if (fAccumulationBuffer.length() > 0) {
114  2666 super.characters(
115    fAccumulationBuffer.toString().toCharArray(),
116    0,
117    fAccumulationBuffer.length());
118    }
119  9919 fAccumulationBuffer.setLength(0);
120    }
121    }