1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wysiwyg.server.internal.cleaner

File LineBreakFilter.java

 

Coverage histogram

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

Code metrics

6
10
2
1
69
37
5
0.5
5
2
2.5

Classes

Class Line # Actions
LineBreakFilter 44 10 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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    package org.xwiki.wysiwyg.server.internal.cleaner;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24    import java.util.Map;
25   
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.w3c.dom.Document;
30    import org.w3c.dom.Element;
31    import org.w3c.dom.NodeList;
32    import org.xwiki.component.annotation.Component;
33   
34    /**
35    * Removes the line breaks that were added by the WYSIWYG editor as spacers. Precisely, it removes all {@code <br
36    * class="spacer"/>}
37    * .
38    *
39    * @version $Id: 045f901763d9598d7fdc445afc7160d28a8bbae6 $
40    */
41    @Component(roles = {HTMLFilter.class })
42    @Named("lineBreak")
43    @Singleton
 
44    public class LineBreakFilter extends AbstractHTMLFilter
45    {
 
46  13 toggle @Override
47    public void filter(Document document, Map<String, String> parameters)
48    {
49  13 NodeList brs = document.getElementsByTagName("br");
50  13 List<Element> emptyLineBRs = new ArrayList<Element>();
51  19 for (int i = 0; i < brs.getLength(); i++) {
52  6 Element br = (Element) brs.item(i);
53  6 if ("spacer".equals(br.getAttribute("class"))) {
54  5 emptyLineBRs.add(br);
55    }
56    }
57  18 for (int i = 0; i < emptyLineBRs.size(); i++) {
58  5 Element br = emptyLineBRs.get(i);
59  5 br.getParentNode().removeChild(br);
60    }
61    }
62   
 
63  13 toggle @Override
64    public int getPriority()
65    {
66    // Make sure this filter is applied before the rest (EmptyLineFilter and StandAloneMacroFilter depend on it).
67  13 return super.getPriority() - 1;
68    }
69    }