Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   76   4   5.5
4   40   0.36   2
2     2  
1    
 
  UnescapeFilter       Line # 43 11 0% 4 0 100% 1.0
 
  (92)
 
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.internal.parser.xwiki10;
21   
22    import java.util.regex.Matcher;
23    import java.util.regex.Pattern;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.phase.Initializable;
30    import org.xwiki.component.phase.InitializationException;
31    import org.xwiki.rendering.parser.xwiki10.AbstractFilter;
32    import org.xwiki.rendering.parser.xwiki10.FilterContext;
33   
34    /**
35    * Restore protected escaped characters.
36    *
37    * @version $Id: b1b57eb57809abd46757f574d47b697afe6cd2dd $
38    * @since 1.9M2
39    */
40    @Component
41    @Named("unescape")
42    @Singleton
 
43    public class UnescapeFilter extends AbstractFilter implements Initializable
44    {
45    public static final Pattern ESCAPE_SPATTERN =
46    Pattern.compile(FilterContext.XWIKI1020TOKEN_OP + FilterContext.XWIKI1020TOKENI_SF_SPATTERN
47    + EscapeFilter.ESCAPE_SUFFIX + "(\\d+)" + FilterContext.XWIKI1020TOKEN_CP);
48   
 
49  92 toggle @Override
50    public void initialize() throws InitializationException
51    {
52  92 setPriority(1500);
53    }
54   
 
55  95 toggle @Override
56    public String filter(String content, FilterContext filterContext)
57    {
58  95 StringBuffer result = new StringBuffer();
59   
60  95 Matcher matcher = ESCAPE_SPATTERN.matcher(content);
61  95 int currentIndex = 0;
62  111 for (; matcher.find(); currentIndex = matcher.end()) {
63  16 result.append(content.substring(currentIndex, matcher.start()));
64   
65  16 result.append(filterContext.getProtectedContent(Integer.valueOf(matcher.group(1))));
66    }
67   
68  95 if (currentIndex == 0) {
69  88 return content;
70    }
71   
72  7 result.append(content.substring(currentIndex));
73   
74  7 return result.toString();
75    }
76    }