1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.officeimporter.internal.filter

File ListFilter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

8
13
1
1
72
38
5
0.38
13
1
5

Classes

Class Line # Actions
ListFilter 49 13 0% 5 5
0.7727272577.3%
 

Contributing tests

This file is covered by 20 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.officeimporter.internal.filter;
21   
22    import java.util.List;
23    import java.util.Map;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.apache.commons.lang3.StringUtils;
29    import org.w3c.dom.Document;
30    import org.w3c.dom.Element;
31    import org.w3c.dom.Node;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.xml.html.filter.AbstractHTMLFilter;
34   
35    /**
36    * <p>
37    * This filter includes a temporary fix for the JIRA: http://jira.xwiki.org/jira/browse/XWIKI-3262
38    * </p>
39    * <p>
40    * Removes isolated paragraph items from list items.
41    * </p>
42    *
43    * @version $Id: 5055065a12d65794a9da263d060c524d7bafc047 $
44    * @since 1.8M1
45    */
46    @Component
47    @Named("officeimporter/list")
48    @Singleton
 
49    public class ListFilter extends AbstractHTMLFilter
50    {
 
51  66 toggle @Override
52    public void filter(Document document, Map<String, String> cleaningParams)
53    {
54  66 List<Element> listItems = filterDescendants(document.getDocumentElement(), new String[] {TAG_LI});
55  66 for (Element listItem : listItems) {
56  10 Node nextChild = listItem.getFirstChild();
57  10 while (nextChild != null) {
58  10 if (nextChild.getNodeType() == Node.TEXT_NODE) {
59  9 String trimmed = StringUtils.stripStart(nextChild.getTextContent(), WHITE_SPACE_CHARS);
60  9 nextChild.setTextContent(trimmed);
61  9 if (trimmed.equals("")) {
62  0 nextChild = nextChild.getNextSibling();
63  0 continue;
64    }
65  1 } else if (nextChild.getNodeName().equals(TAG_P)) {
66  1 replaceWithChildren((Element) nextChild);
67    }
68  10 break;
69    }
70    }
71    }
72    }