1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 * 9 * http://www.apache.org/licenses/LICENSE-2.010 * 11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */1718packageorg.apache.jetspeed.capabilities.impl;
1920import java.util.Map;
21import java.util.Iterator;
2223import org.apache.commons.logging.Log;
24import org.apache.commons.logging.LogFactory;
2526import org.apache.jetspeed.capabilities.Capabilities;
27import org.apache.jetspeed.capabilities.CapabilityMap;
28import org.apache.jetspeed.capabilities.MediaType;
29import org.apache.jetspeed.capabilities.Client;
30import org.apache.jetspeed.pipeline.PipelineException;
31import org.apache.jetspeed.pipeline.valve.AbstractValve;
32import org.apache.jetspeed.pipeline.valve.ValveContext;
33import org.apache.jetspeed.request.RequestContext;
3435/***36 * Invokes the capability customizer in the request pipeline37 * 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 */41publicclassCapabilityCustomizerValveImplextendsAbstractValve42 {
4344privatestaticfinal Log log = LogFactory.getLog(CapabilityCustomizerValveImpl.class);
4546private Capabilities capabilities;
47private Map clientToMediaTypeMap;
4849publicCapabilityCustomizerValveImpl( Capabilities capabilities, Map clientToMediaTypeMap )
50 {
51this.capabilities = capabilities;
52this.clientToMediaTypeMap = clientToMediaTypeMap;
53 }
5455/***56 * Initialize the valve before using in a pipeline.57 */58publicvoid initialize() throws PipelineException
59 {
6061 }
6263publicvoid invoke( RequestContext request, ValveContext context ) throws PipelineException
64 {
65 CapabilityMap cm = request.getCapabilityMap();
6667if (cm != null && this.clientToMediaTypeMap != null)
68 {
69 Client client = cm.getClient();
70 String mediaTypeName = (String) this.clientToMediaTypeMap.get(client.getName());
7172if (mediaTypeName != null)
73 {
74 MediaType mediaType = this.capabilities.getMediaType(mediaTypeName);
75 cm.setPreferredMediaType(mediaType);
76 request.setMediaType(mediaTypeName);
77 }
78 }
7980// Pass control to the next Valve in the Pipeline81 context.invokeNext(request);
82 }
8384public String toString()
85 {
86return"CapabilityCustomizerValveImpl";
87 }
88 }