21
21
22
22
import static org .springframework .http .MediaType .parseMediaType ;
23
23
24
+ import org .commonwl .view .workflow .Workflow ;
25
+ import org .commonwl .view .workflow .WorkflowPermalinkController ;
24
26
import org .springframework .context .annotation .Configuration ;
25
27
import org .springframework .http .MediaType ;
26
28
import org .springframework .web .servlet .config .annotation .ContentNegotiationConfigurer ;
30
32
public class WebConfig extends WebMvcConfigurerAdapter {
31
33
32
34
/**
33
- * Ordered list of formats as presented on Workflow page - must match the
34
- * .mediaType() strings below.
35
+ * Ordered list of formats as presented on Workflow page and supported for
36
+ * content negotiation.
37
+ *
38
+ * @see Workflow#getPermalink(Format)
39
+ * @see WorkflowPermalinkController
35
40
*
36
41
*/
37
- public static enum formats {
38
- html , json , turtle , jsonld , rdfxml , svg , png , dot , zip , ro , yaml , raw
42
+ public static enum Format {
43
+ // Browser
44
+ html (MediaType .TEXT_HTML ),
45
+ // API
46
+ json (MediaType .APPLICATION_JSON ),
47
+ // RDF
48
+ turtle ("text/turtle" ), jsonld ("application/ld+json" ), rdfxml ("application/rdf+xml" ),
49
+ // Images
50
+ svg ("image/svg+xml" ), png (MediaType .IMAGE_PNG ), dot ("text/vnd+graphviz" ),
51
+ // Archives
52
+ zip ("application/zip" ), ro ("application/vnd.wf4ever.robundle+zip" ),
53
+ // raw redirects
54
+ yaml ("text/x-yaml" ), raw (MediaType .APPLICATION_OCTET_STREAM );
55
+
56
+ private final MediaType mediaType ;
57
+
58
+ Format (MediaType mediaType ) {
59
+ this .mediaType = mediaType ;
60
+ }
61
+
62
+ Format (String mediaType ) {
63
+ this .mediaType = parseMediaType (mediaType );
64
+ }
65
+
66
+ public MediaType mediaType () {
67
+ return mediaType ;
68
+ }
39
69
}
40
70
41
71
/**
42
- * Allows the use of the format query parameter to be used
43
- * instead of the Accept HTTP header
72
+ * Allows the use of the format query parameter to be used instead of the Accept
73
+ * HTTP header
44
74
*/
45
75
@ Override
46
76
public void configureContentNegotiation (ContentNegotiationConfigurer configurer ) {
47
- configurer .favorParameter (true )
48
- // Browser
49
- .mediaType ("html" , MediaType .TEXT_HTML )
50
- // API
51
- .mediaType ("json" , MediaType .APPLICATION_JSON )
52
- // RDF
53
- .mediaType ("turtle" , parseMediaType ("text/turtle" ))
54
- .mediaType ("jsonld" , parseMediaType ("application/ld+json" ))
55
- .mediaType ("rdfxml" , parseMediaType ("application/rdf+xml" ))
56
- // Images
57
- .mediaType ("svg" , parseMediaType ("image/svg+xml" ))
58
- .mediaType ("png" , MediaType .IMAGE_PNG )
59
- .mediaType ("dot" , parseMediaType ("text/vnd+graphviz" ))
60
- // Archives
61
- .mediaType ("zip" , parseMediaType ("application/zip" ))
62
- .mediaType ("ro" , parseMediaType ("application/vnd.wf4ever.robundle+zip" ))
63
- // raw redirects
64
- .mediaType ("yaml" , parseMediaType ("text/x-yaml" ))
65
- .mediaType ("raw" , MediaType .APPLICATION_OCTET_STREAM );
77
+ ContentNegotiationConfigurer c = configurer .favorParameter (true );
78
+ for (Format f : Format .values ()) {
79
+ c = c .mediaType (f .name (), f .mediaType ());
80
+ }
66
81
}
67
82
}
0 commit comments