KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > mina > example > httpserver > codec > HttpRequestMessage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20 package org.apache.mina.example.httpserver.codec;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.Map.Entry;
25
26 /**
27  * A HTTP request message.
28  *
29  * @author The Apache Directory Project (mina-dev@directory.apache.org)
30  * @version $Rev: 555855 $, $Date: 2007-07-13 12:19:00 +0900 (금, 13 7월 2007) $
31  */

32 public class HttpRequestMessage {
33     /** Map<String, String[]> */
34     private Map JavaDoc headers = null;
35
36     public void setHeaders(Map JavaDoc headers) {
37         this.headers = headers;
38     }
39
40     public Map JavaDoc getHeaders() {
41         return headers;
42     }
43
44     public String JavaDoc getContext() {
45         String JavaDoc[] context = (String JavaDoc[]) headers.get("Context");
46         return context == null ? "" : context[0];
47     }
48
49     public String JavaDoc getParameter(String JavaDoc name) {
50         String JavaDoc[] param = (String JavaDoc[]) headers.get("@".concat(name));
51         return param == null ? "" : param[0];
52     }
53
54     public String JavaDoc[] getParameters(String JavaDoc name) {
55         String JavaDoc[] param = (String JavaDoc[]) headers.get("@".concat(name));
56         return param == null ? new String JavaDoc[] {} : param;
57     }
58
59     public String JavaDoc[] getHeader(String JavaDoc name) {
60         return (String JavaDoc[]) headers.get(name);
61     }
62
63     public String JavaDoc toString() {
64         StringBuilder JavaDoc str = new StringBuilder JavaDoc();
65
66         Iterator JavaDoc it = headers.entrySet().iterator();
67         while (it.hasNext()) {
68             Entry e = (Entry) it.next();
69             str.append(e.getKey() + " : "
70                     + arrayToString((String JavaDoc[]) e.getValue(), ',') + "\n");
71         }
72         return str.toString();
73     }
74
75     public static String JavaDoc arrayToString(String JavaDoc[] s, char sep) {
76         if (s == null || s.length == 0)
77             return "";
78         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
79         if (s != null) {
80             for (int i = 0; i < s.length; i++) {
81                 if (i > 0)
82                     buf.append(sep);
83                 buf.append(s[i]);
84             }
85         }
86         return buf.toString();
87     }
88 }
89
Popular Tags