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

File EmptyLineFilter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

6
11
1
1
63
34
4
0.36
11
1
4

Classes

Class Line # Actions
EmptyLineFilter 43 11 0% 4 7
0.611111161.1%
 

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    * Converts empty paragraphs to empty lines. Precisely, converts all {@code <p>
36    * </p>} to {@code <div class="wikimodel-emptyline"></div>}.
37    *
38    * @version $Id: 0ca573dabb63d83303bb91284cbcaad1e9eae3da $
39    */
40    @Component(roles = {HTMLFilter.class })
41    @Named("emptyLine")
42    @Singleton
 
43    public class EmptyLineFilter extends AbstractHTMLFilter
44    {
 
45  13 toggle @Override
46    public void filter(Document document, Map<String, String> parameters)
47    {
48  13 NodeList paragraphs = document.getElementsByTagName("p");
49  13 List<Element> emptyParagraphs = new ArrayList<Element>();
50  16 for (int i = 0; i < paragraphs.getLength(); i++) {
51  3 Element paragraph = (Element) paragraphs.item(i);
52  3 if (!paragraph.hasChildNodes()) {
53  0 emptyParagraphs.add(paragraph);
54    }
55    }
56  13 for (int i = 0; i < emptyParagraphs.size(); i++) {
57  0 Element div = document.createElement("div");
58  0 div.setAttribute("class", "wikimodel-emptyline");
59  0 Element paragraph = emptyParagraphs.get(i);
60  0 paragraph.getParentNode().replaceChild(div, paragraph);
61    }
62    }
63    }