Project

General

Profile

Download (1.9 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id: RdfView.java 7479 2009-11-02 12:31:13Z ben.clark $
2
package eu.etaxonomy.cdm.remote.view;
3

    
4
import java.util.Map;
5

    
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
8
import javax.xml.transform.stream.StreamResult;
9

    
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.oxm.Marshaller;
12
import org.springframework.web.servlet.view.AbstractView;
13

    
14
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
15

    
16
/**
17
 * View class which takes a serializes a cdm object as xml
18
 * @author ben
19
 * @see javax.xml.transform.Source
20
 * @see com.ibm.lsid.MetadataResponse
21
 */
22
public class XmlView extends AbstractView {
23
	
24
	private Marshaller marshaller;
25
	
26
	private boolean locationHeader = false;
27
	
28
	private String locationPrefix = "";
29
	
30
	public void setLocationHeader(boolean locationHeader) {
31
		this.locationHeader = locationHeader;
32
	}
33

    
34
	public void setLocationPrefix(String locationPrefix) {
35
		this.locationPrefix = locationPrefix;
36
	}
37

    
38
	public XmlView() {
39
		
40
	}
41
	
42
	@Autowired
43
	public void setMarshaller(Marshaller marshaller) {
44
		this.marshaller = marshaller;
45
	}
46
	
47
	
48
	
49
	@Override
50
	protected void renderMergedOutputModel(Map model,HttpServletRequest request, HttpServletResponse response)
51
			throws Exception {
52
		
53
		for(Object object : model.values()) {
54
		    if(object instanceof IdentifiableEntity) {		    			    	
55
		        IdentifiableEntity identifiableEntity = (IdentifiableEntity)object;
56
                if(locationHeader) {
57
		    		response.addHeader("Location", locationPrefix + identifiableEntity.getUuid().toString());
58
		    	}
59
		        marshaller.marshal(identifiableEntity, new StreamResult(response.getOutputStream()));
60
		    } else if(object instanceof Throwable) {
61
		    	eu.etaxonomy.cdm.io.jaxb.Error error = new eu.etaxonomy.cdm.io.jaxb.Error((Throwable)object);
62
		    	marshaller.marshal(error, new StreamResult(response.getOutputStream()));
63
		    }
64
		}		
65
	}
66

    
67
}
(8-8/8)