Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
RequestUtils |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright 2004-2009 the Seasar Foundation and the Others. | |
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, | |
13 | * either express or implied. See the License for the specific language | |
14 | * governing permissions and limitations under the License. | |
15 | */ | |
16 | package org.seasar.cubby.internal.util; | |
17 | ||
18 | import javax.servlet.ServletRequest; | |
19 | import javax.servlet.http.HttpServletRequest; | |
20 | ||
21 | /** | |
22 | * サーブレット要求をに対するユーティリティクラスです。 | |
23 | * | |
24 | * @author baba | |
25 | * @since 2.0.0 | |
26 | */ | |
27 | 0 | public class RequestUtils { |
28 | ||
29 | /** | |
30 | * リクエストの URI からコンテキストパスを除いたパスを返します。 | |
31 | * | |
32 | * @param request | |
33 | * リクエスト | |
34 | * @return コンテキストパスを除いたパス | |
35 | */ | |
36 | public static String getPath(final HttpServletRequest request) { | |
37 | 3 | final StringBuilder builder = new StringBuilder(); |
38 | 3 | builder.append(request.getServletPath()); |
39 | 3 | final String pathInfo = request.getPathInfo(); |
40 | 3 | if (pathInfo != null) { |
41 | 3 | builder.append(pathInfo); |
42 | } | |
43 | 3 | return builder.toString(); |
44 | } | |
45 | ||
46 | /** | |
47 | * リクエストから属性を取得します。 | |
48 | * | |
49 | * @param <T> | |
50 | * 取得する属性の型 | |
51 | * @param request | |
52 | * 要求 | |
53 | * @param name | |
54 | * 属性名 | |
55 | * @return 属性 | |
56 | * @since 1.1.0 | |
57 | */ | |
58 | @SuppressWarnings("unchecked") | |
59 | public static <T> T getAttribute(final ServletRequest request, | |
60 | final String name) { | |
61 | 8 | return (T) request.getAttribute(name); |
62 | } | |
63 | ||
64 | } |