1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.annotation.internal.content

File AbstractFilterContentAlterer.java

 

Coverage histogram

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

Code metrics

10
20
1
1
78
39
6
0.3
20
1
6

Classes

Class Line # Actions
AbstractFilterContentAlterer 37 20 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 128 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   
21    package org.xwiki.annotation.internal.content;
22   
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.xwiki.annotation.content.AlteredContent;
27    import org.xwiki.annotation.content.filter.Filter;
28   
29    /**
30    * Content alterer to filter out characters which are part of a wiki syntax. This class should be extended to provide
31    * the {@link Filter} used to determine which characters are not meaningful text and should be preserved (not
32    * syntax characters).
33    *
34    * @version $Id: 03041d8c1c35a48aec9c3fd4ee264eb9f398c116 $
35    * @since 2.3M1
36    */
 
37    public abstract class AbstractFilterContentAlterer extends AbstractContentAlterer
38    {
39    /**
40    * @return Syntax filter used to determine the accepted characters in the content altered by this alterer.
41    */
42    protected abstract Filter getFilter();
43   
 
44  254 toggle @Override
45    public AlteredContent alter(CharSequence sequence)
46    {
47  254 StringBuffer buffer = new StringBuffer();
48  254 Map<Integer, Integer> initialToAltered = new HashMap<Integer, Integer>();
49  254 Map<Integer, Integer> alteredToInitial = new HashMap<Integer, Integer>();
50   
51    // index altered
52  254 int j = 0;
53    // number of refused chars
54  254 int z = 0;
55  254 Character c;
56  76983 for (int i = 0; i < sequence.length(); ++i) {
57  76729 c = sequence.charAt(i);
58  76729 if (getFilter().accept(c)) {
59  73178 buffer.append(c);
60  149852 for (int t = 0; t <= z; ++t) {
61    // 1+0;1 // 1+1;1
62  76674 initialToAltered.put(i - t, j);
63    }
64  73178 alteredToInitial.put(j, i);
65  73178 ++j;
66  73178 z = 0;
67    } else {
68  3551 z++;
69    }
70    }
71  254 if (j != 0) {
72  261 for (int t = 0; t < z; ++t) {
73  23 initialToAltered.put(sequence.length() - 1 - t, j - 1);
74    }
75    }
76  254 return new OffsetsMapAlteredContent(buffer.toString(), sequence.length(), initialToAltered, alteredToInitial);
77    }
78    }