1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.transport.http;
18
19 import java.io.File;
20 import java.net.URI;
21 import java.net.URISyntaxException;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import javax.xml.transform.Source;
25 import javax.xml.transform.Transformer;
26 import javax.xml.transform.dom.DOMSource;
27 import javax.xml.transform.stream.StreamResult;
28
29 import org.w3c.dom.Document;
30
31 import org.springframework.util.StringUtils;
32 import org.springframework.web.servlet.HandlerAdapter;
33 import org.springframework.web.servlet.ModelAndView;
34 import org.springframework.xml.transform.TransformerObjectSupport;
35 import org.springframework.xml.transform.TraxUtils;
36 import org.springframework.xml.xsd.XsdSchema;
37
38
39
40
41
42
43
44
45
46
47
48
49 public class XsdSchemaHandlerAdapter extends TransformerObjectSupport implements HandlerAdapter {
50
51 private static final String CONTENT_TYPE = "text/xml";
52
53 public boolean supports(Object handler) {
54 return handler instanceof XsdSchema;
55 }
56
57 public long getLastModified(HttpServletRequest request, Object handler) {
58 Source schemaSource = ((XsdSchema) handler).getSource();
59 return LastModifiedHelper.getLastModified(schemaSource);
60 }
61
62 public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
63 throws Exception {
64 if (HttpTransportConstants.METHOD_GET.equals(request.getMethod())) {
65 response.setContentType(CONTENT_TYPE);
66 Transformer transformer = createTransformer();
67 Source schemaSource = getSchemaSource((XsdSchema) handler);
68 StreamResult responseResult = new StreamResult(response.getOutputStream());
69 transformer.transform(schemaSource, responseResult);
70 }
71 else {
72 response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
73 }
74 return null;
75 }
76
77
78
79
80
81
82
83
84
85
86
87 protected Source getSchemaSource(XsdSchema schema) throws Exception {
88 return schema.getSource();
89 }
90
91 }