1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
|
10
|
|
11
|
import java.io.IOException;
|
12
|
import java.io.Reader;
|
13
|
import java.io.StringReader;
|
14
|
|
15
|
import org.dozer.CustomConverter;
|
16
|
import org.dozer.MappingException;
|
17
|
|
18
|
|
19
|
public class StripTagsConverter implements CustomConverter {
|
20
|
|
21
|
@Override
|
22
|
public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
|
23
|
if (source == null) {
|
24
|
return null;
|
25
|
}
|
26
|
if (source instanceof String) {
|
27
|
Reader reader = new RemoveHTMLReader(new StringReader((String)source));
|
28
|
StringBuilder stringBuilder = new StringBuilder();
|
29
|
int charValue;
|
30
|
try {
|
31
|
while ((charValue = reader.read()) != -1) {
|
32
|
stringBuilder.append((char)charValue);
|
33
|
}
|
34
|
reader.close();
|
35
|
} catch (IOException e) {return e.toString();}
|
36
|
return stringBuilder.toString();
|
37
|
} else {
|
38
|
throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
|
39
|
+ destination + " and " + source);
|
40
|
}
|
41
|
}
|
42
|
}
|