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
15   80   5   7.5
6   44   0.33   2
2     2.5  
1    
 
  HrFilter       Line # 42 15 0% 5 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    import org.xwiki.rendering.parser.xwiki10.util.CleanUtil;
34   
35    /**
36    * @version $Id: 0888988bb4c4e4ae524563f2eca0c4f36e249867 $
37    * @since 1.8M1
38    */
39    @Component
40    @Named("hr")
41    @Singleton
 
42    public class HrFilter extends AbstractFilter implements Initializable
43    {
44    private static final Pattern HR_PATTERN = Pattern.compile("(?<=^| )----++(?=$| )", Pattern.MULTILINE);
45   
 
46  92 toggle @Override
47    public void initialize() throws InitializationException
48    {
49  92 setPriority(800);
50    }
51   
 
52  92 toggle @Override
53    public String filter(String content, FilterContext filterContext)
54    {
55  92 StringBuffer result = new StringBuffer();
56   
57  92 String hr20 = filterContext.addProtectedContent("----", false);
58   
59  92 Matcher matcher = HR_PATTERN.matcher(content);
60  92 int currentIndex = 0;
61  94 for (; matcher.find(); currentIndex = matcher.end()) {
62  2 String before = content.substring(currentIndex, matcher.start());
63   
64  2 if (currentIndex > 0) {
65  1 before = CleanUtil.setLeadingNewLines(before, 2);
66    }
67   
68  2 result.append(before);
69  2 result.append(hr20);
70    }
71   
72  92 if (currentIndex == 0) {
73  91 return content;
74    }
75   
76  1 result.append(CleanUtil.setLeadingNewLines(content.substring(currentIndex), 2));
77   
78  1 return result.toString();
79    }
80    }