1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jetspeed.capabilities.impl;
19
20 import java.util.Map;
21 import java.util.Iterator;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import org.apache.jetspeed.capabilities.Capabilities;
27 import org.apache.jetspeed.capabilities.CapabilityMap;
28 import org.apache.jetspeed.capabilities.MediaType;
29 import org.apache.jetspeed.capabilities.Client;
30 import org.apache.jetspeed.pipeline.PipelineException;
31 import org.apache.jetspeed.pipeline.valve.AbstractValve;
32 import org.apache.jetspeed.pipeline.valve.ValveContext;
33 import org.apache.jetspeed.request.RequestContext;
34
35 /***
36 * Invokes the capability customizer in the request pipeline
37 *
38 * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
39 * @version $Id: CapabilityCustomizerValveImpl.java 517719 2007-03-13 15:05:48Z ate $
40 */
41 public class CapabilityCustomizerValveImpl extends AbstractValve
42 {
43
44 private static final Log log = LogFactory.getLog(CapabilityCustomizerValveImpl.class);
45
46 private Capabilities capabilities;
47 private Map clientToMediaTypeMap;
48
49 public CapabilityCustomizerValveImpl( Capabilities capabilities, Map clientToMediaTypeMap )
50 {
51 this.capabilities = capabilities;
52 this.clientToMediaTypeMap = clientToMediaTypeMap;
53 }
54
55 /***
56 * Initialize the valve before using in a pipeline.
57 */
58 public void initialize() throws PipelineException
59 {
60
61 }
62
63 public void invoke( RequestContext request, ValveContext context ) throws PipelineException
64 {
65 CapabilityMap cm = request.getCapabilityMap();
66
67 if (cm != null && this.clientToMediaTypeMap != null)
68 {
69 Client client = cm.getClient();
70 String mediaTypeName = (String) this.clientToMediaTypeMap.get(client.getName());
71
72 if (mediaTypeName != null)
73 {
74 MediaType mediaType = this.capabilities.getMediaType(mediaTypeName);
75 cm.setPreferredMediaType(mediaType);
76 request.setMediaType(mediaTypeName);
77 }
78 }
79
80
81 context.invokeNext(request);
82 }
83
84 public String toString()
85 {
86 return "CapabilityCustomizerValveImpl";
87 }
88 }