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
19   96   4   9.5
4   56   0.21   2
2     2  
1    
 
  PreFilter       Line # 44 19 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.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.phase.Initializable;
31    import org.xwiki.component.phase.InitializationException;
32    import org.xwiki.rendering.parser.xwiki10.AbstractFilter;
33    import org.xwiki.rendering.parser.xwiki10.Filter;
34    import org.xwiki.rendering.parser.xwiki10.FilterContext;
35    import org.xwiki.rendering.parser.xwiki10.util.CleanUtil;
36   
37    /**
38    * @version $Id: ea6ac4ace6203587fa624fcb0e9fca84b773e095 $
39    * @since 1.8M1
40    */
41    @Component
42    @Named("pre")
43    @Singleton
 
44    public class PreFilter extends AbstractFilter implements Initializable
45    {
46    private static final Pattern PRE_PATTERN =
47    Pattern.compile("\\{pre\\}(.*?)\\{/pre\\}", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
48   
49    @Inject
50    @Named("spacescleanning")
51    public Filter spacesCleaningFilter;
52   
53    @Inject
54    @Named("standalonenewlinecleanning")
55    public Filter standaloneNewLineCleaningFilter;
56   
 
57  92 toggle @Override
58    public void initialize() throws InitializationException
59    {
60  92 setPriority(100);
61    }
62   
 
63  92 toggle @Override
64    public String filter(String content, FilterContext filterContext)
65    {
66  92 StringBuffer result = new StringBuffer();
67   
68  92 Matcher matcher = PRE_PATTERN.matcher(content);
69  92 int currentIndex = 0;
70  95 for (; matcher.find(); currentIndex = matcher.end()) {
71  3 String before = content.substring(currentIndex, matcher.start());
72   
73  3 result.append(before);
74   
75    // print pre
76  3 StringBuffer preBuffer = new StringBuffer();
77   
78  3 preBuffer.append("{{{");
79  3 String preContent = matcher.group(1);
80  3 preContent = this.standaloneNewLineCleaningFilter.filter(preContent, filterContext);
81  3 preContent = this.spacesCleaningFilter.filter(preContent, filterContext);
82  3 preBuffer.append(preContent.trim());
83  3 preBuffer.append("}}}");
84   
85  3 result.append(CleanUtil.extractVelocity(preBuffer, filterContext, true, true));
86    }
87   
88  92 if (currentIndex == 0) {
89  90 return content;
90    }
91   
92  2 result.append(content.substring(currentIndex));
93   
94  2 return result.toString();
95    }
96    }