| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ReplacerFactory |
|
| 1.0;1 | ||||
| ReplacerFactory$1 |
|
| 1.0;1 | ||||
| ReplacerFactory$Replacer |
|
| 1.0;1 |
| 1 | package org.jtheque.primary.utils.web.analyzers.generic.transform; | |
| 2 | ||
| 3 | /* | |
| 4 | * This file is part of JTheque. | |
| 5 | * | |
| 6 | * JTheque is free software: you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation, either version 3 of the License. | |
| 9 | * | |
| 10 | * JTheque 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 | |
| 13 | * GNU General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU General Public License | |
| 16 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 17 | */ | |
| 18 | ||
| 19 | import org.jdom.Element; | |
| 20 | import org.jtheque.core.utils.file.XMLException; | |
| 21 | import org.jtheque.core.utils.file.XMLReader; | |
| 22 | import org.jtheque.primary.utils.web.analyzers.generic.Factory; | |
| 23 | ||
| 24 | /** | |
| 25 | * A factory for replacer objects. | |
| 26 | * | |
| 27 | * @author Baptiste Wicht | |
| 28 | */ | |
| 29 | 0 | final class ReplacerFactory implements Factory<Transformer> { |
| 30 | @Override | |
| 31 | public boolean canFactor(Element element, XMLReader reader){ | |
| 32 | 0 | return "replacer".equals(element.getName()); |
| 33 | } | |
| 34 | ||
| 35 | @Override | |
| 36 | public Transformer factor(Element n, XMLReader reader) throws XMLException{ | |
| 37 | 0 | return new Replacer(reader.readString("from", n), reader.readString("to", n)); |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * A Transformer who replace all the occurrences of a char sequence with an another. | |
| 42 | * | |
| 43 | * @author Baptiste Wicht | |
| 44 | */ | |
| 45 | 0 | private static final class Replacer implements Transformer { |
| 46 | private final String from; | |
| 47 | private final String to; | |
| 48 | ||
| 49 | /** | |
| 50 | * Construct a new Replacer. | |
| 51 | * | |
| 52 | * @param from The char sequence to replace. | |
| 53 | * @param to The char to replace with. | |
| 54 | */ | |
| 55 | private Replacer(String from, String to){ | |
| 56 | 0 | super(); |
| 57 | ||
| 58 | 0 | this.from = from; |
| 59 | 0 | this.to = to; |
| 60 | 0 | } |
| 61 | ||
| 62 | @Override | |
| 63 | public String transform(String value){ | |
| 64 | 0 | return value.replace(from, to); |
| 65 | } | |
| 66 | ||
| 67 | @Override | |
| 68 | public String toString(){ | |
| 69 | 0 | return "Replacer{" + |
| 70 | "from='" + from + '\'' + | |
| 71 | ", to='" + to + '\'' + | |
| 72 | '}'; | |
| 73 | } | |
| 74 | } | |
| 75 | } |