01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: private static final Log log = LogFactory
44: .getLog(CapabilityCustomizerValveImpl.class);
45:
46: private Capabilities capabilities;
47: private Map clientToMediaTypeMap;
48:
49: public CapabilityCustomizerValveImpl(Capabilities capabilities,
50: Map clientToMediaTypeMap) {
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: public void invoke(RequestContext request, ValveContext context)
63: throws PipelineException {
64: CapabilityMap cm = request.getCapabilityMap();
65:
66: if (cm != null && this .clientToMediaTypeMap != null) {
67: Client client = cm.getClient();
68: String mediaTypeName = (String) this .clientToMediaTypeMap
69: .get(client.getName());
70:
71: if (mediaTypeName != null) {
72: MediaType mediaType = this .capabilities
73: .getMediaType(mediaTypeName);
74: cm.setPreferredMediaType(mediaType);
75: request.setMediaType(mediaTypeName);
76: }
77: }
78:
79: // Pass control to the next Valve in the Pipeline
80: context.invokeNext(request);
81: }
82:
83: public String toString() {
84: return "CapabilityCustomizerValveImpl";
85: }
86: }
|