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

File EmptyAttributeFilter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

2
6
1
1
66
33
3
0.5
6
1
3

Classes

Class Line # Actions
EmptyAttributeFilter 45 6 0% 3 4
0.555555655.6%
 

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.Map;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27    import javax.xml.transform.TransformerException;
28   
29    import org.apache.xpath.XPathAPI;
30    import org.slf4j.Logger;
31    import org.w3c.dom.Attr;
32    import org.w3c.dom.Document;
33    import org.w3c.dom.NodeList;
34    import org.xwiki.component.annotation.Component;
35   
36    /**
37    * Removes attributes with no value. Precisely, elements like {@code <span style="" title="Title">text</span>} are
38    * transformed into {@code <span title="Title">text</span>}.
39    *
40    * @version $Id: 2b4a52020f6f86966634a62ecd52aba36947ebe9 $
41    */
42    @Component(roles = { HTMLFilter.class })
43    @Named("emptyAttribute")
44    @Singleton
 
45    public class EmptyAttributeFilter extends AbstractHTMLFilter
46    {
47    /**
48    * Logger.
49    */
50    @Inject
51    private Logger logger;
52   
 
53  13 toggle @Override
54    public void filter(Document document, Map<String, String> parameters)
55    {
56  13 try {
57  13 NodeList emptyAttributes = XPathAPI.selectNodeList(document, "//@*[. = '']");
58  13 for (int i = emptyAttributes.getLength() - 1; i >= 0; i--) {
59  0 Attr emptyAttribute = (Attr) emptyAttributes.item(i);
60  0 emptyAttribute.getOwnerElement().removeAttributeNode(emptyAttribute);
61    }
62    } catch (TransformerException e) {
63  0 logger.error("Exception while filtering empty attributes.", e);
64    }
65    }
66    }