View Javadoc

1   /*
2    * Copyright 2006 Robert Hanson <iamroberthanson AT gmail.com>
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.gwtwidgets.client.util;
18  
19  import java.util.HashMap;
20  import java.util.Map;
21  
22  public class Location
23  {
24      private String hash;
25      private String host;
26      private String hostName;
27      private String href;
28      private String path;
29      private String port;
30      private String protocol;
31      private String queryString;
32      private HashMap paramMap;
33  
34  
35      public String getHash ()
36      {
37          return hash;
38      }
39  
40      public String getHost ()
41      {
42          return host;
43      }
44  
45      public String getHostName ()
46      {
47          return hostName;
48      }
49  
50      public String getHref ()
51      {
52          return href;
53      }
54  
55      public String getPath ()
56      {
57          return path;
58      }
59  
60      public String getPort ()
61      {
62          return port;
63      }
64  
65      public String getProtocol ()
66      {
67          return protocol;
68      }
69  
70      public String getQueryString ()
71      {
72          return queryString;
73      }
74  
75      protected void setHash (String hash)
76      {
77          this.hash = hash;
78      }
79  
80      protected void setHost (String host)
81      {
82          this.host = host;
83      }
84  
85      protected void setHostName (String hostName)
86      {
87          this.hostName = hostName;
88      }
89  
90      protected void setHref (String href)
91      {
92          this.href = href;
93      }
94  
95      protected void setPath (String path)
96      {
97          this.path = path;
98      }
99  
100     protected void setPort (String port)
101     {
102         this.port = port;
103     }
104 
105     protected void setProtocol (String protocol)
106     {
107         this.protocol = protocol;
108     }
109 
110     protected void setQueryString (String queryString)
111     {
112         this.queryString = queryString;
113         paramMap = new HashMap();
114         
115         if (queryString != null && queryString.length() > 1) {
116             String qs = queryString.substring(1);
117             String[] kvPairs = qs.split("&");
118             for (int i = 0; i < kvPairs.length; i++) {
119                 String[] kv = kvPairs[i].split("=");
120                 if (kv.length > 1) {
121                     paramMap.put(kv[0], unescape(kv[1]));
122                 }
123                 else {
124                     paramMap.put(kv[0], "");
125                 }
126             }
127         }
128     }
129     
130     private native String unescape (String val) /*-{
131         return unescape(val);
132     }-*/;
133 
134     public String getParameter (String name)
135     {
136         return (String) paramMap.get(name);
137     }
138 
139     public Map getParameterMap ()
140     {
141         return paramMap;
142     }
143 
144 }