1
|
package eu.etaxonomy.cdm.remote.dto.assembler.converter;
|
2
|
|
3
|
import java.net.URISyntaxException;
|
4
|
import java.util.UUID;
|
5
|
|
6
|
import org.dozer.ConfigurableCustomConverter;
|
7
|
|
8
|
import eu.etaxonomy.cdm.common.URI;
|
9
|
import eu.etaxonomy.cdm.remote.dto.dc.Relation;
|
10
|
|
11
|
/**
|
12
|
* Default page converter implementation that makes a gross assumption that
|
13
|
* the metadata are being served on the same server as the human-readable page,
|
14
|
* and that the urls map to {relatedPagePrefix}{param}/{uuid}
|
15
|
*
|
16
|
* @author ben.clark
|
17
|
*
|
18
|
*/
|
19
|
public class DefaultRelatedPageConverter implements ConfigurableCustomConverter {
|
20
|
|
21
|
private String relatedPagePrefix = "/";
|
22
|
|
23
|
public void setRelatedPagePrefix(String relatedPagePrefix) {
|
24
|
this.relatedPagePrefix = relatedPagePrefix;
|
25
|
}
|
26
|
|
27
|
String parameter = null;
|
28
|
|
29
|
/* (non-Javadoc)
|
30
|
* @see org.dozer.ConfigurableCustomConverter#setParameter(java.lang.String)
|
31
|
*/
|
32
|
@Override
|
33
|
public void setParameter(String parameter) {
|
34
|
this.parameter = parameter;
|
35
|
|
36
|
}
|
37
|
|
38
|
public Object convert(Object existingDestinationFieldValue, Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) {
|
39
|
if(sourceFieldValue == null) {
|
40
|
return null;
|
41
|
}
|
42
|
StringBuffer stringBuffer = new StringBuffer();
|
43
|
|
44
|
stringBuffer.append(relatedPagePrefix);
|
45
|
|
46
|
stringBuffer.append(parameter + "/");
|
47
|
stringBuffer.append(((UUID)sourceFieldValue).toString());
|
48
|
|
49
|
Relation relation = new Relation();
|
50
|
try {
|
51
|
relation.setResource(new URI(stringBuffer.toString()));
|
52
|
} catch (URISyntaxException e) {
|
53
|
// TODO Auto-generated catch block
|
54
|
e.printStackTrace();
|
55
|
}
|
56
|
return relation;
|
57
|
}
|
58
|
|
59
|
}
|