Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../img/srcFileCovDistChart9.png 55% of files have more coverage
17   121   11   1.89
4   70   0.65   9
9     1.22  
1    
 
  AccumulationXMLFilter       Line # 36 17 0% 11 3 90% 0.9
 
  (219)
 
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  309 toggle public AccumulationXMLFilter(XMLReader reader)
46    {
47  309 super(reader);
48    }
49   
50    /**
51    * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
52    */
 
53  938 toggle @Override
54    public void characters(char[] array, int start, int length)
55    throws SAXException
56    {
57  938 if (fAccumulationBuffer != null) {
58  938 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  1677 toggle @Override
67    public void startElement(
68    String uri,
69    String localName,
70    String qName,
71    Attributes attributes) throws SAXException
72    {
73  1677 flushAccumulationBuffer();
74  1677 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  1677 toggle @Override
82    public void endElement(String uri, String localName, String qName)
83    throws SAXException
84    {
85  1677 flushAccumulationBuffer();
86  1677 super.endElement(uri, localName, qName);
87    }
88   
 
89  205 toggle @Override
90    public void comment(char[] array, int start, int length)
91    throws SAXException
92    {
93  205 flushAccumulationBuffer();
94  205 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  3565 toggle private void flushAccumulationBuffer() throws SAXException
112    {
113  3565 if (fAccumulationBuffer.length() > 0) {
114  852 super.characters(
115    fAccumulationBuffer.toString().toCharArray(),
116    0,
117    fAccumulationBuffer.length());
118    }
119  3565 fAccumulationBuffer.setLength(0);
120    }
121    }