View Javadoc
1   /*
2    * Copyright 2002-2013 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.web.socket.adapter.standard;
18  
19  import java.util.List;
20  import java.util.Locale;
21  import java.util.Map;
22  import javax.websocket.Extension;
23  
24  import org.springframework.util.LinkedCaseInsensitiveMap;
25  import org.springframework.web.socket.WebSocketExtension;
26  
27  /**
28   * A sub-class of {@link org.springframework.web.socket.WebSocketExtension} that
29   * can be constructed from an {@link javax.websocket.Extension}.
30   *
31   * @author Rossen Stoyanchev
32   * @since 4.0
33   */
34  public class StandardToWebSocketExtensionAdapter extends WebSocketExtension {
35  
36  
37  	public StandardToWebSocketExtensionAdapter(Extension extension) {
38  		super(extension.getName(), initParameters(extension));
39  	}
40  
41  
42  	private static Map<String, String> initParameters(Extension extension) {
43  		List<Extension.Parameter> parameters = extension.getParameters();
44  		Map<String, String> result = new LinkedCaseInsensitiveMap<String>(parameters.size(), Locale.ENGLISH);
45  		for (Extension.Parameter parameter : parameters) {
46  			result.put(parameter.getName(), parameter.getValue());
47  		}
48  		return result;
49  	}
50  
51  }