]> git.argeo.org Git - gpl/argeo-slc.git/blob - XsltMarshallerView.java
127188b842a8caf112ea357dc6e18751d4c11eb4
[gpl/argeo-slc.git] / XsltMarshallerView.java
1 package org.argeo.slc.web.mvc;
2
3 import javax.xml.parsers.DocumentBuilderFactory;
4 import javax.xml.transform.Source;
5 import javax.xml.transform.dom.DOMResult;
6 import javax.xml.transform.dom.DOMSource;
7
8 import org.argeo.slc.core.SlcException;
9 import org.springframework.oxm.Marshaller;
10 import org.springframework.web.servlet.view.xslt.XsltView;
11 import org.w3c.dom.Document;
12
13 public class XsltMarshallerView extends XsltView {
14
15 private Marshaller marshaller;
16
17 @Override
18 protected Class<?>[] getSourceTypes() {
19 return new Class[] { Object.class };
20 }
21
22 @Override
23 protected Source convertSource(Object source) throws Exception {
24 Document document = DocumentBuilderFactory.newInstance()
25 .newDocumentBuilder().newDocument();
26 DOMResult result = new DOMResult(document);
27 if (!marshaller.supports(source.getClass()))
28 throw new SlcException("Object of type " + source.getClass()
29 + " not supported.");
30 marshaller.marshal(source, result);
31 return new DOMSource(result.getNode());
32 }
33
34 public void setMarshaller(Marshaller marshaller) {
35 this.marshaller = marshaller;
36 }
37
38 }