Project

General

Profile

Download (1.5 KB) Statistics
| Branch: | Tag: | Revision:
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
public class DefaultRelatedPageConverter implements ConfigurableCustomConverter  {
19

    
20
	private String relatedPagePrefix = "/";
21

    
22
	public void setRelatedPagePrefix(String relatedPagePrefix) {
23
		this.relatedPagePrefix = relatedPagePrefix;
24
	}
25

    
26
	String parameter = null;
27

    
28
	@Override
29
	public void setParameter(String parameter) {
30
		this.parameter = parameter;
31
	}
32

    
33
	@Override
34
    public Object convert(Object existingDestinationFieldValue,	Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) {
35
		if(sourceFieldValue == null) {
36
			return null;
37
		}
38
		StringBuffer stringBuffer = new StringBuffer();
39

    
40
		stringBuffer.append(relatedPagePrefix);
41

    
42
		stringBuffer.append(parameter + "/");
43
		stringBuffer.append(((UUID)sourceFieldValue).toString());
44

    
45
		Relation relation = new Relation();
46
		try {
47
			relation.setResource(new URI(stringBuffer.toString()));
48
		} catch (URISyntaxException e) {
49
			// TODO Auto-generated catch block
50
			e.printStackTrace();
51
		}
52
		return relation;
53
	}
54

    
55
}
(2-2/11)