1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.htmlcleaner

File TrimAttributeTagTransformation.java

 

Coverage histogram

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

Code metrics

2
8
2
1
69
23
4
0.5
4
2
2

Classes

Class Line # Actions
TrimAttributeTagTransformation 40 8 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 106 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.htmlcleaner;
21   
22    import java.util.HashSet;
23    import java.util.Map;
24   
25    import org.xwiki.stability.Unstable;
26   
27    /**
28    * This class allows to transform all tags attribute to trim their value from leading space, except for input value.
29    * It applies the original tag transformations, and then iterates over the attributes to remove the leading spaces.
30    * This class aims at being deleted once HtmlCleaner offers a way to have a better control over trimAttribute flag,
31    * see: https://sourceforge.net/p/htmlcleaner/bugs/213/.
32    *
33    * Note: Even though in a public package this code is not meant to be a public API. We've had to put in under the {@code
34    * org.htmlcleaner} package because we use the following package protected API: TagTransformation#getSourceTag().
35    *
36    * @version $Id: 33f33f2587368b60581c06d5ffb50cea52ba8cd6 $
37    * @since 11.1RC1
38    */
39    @Unstable
 
40    public class TrimAttributeTagTransformation extends TagTransformation
41    {
42    /**
43    * Create a {@link TagTransformation} from source tag to target tag. This kind of transformation always preserve
44    * the attributes.
45    * @param sourceTag Name of the tag to be transformed.
46    * @param destTag Name of tag to which source tag is to be transformed.
47    */
 
48  62840 toggle public TrimAttributeTagTransformation(String sourceTag, String destTag) {
49  62841 super(sourceTag, destTag);
50    }
51   
 
52  172844 toggle @Override
53    public Map<String, String> applyTagTransformations(Map<String, String> attributes) {
54  172844 Map<String, String> result = super.applyTagTransformations(attributes);
55   
56  172844 for (Map.Entry<String, String> attributesEntry : new HashSet<>(result.entrySet())) {
57  242156 String attrName = attributesEntry.getKey();
58  242156 String attrValue = attributesEntry.getValue();
59   
60    // we don't want to trim spaces for input value attribute
61    // this is the only reason of this class existence.
62  242156 if (!(getSourceTag().equals("input") && attrName.equals("value"))) {
63  231763 result.put(attrName, attrValue.trim());
64    }
65    }
66   
67  172844 return result;
68    }
69    }