Clover coverage report - brownies library - 1.0-beta-1 Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00 FRAMES NO FRAMES |
file stats: | LOC: | 172 |  | Methods: | 11
| NCLOC: | 127 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
ServletUtils.java | 0% | 0% | 0% | 0% |

1 |  |
     /*
2 |  |
      * Joey and its relative products are published under the terms
3 |  |
      * of the Apache Software License.
4 |  |
      */
5 |  |
     package org.asyrinx.brownie.servlet;
6 |  |
7 |  |
     import java.util.Enumeration;
8 |  |
     import java.util.HashMap;
9 |  |
     import java.util.Map;
10 |  |
11 |  |
     import javax.servlet.ServletConfig;
12 |  |
     import javax.servlet.ServletContext;
13 |  |
     import javax.servlet.http.HttpServletRequest;
14 |  |
     import javax.servlet.http.HttpServletResponse;
15 |  |
     import javax.servlet.http.HttpSession;
16 |  |
17 |  |
     import org.asyrinx.brownie.core.lang.ArrayUtils;
18 |  |
     import org.asyrinx.brownie.core.lang.StringUtils;
19 |  |
20 |  |
     /**
21 |  |
      * @author Akima
22 |  |
      */
23 |  |
     public final class ServletUtils {
24 |  |
25 |  |
         /**
26 |  |
          * Constructor for ServletUtils.
27 |  |
          */
28 | 0 |
         private ServletUtils() {
29 | 0 |
             super();
30 |  |
         }
31 |  |
32 | 0 |
         static public Map parametersToMap(ServletConfig config) {
33 | 0 |
             final Map result = new HashMap();
34 | 0 |
             final Enumeration enum = config.getInitParameterNames();
35 | 0 |
             while (enum.hasMoreElements()) {
36 | 0 |
                 String key = (String) enum.nextElement();
37 | 0 |
                 result.put(key, config.getInitParameter(key));
38 |  |
             }
39 | 0 |
             return result;
40 |  |
         }
41 |  |
42 | 0 |
         static public Map parametersToMap(ServletContext context) {
43 | 0 |
             final Map result = new HashMap();
44 | 0 |
             final Enumeration enum = context.getInitParameterNames();
45 | 0 |
             while (enum.hasMoreElements()) {
46 | 0 |
                 String key = (String) enum.nextElement();
47 | 0 |
                 result.put(key, context.getInitParameter(key));
48 |  |
             }
49 | 0 |
             return result;
50 |  |
         }
51 |  |
52 | 0 |
         static public Map attributesToMap(ServletContext context) {
53 | 0 |
             final Map result = new HashMap();
54 | 0 |
             final Enumeration enum = context.getAttributeNames();
55 | 0 |
             while (enum.hasMoreElements()) {
56 | 0 |
                 String key = (String) enum.nextElement();
57 | 0 |
                 result.put(key, context.getAttribute(key));
58 |  |
             }
59 | 0 |
             return result;
60 |  |
         }
61 |  |
62 | 0 |
         static public Map attributesToMap(HttpSession session) {
63 | 0 |
             final Map result = new HashMap();
64 | 0 |
             final Enumeration enum = session.getAttributeNames();
65 | 0 |
             while (enum.hasMoreElements()) {
66 | 0 |
                 String key = (String) enum.nextElement();
67 | 0 |
                 result.put(key, session.getAttribute(key));
68 |  |
             }
69 | 0 |
             return result;
70 |  |
         }
71 |  |
72 | 0 |
         static public Map attributesToMap(HttpServletRequest req) {
73 | 0 |
             final Map result = new HashMap();
74 | 0 |
             final Enumeration enum = req.getAttributeNames();
75 | 0 |
             while (enum.hasMoreElements()) {
76 | 0 |
                 String key = (String) enum.nextElement();
77 | 0 |
                 result.put(key, req.getAttribute(key));
78 |  |
             }
79 | 0 |
             return result;
80 |  |
         }
81 |  |
82 | 0 |
         static public Map parametersToMap(HttpServletRequest req) {
83 | 0 |
             final Map result = new HashMap();
84 | 0 |
             final Enumeration enum = req.getParameterNames();
85 | 0 |
             while (enum.hasMoreElements()) {
86 | 0 |
                 String key = (String) enum.nextElement();
87 | 0 |
                 String data = req.getParameter(key);
88 | 0 |
                 result.put(key, data);
89 |  |
             }
90 | 0 |
             return result;
91 |  |
         }
92 |  |
93 | 0 |
         static public Map headerToMap(HttpServletRequest req) {
94 | 0 |
             final Map result = new HashMap();
95 | 0 |
             final Enumeration enum = req.getHeaderNames();
96 | 0 |
             while (enum.hasMoreElements()) {
97 | 0 |
                 String key = (String) enum.nextElement();
98 | 0 |
                 String data = req.getHeader(key);
99 | 0 |
                 result.put(key, data);
100 |  |
             }
101 | 0 |
             return result;
102 |  |
         }
103 |  |
104 | 0 |
         static public String reqToStr(HttpServletRequest req) {
105 | 0 |
             final StringBuffer result = new StringBuffer();
106 | 0 |
             result.append("\nUri=" + req.getRequestURI());
107 | 0 |
             result.append("\nMethod=" + req.getMethod());
108 | 0 |
             result.append("\nParameters=" + parametersToMap(req));
109 | 0 |
             result.append("\nAttributes=" + attributesToMap(req));
110 | 0 |
             result.append("\nQueryString=" + req.getQueryString());
111 | 0 |
             result.append("\nHeaders=" + headerToMap(req));
112 | 0 |
             result.append("\nPathInfo=" + req.getPathInfo());
113 | 0 |
             result.append("\nPathTranslated=" + req.getPathTranslated());
114 | 0 |
             result.append("\nRequestedSessionId=" + req.getRequestedSessionId());
115 | 0 |
             result.append("\nRemoteAddr=" + req.getRemoteAddr());
116 | 0 |
             result.append("\nRemoteHost=" + req.getRemoteHost());
117 | 0 |
             result.append("\nRemoteUser=" + req.getRemoteUser());
118 | 0 |
             result.append("\nSession=" + req.getSession());
119 | 0 |
             result.append("\nScheme=" + req.getScheme());
120 | 0 |
             result.append("\nServerName=" + req.getServerName());
121 | 0 |
             result.append("\nServerPort=" + req.getServerPort());
122 | 0 |
             result.append("\nServletPath=" + req.getServletPath());
123 | 0 |
             result.append("\nCookies=" + ArrayUtils.toArrayList(req.getCookies()));
124 | 0 |
             result.append("\nEncoding=" + req.getCharacterEncoding());
125 | 0 |
             result.append("\nAuthType=" + req.getAuthType());
126 |  |
127 | 0 |
             return result.toString();
128 |  |
         }
129 |  |
130 |  |
         /**
131 |  |
          * サーバーサイドにおいてHTTPヘッダへのキャッシュ無効指示
132 |  |
          *
133 |  |
          * @param HttpServletResponse
134 |  |
          *            res
135 |  |
          * @return なし
136 |  |
          */
137 | 0 |
         public static void setNoCache(HttpServletResponse res) {
138 | 0 |
             res.setHeader("Pragma", "no-chace"); // キャッシュプラグマヘッダ
139 | 0 |
             res.setHeader("Cahce-Control", "no-store"); // キャッシュコントロールヘッダ
140 | 0 |
             long lngCurrentTm = System.currentTimeMillis(); // 現時間
141 | 0 |
             long lngValidTm = (60 * 1000) * 5; // ５分後
142 | 0 |
             res.setDateHeader("Expires", lngCurrentTm + lngValidTm); // 有効期限
143 |  |
         }
144 |  |
145 |  |
         /**
146 |  |
          * 指定リクエストＵＲＬの取得 <BR>
147 |  |
          * パラメータも含めた上で文字列を作成（POSTパラメータもGETパラメータ文字列に変換）
148 |  |
          * 例）http://xxx.org/AAAA.jsp?PAGE=123456&AAA=9999
149 |  |
          *
150 |  |
          * @param HttpServletRequest
151 |  |
          *            p_Req HttpServletRequestオブジェクト
152 |  |
          * @return String ＵＲＬ文字列（HttpRequest）
153 |  |
          */
154 | 0 |
         public static String getFullURL(HttpServletRequest req) {
155 | 0 |
             final Enumeration enumPrms = req.getParameterNames(); // パラメータ名列挙オブジェクト
156 | 0 |
             String params = ""; // パラメータ文字列
157 | 0 |
             while (enumPrms.hasMoreElements()) {
158 |  |
                 // リクエスト情報の変数名を取得
159 | 0 |
                 final String paramName = (String) enumPrms.nextElement();
160 | 0 |
                 if (!StringUtils.isEmpty(params))
161 | 0 |
                     params += "&";
162 | 0 |
                 params += paramName + "="
163 |  |
                         + StringUtils.nullTrim(req.getParameter(paramName));
164 |  |
             }
165 | 0 |
             final String result = req.getRequestURI(); // ＵＲＬ
166 | 0 |
             if (!StringUtils.isEmpty(params))
167 | 0 |
                 return result + "?" + params; // パラメータ文字列 付加
168 |  |
             else
169 | 0 |
                 return result;
170 |  |
         }
171 |  |
172 |  |
     }