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  public class WindowUtils
20  {
21      public static Location getLocation ()
22      {
23          Location result = new Location();
24          result.setHash(getHash());
25          result.setHost(getHost());
26          result.setHostName(getHostName());
27          result.setHref(getHref());
28          result.setPath(getPath());
29          result.setPort(getPort());
30          result.setProtocol(getProtocol());
31          result.setQueryString(getQueryString());
32          return result;
33      }
34  
35      private static native String getQueryString () /*-{
36          return $wnd.location.search;
37      }-*/;
38  
39      private static native String getProtocol () /*-{
40          return $wnd.location.protocol;
41      }-*/;
42  
43      private static native String getPort () /*-{
44          return $wnd.location.port;
45      }-*/;
46  
47      private static native String getPath () /*-{
48          return $wnd.location.pathname;
49      }-*/;
50  
51      private static native String getHref () /*-{
52          return $wnd.location.href;
53      }-*/;
54  
55      private static native String getHostName () /*-{
56          return $wnd.location.hostname;
57      }-*/;
58  
59      private static native String getHost () /*-{
60          return $wnd.location.host;
61      }-*/;
62  
63      private static native String getHash () /*-{
64          return $wnd.location.hash;
65      }-*/;
66      
67  }