mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-19 20:25:31 +00:00
Bug 4202: Imported ajaxloader as source to prevent infinit build loop in
Eclipse
This commit is contained in:
@@ -4,6 +4,5 @@
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="lib" path="gwt-ajaxloader.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -7,12 +7,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: com.google.gwt.user;bundle-version="2.8.2";resolution:=optional,
|
||||
com.google.gwt.dev;bundle-version="2.8.2";resolution:=optional,
|
||||
com.google.gwt.servlet;bundle-version="2.8.2"
|
||||
com.google.gwt.ajaxloader;bundle-version="1.1.0";visibility:=reexport
|
||||
Automatic-Module-Name: com.github.branflake2267.gwt-maps-api
|
||||
Bundle-ClassPath: gwt-ajaxloader.jar,
|
||||
.
|
||||
Export-Package: com.google.gwt.ajaxloader.client,
|
||||
com.google.gwt.maps.client,
|
||||
Bundle-ClassPath: .
|
||||
Export-Package: com.google.gwt.maps.client,
|
||||
com.google.gwt.maps.client.adsense,
|
||||
com.google.gwt.maps.client.base,
|
||||
com.google.gwt.maps.client.controls,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
gwt-ajaxloader.jar
|
||||
.
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1 @@
|
||||
bin
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.google.gwt.ajaxloader</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,81 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deadCode=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
@@ -0,0 +1,4 @@
|
||||
#Tue Feb 28 12:33:59 CET 2012
|
||||
eclipse.preferences.version=1
|
||||
pluginProject.extensions=false
|
||||
resolve.requirebundle=false
|
||||
@@ -0,0 +1,12 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Google Maps API
|
||||
Bundle-SymbolicName: com.google.gwt.ajaxloader
|
||||
Bundle-Version: 1.1.0.qualifier
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: com.google.gwt.user;bundle-version="2.8.2";resolution:=optional,
|
||||
com.google.gwt.dev;bundle-version="2.8.2";resolution:=optional
|
||||
Automatic-Module-Name: com.google.gwt.ajaxloader
|
||||
Bundle-ClassPath: .
|
||||
Export-Package: com.google.gwt.ajaxloader.client
|
||||
@@ -0,0 +1,4 @@
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>root</artifactId>
|
||||
<groupId>com.sap.sailing</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>com.google.gwt.ajaxloader</artifactId>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<version>1.1.0-SHAPSHOT</version>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>tycho-source-plugin</artifactId>
|
||||
<version>${tycho-version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>plugin-source</id>
|
||||
<phase>generate-sources</phase>
|
||||
<goals>
|
||||
<goal>plugin-source</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- -->
|
||||
<!-- Copyright 2009 Google Inc. -->
|
||||
<!-- Licensed under the Apache License, Version 2.0 (the "License"); you -->
|
||||
<!-- may not use this file except in compliance with the License. You may -->
|
||||
<!-- may obtain a copy of the License at -->
|
||||
<!-- -->
|
||||
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
|
||||
<!-- -->
|
||||
<!-- Unless required by applicable law or agreed to in writing, software -->
|
||||
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
|
||||
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -->
|
||||
<!-- implied. License for the specific language governing permissions and -->
|
||||
<!-- limitations under the License. -->
|
||||
<module>
|
||||
<inherits name="com.google.gwt.user.User"/>
|
||||
<!-- I18N is needed for the AjaxKeyRepostitory class -->
|
||||
<inherits name="com.google.gwt.i18n.I18N"/>
|
||||
<source path="client"/>
|
||||
</module>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.i18n.client.Constants;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* For retrieving host:port/key pairs from a file.
|
||||
*/
|
||||
public interface AjaxKeyConstants extends Constants {
|
||||
@DefaultStringMapValue({
|
||||
"localhost:8080",
|
||||
"ABQIAAAAG8LzhtshQCjpSshU_uJjmxTwM0brOpm-All5BF6PoaKBxRWWERTZER2lJ4GnsG8nvhKLOQ20degaEQ",
|
||||
"127.0.0.1:8080",
|
||||
"ABQIAAAAG8LzhtshQCjpSshU_uJjmxTBfUk9TZrBRaIteybtnU2KziHEpRQvhPNTjo7DMczjrRD3yBPRJ_BSQQ"})
|
||||
Map<String, String> ajaxKeys();
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.Window.Location;
|
||||
|
||||
/**
|
||||
* Stores keys for different locations (hostname:port). The AjaxLoader class can
|
||||
* lookup a key from this repository if not otherwise specified.
|
||||
*
|
||||
* This repository can be helpful for web sites that respond to requests for
|
||||
* multiple domains (or by name and IP address), or to run your application on
|
||||
* multiple servers (say development, test, and production) and store the set of
|
||||
* valid keys compiled into the application.
|
||||
*
|
||||
* You can specify these keys in multiple ways:
|
||||
*
|
||||
* - You can create a
|
||||
* com/google/gwt/ajaxloader/client/AjaxKeyConstants.properties file with the
|
||||
* following format:
|
||||
*
|
||||
* localhost\:8080 = ABQIAAAAG8LzhtshQCjpSshU_uJjm\
|
||||
* xTwM0brOpm-All5BF6PoaKBxRWWERTZER2lJ4GnsG8nvhKLOQ20degaEQ
|
||||
*
|
||||
* 127.0.0.1\:8080 = ABQIAAAAG8LzhtshQCjpSshU_uJjm\
|
||||
* xTBfUk9TZrBRaIteybtnU2KziHEpRQvhPNTjo7DMczjrRD3yBPRJ_BSQQ
|
||||
*
|
||||
* example.com\:8080 = ABQIAAAAG8LzhU_uJjmhtshQCjpSs\
|
||||
* 3yBPRJ_BSQQxTBfUk9TZrBRaIteybtnU2KziHEpRQvhPNTjo7DMczjrRD
|
||||
*
|
||||
* ajaxKeys = localhost\:8080, 127.0.0.1\:8080 example.com\:8080
|
||||
*
|
||||
* - You can specify an instance of AjaxKeyConstants to the
|
||||
* {@link #setKeys(AjaxKeyConstants)} method.
|
||||
*
|
||||
* - You can load keys at runtime with the {@link #putKey(String, String)}
|
||||
* method.
|
||||
*/
|
||||
public class AjaxKeyRepository {
|
||||
|
||||
// Deferred bound instance of Constants class used to populate keys
|
||||
private static AjaxKeyConstants keys = GWT.create(AjaxKeyConstants.class);
|
||||
|
||||
/**
|
||||
* Retrieve an Ajax API key given the current location.
|
||||
*/
|
||||
public static String getKey() {
|
||||
return keys.ajaxKeys().get(Location.getHost());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an Ajax API Key given the hostname:port value.
|
||||
*
|
||||
* @param location hostname:port string
|
||||
*/
|
||||
public static String getKey(String location) {
|
||||
return keys.ajaxKeys().get(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Associates a a hostname:port with an Ajax API key.
|
||||
*
|
||||
* @param location hostname:port value
|
||||
* @param ajaxApiKey the key registered for the above hostname:port combo
|
||||
*/
|
||||
public static void putKey(String location, String ajaxApiKey) {
|
||||
keys.ajaxKeys().put(location, ajaxApiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the default key properties with your own custom subclass. Note
|
||||
* that calling this method will invalidate any keys set with putKey or any
|
||||
* defaults compiled into the library.
|
||||
*
|
||||
* @param keys an extension of the AjaxKeyConstants interface to override the
|
||||
* defaults.
|
||||
*/
|
||||
public static void setKeys(AjaxKeyConstants keys) {
|
||||
AjaxKeyRepository.keys = keys;
|
||||
}
|
||||
|
||||
private AjaxKeyRepository() {
|
||||
// do not instantiate this class
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.ScriptElement;
|
||||
import com.google.gwt.user.client.Window;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* A wrapper for the google Ajax API loader.
|
||||
*
|
||||
* http://code.google.com/apis/ajax/documentation/
|
||||
*/
|
||||
public class AjaxLoader {
|
||||
/**
|
||||
* An object to pass as the third parameter to load() call.
|
||||
*/
|
||||
public static class AjaxLoaderOptions extends JavaScriptObject {
|
||||
public static AjaxLoaderOptions newInstance() {
|
||||
return JavaScriptObject.createObject().cast();
|
||||
}
|
||||
|
||||
protected AjaxLoaderOptions() {
|
||||
// A protected constructor is required for JavaScriptObject overlays.
|
||||
}
|
||||
|
||||
public final native void setBaseDomain(String baseDomain) /*-{
|
||||
this.base_domain = baseDomain;
|
||||
}-*/;
|
||||
|
||||
public final native void setLanguage(String language) /*-{
|
||||
// TODO(zundel): try to incorporate w/ GWT locale?
|
||||
this.language = language;
|
||||
}-*/;
|
||||
|
||||
// TODO(zundel): the docs are a little confusing on this one.
|
||||
public final native void setNoCss(boolean value) /*-{
|
||||
this.nocss = value;
|
||||
}-*/;
|
||||
|
||||
public final native void setOtherParms(String otherParams) /*-{
|
||||
this.other_params = otherParams;
|
||||
}-*/;
|
||||
|
||||
public final native void setPackages(JsArrayString packages) /*-{
|
||||
this.packages = packages;
|
||||
}-*/;
|
||||
|
||||
public final void setPackages(String... packages) {
|
||||
setPackages(ArrayHelper.toJsArrayString(packages));
|
||||
}
|
||||
|
||||
private native void setCallback(Runnable onLoad) /*-{
|
||||
this.callback = function() {
|
||||
@com.google.gwt.ajaxloader.client.ExceptionHelper::runProtected(Ljava/lang/Runnable;)(onLoad);
|
||||
}
|
||||
}-*/;
|
||||
}
|
||||
|
||||
// NativeCreateCallback already ran, or someone injected the API outside of
|
||||
// this program.
|
||||
static boolean alreadyInjected = false;
|
||||
|
||||
// Set to true if the init(key) method has been called.
|
||||
static boolean initialized = false;
|
||||
|
||||
// True if the JavaScript __gwt_AjaxLoader_onLoad callback has already run.
|
||||
// This function is registered on the window in nativeCreateCallback()
|
||||
static boolean loaded = false;
|
||||
|
||||
static Vector<Runnable> queuedApiLoads = new Vector<Runnable>();
|
||||
|
||||
public static ClientLocation getClientLocation() {
|
||||
if (!injectJsapi(null, null)) {
|
||||
return null;
|
||||
}
|
||||
return nativeGetClientLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the API without specifying a key.
|
||||
*/
|
||||
public static void init() {
|
||||
init(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the API with a supplied key value. See
|
||||
* http://code.google.com/apis/ajaxsearch/signup.html
|
||||
*
|
||||
* @param apiKey API key value.
|
||||
*/
|
||||
public static void init(String apiKey) {
|
||||
init(apiKey, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the API with a supplied key value and custom hostname. Most
|
||||
* programmers should use {@link AjaxLoader#init(String)} instead, as it
|
||||
* covers almost all cases of using AjaxLoader API.
|
||||
*
|
||||
* See http://code.google.com/apis/ajaxsearch/signup.html
|
||||
*
|
||||
* @param apiKey API key value.
|
||||
* @param hostname Custom hostname (e.g. "www.google.com").
|
||||
*/
|
||||
public static void init(String apiKey, String hostname) {
|
||||
if (initialized == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (apiKey == null) {
|
||||
// No key was specified. Use the location in the page to lookup a key from
|
||||
// the Key repository
|
||||
apiKey = AjaxKeyRepository.getKey();
|
||||
}
|
||||
|
||||
boolean alreadyLoaded = injectJsapi(apiKey, hostname);
|
||||
|
||||
// In IE, the above script can execute immediately if its already in the
|
||||
// cache, so don't touch the loaded variable unless we bypassed loading the
|
||||
// script completely
|
||||
if (alreadyLoaded) {
|
||||
loaded = true;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches an API load request.
|
||||
*
|
||||
* @param api The name of the API to load
|
||||
* @param version The API version to load
|
||||
* @param onLoad A callback that will be invoked when the API is finished
|
||||
* loaded. Do not make any calls into the API being loaded until this
|
||||
* call returns.
|
||||
* @param settings An object containing additional settings.
|
||||
*/
|
||||
public static void loadApi(final String api, final String version,
|
||||
Runnable onLoad, AjaxLoaderOptions settings) {
|
||||
|
||||
// Initialize the API if it hasn't already been initialized.
|
||||
init();
|
||||
|
||||
// Set the onLoad callback into the
|
||||
assert (onLoad != null);
|
||||
if (settings == null) {
|
||||
settings = AjaxLoaderOptions.newInstance();
|
||||
}
|
||||
settings.setCallback(onLoad);
|
||||
final AjaxLoaderOptions copyOfSettings = settings;
|
||||
|
||||
// Define a Runnable that will run the actual load.
|
||||
Runnable apiLoad = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
nativeLoadApi(api, version, copyOfSettings);
|
||||
}
|
||||
};
|
||||
|
||||
if (loaded) {
|
||||
// jsapi is finished loading, start the individual API load now.
|
||||
apiLoad.run();
|
||||
} else {
|
||||
// Defer the load until jsapi is finished.
|
||||
queuedApiLoads.add(apiLoad);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getProtocol() {
|
||||
if (Window.Location.getProtocol().equals("https:")) {
|
||||
return "https:";
|
||||
}
|
||||
return "http:";
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a script element to the DOM that loads the Ajax API Loader main script
|
||||
* "jsapi".
|
||||
*
|
||||
* @param apiKey Optional API key value (pass null to omit the key). See
|
||||
* http://code.google.com/apis/ajaxsearch/signup.html
|
||||
* @returns <code>true</code> if the API has already been loaded. Otherwise,
|
||||
* returns <code>false</code>, meaning that the application should
|
||||
* wait for a callback.
|
||||
*/
|
||||
private static boolean injectJsapi(String apiKey, String hostname) {
|
||||
if (alreadyInjected) {
|
||||
return true;
|
||||
}
|
||||
boolean alreadyLoaded = nativeCreateCallback();
|
||||
alreadyInjected = true;
|
||||
if (alreadyLoaded) {
|
||||
return true;
|
||||
}
|
||||
Document doc = Document.get();
|
||||
String key = (apiKey == null) ? "" : ("key=" + apiKey + "&");
|
||||
hostname = (hostname == null) ? "www.google.com" : hostname;
|
||||
String src = getProtocol() + "//" + hostname + "/jsapi?" + key
|
||||
+ "callback=__gwt_AjaxLoader_onLoad";
|
||||
ScriptElement script = doc.createScriptElement();
|
||||
script.setSrc(src);
|
||||
script.setType("text/javascript");
|
||||
doc.getBody().appendChild(script);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a function to be registered for a callback after jsapi loads.
|
||||
*/
|
||||
private static native boolean nativeCreateCallback() /*-{
|
||||
if ($wnd['google'] && $wnd.google['load']) {
|
||||
// The API has already been loaded.
|
||||
return true;
|
||||
}
|
||||
$wnd.__gwt_AjaxLoader_onLoad = function() {
|
||||
@com.google.gwt.ajaxloader.client.AjaxLoader::onLoadCallback()();
|
||||
}
|
||||
// The application must wait for a callback.
|
||||
return false;
|
||||
}-*/;
|
||||
|
||||
private static final native ClientLocation nativeGetClientLocation() /*-{
|
||||
return $wnd.google.loader.ClientLocation;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Wrapper for AjaxLoader google.load() native method.
|
||||
*/
|
||||
private static native void nativeLoadApi(String api, String version,
|
||||
JavaScriptObject settings) /*-{
|
||||
$wnd.google.load(api, version, settings);
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Called back when the jsapi is finished loaded. It must kick of any API
|
||||
* loads that have been queued while waiting on jsapi to finish loading.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private static void onLoadCallback() {
|
||||
loaded = true;
|
||||
|
||||
for (Runnable r : queuedApiLoads) {
|
||||
r.run();
|
||||
}
|
||||
queuedApiLoads.clear();
|
||||
}
|
||||
|
||||
private AjaxLoader() {
|
||||
// This class only contains static methods and should not be instantiated.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.JsArrayBoolean;
|
||||
import com.google.gwt.core.client.JsArrayInteger;
|
||||
import com.google.gwt.core.client.JsArrayNumber;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
|
||||
/**
|
||||
* Convenience methods for working with GWT JsArrays.
|
||||
*/
|
||||
public class ArrayHelper {
|
||||
/**
|
||||
* Converts a Java array of booleans to a JavaScript boolean array.
|
||||
*
|
||||
* @param bits array of booleans to convert.
|
||||
* @deprecated this overload can be ambiguous with other methods using
|
||||
* varargs. Use the toJsArrayBoolean() method instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static JsArrayBoolean createJsArray(boolean... bits) {
|
||||
return toJsArrayBoolean(bits);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Java array of doubles to a JavaScript number array.
|
||||
*
|
||||
* @param numbers array of doubles to convert.
|
||||
* @deprecated this overload is ambiguous with other methods using varrgs. Use
|
||||
* toJsArrayNumber() instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static JsArrayNumber createJsArray(double... numbers) {
|
||||
return toJsArrayNumber(numbers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Java integer array to JavaScript integer array.
|
||||
*
|
||||
* @param integers array of integers to convert.
|
||||
* @deprecated This overload is ambiguous with other methods using varargs.
|
||||
* Use toJsArrayInteger() instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static JsArrayInteger createJsArray(int[] integers) {
|
||||
return toJsArrayInteger(integers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of Java strings to an array of JavaScript strings.
|
||||
*
|
||||
* @param strings array of strings to convert
|
||||
* @deprecated renamed to toJsArrayString() to avoid using overloads w/
|
||||
* varargs
|
||||
*/
|
||||
@Deprecated
|
||||
public static JsArrayString createJsArray(String... strings) {
|
||||
return toJsArrayString(strings);
|
||||
}
|
||||
|
||||
// TODO(zundel): Add other methods to convert to Java Arrays
|
||||
|
||||
/**
|
||||
* Takes an array of Integers to be interpreted as bytes and returns a Java
|
||||
* Array of the byte primitive type.
|
||||
*
|
||||
* @param bytes a JavaScript array to return.
|
||||
*/
|
||||
public static byte[] toJavaArrayBytes(JsArrayInteger bytes) {
|
||||
int length = bytes.length();
|
||||
byte[] ret = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = (byte) bytes.get(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static <J extends JavaScriptObject> JsArray<J> toJsArray(J... objects) {
|
||||
JsArray<J> result = JsArray.createArray().cast();
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
result.set(i, objects[i]);
|
||||
}
|
||||
nativePatchConstructorForSafari(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Java array of booleans to a JavaScript boolean array.
|
||||
*
|
||||
* @param bits array of booleans to convert.
|
||||
*/
|
||||
public static JsArrayBoolean toJsArrayBoolean(boolean... bits) {
|
||||
JsArrayBoolean result = JsArrayBoolean.createArray().cast();
|
||||
for (int i = 0; i < bits.length; i++) {
|
||||
result.set(i, bits[i]);
|
||||
}
|
||||
nativePatchConstructorForSafari(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts Java integer array to JavaScript integer array.
|
||||
*
|
||||
* @param integers array of integers to convert.
|
||||
*/
|
||||
public static JsArrayInteger toJsArrayInteger(int... integers) {
|
||||
JsArrayInteger result = JsArrayInteger.createArray().cast();
|
||||
for (int i = 0; i < integers.length; i++) {
|
||||
result.set(i, integers[i]);
|
||||
}
|
||||
nativePatchConstructorForSafari(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Java array of doubles to a JavaScript number array.
|
||||
*
|
||||
* @param numbers array of doubles to convert.
|
||||
*/
|
||||
public static JsArrayNumber toJsArrayNumber(double... numbers) {
|
||||
JsArrayNumber result = JsArrayNumber.createArray().cast();
|
||||
for (int i = 0; i < numbers.length; i++) {
|
||||
result.set(i, numbers[i]);
|
||||
}
|
||||
nativePatchConstructorForSafari(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of Java strings to an array of JavaScript strings.
|
||||
*
|
||||
* @param strings array of strings to convert
|
||||
*/
|
||||
public static JsArrayString toJsArrayString(String... strings) {
|
||||
JsArrayString result = JsArrayString.createArray().cast();
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
result.set(i, strings[i]);
|
||||
}
|
||||
nativePatchConstructorForSafari(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a fixup for the constructor used to address issue 219 - Safari bug
|
||||
* in comparing Date & Array constructors.
|
||||
*
|
||||
* @param result
|
||||
*/
|
||||
private static native void nativePatchConstructorForSafari(
|
||||
JavaScriptObject result) /*-{
|
||||
result.constructor = $wnd.Array;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
/**
|
||||
* Wraps the ClientLocation object stored on google.loader described at
|
||||
* http://code.google.com/apis/ajax/documentation/#ClientLocation
|
||||
*/
|
||||
public class ClientLocation extends JavaScriptObject {
|
||||
|
||||
protected ClientLocation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Supplies the name of the city associated with the client's IP address.
|
||||
*/
|
||||
public final native String getCity() /*-{
|
||||
return this.address.city;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Supplies the name of the country associated with the client's IP address.
|
||||
*/
|
||||
public final native String getCountry() /*-{
|
||||
return this.address.country;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Supplies the name of the ISO 3166-1 country code associated with the
|
||||
* client's IP address.
|
||||
*/
|
||||
public final native String getCountryCode() /*-{
|
||||
return this.address.country_code;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Supplies the low resolution latitude associated with the client's IP
|
||||
* address.
|
||||
*/
|
||||
public final native double getLatitude() /*-{
|
||||
return this.latitude;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Supplies the low resolution longitude associated with the client's IP
|
||||
* address.
|
||||
*/
|
||||
public final native double getLongitude() /*-{
|
||||
return this.longitude;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Supplies the country specific region name associated with the client's IP
|
||||
* address.
|
||||
*/
|
||||
public final native String getRegion() /*-{
|
||||
return this.address.region;
|
||||
}-*/;
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
|
||||
|
||||
/**
|
||||
* Helps with the GWT uncaught exception handler.
|
||||
*/
|
||||
public abstract class ExceptionHelper {
|
||||
/**
|
||||
* If an uncaught exception handler has been registered, execute the Runnable
|
||||
* in a try/catch block and handle exceptions with the uncaught exception
|
||||
* handler. Otherwise, run the Runnable and do not catch exceptions.
|
||||
*
|
||||
* @param runnable The Runnable to execute.
|
||||
*/
|
||||
public static void runProtected(Runnable runnable) {
|
||||
UncaughtExceptionHandler handler = GWT.getUncaughtExceptionHandler();
|
||||
if (handler != null) {
|
||||
try {
|
||||
runnable.run();
|
||||
} catch (Throwable e) {
|
||||
handler.onUncaughtException(e);
|
||||
}
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
private ExceptionHelper() {
|
||||
// do not instantiate
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Wraps a JavaScript Date object.
|
||||
*/
|
||||
public class JsDate extends JavaScriptObject {
|
||||
/**
|
||||
* Create a JsDate with the current time.
|
||||
*
|
||||
* @return A JsDate with the current time.
|
||||
*/
|
||||
public static native JsDate create() /*-{
|
||||
var result = new $wnd.Date();
|
||||
// Safari bug: see issue 219
|
||||
result.constructor = $wnd.Date;
|
||||
return result;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Create a date given the time in milliseconds.
|
||||
*
|
||||
* @param time A time value in milliseconds. Uses the double type for
|
||||
* efficiency.
|
||||
* @return A JsDate with the given time.
|
||||
*/
|
||||
public static native JsDate create(double time) /*-{
|
||||
var result = new $wnd.Date(time);
|
||||
// Safari bug: see issue 219
|
||||
result.constructor = $wnd.Date;
|
||||
return result;
|
||||
}-*/;
|
||||
/**
|
||||
* Tests if the JavaScriptObject can be cast to JsDate. Checks if the
|
||||
* underlying JavaScript object has a method called getTime() that returns
|
||||
* a number.
|
||||
*
|
||||
* @param js A JavaScriptObject that may or may not be wrapping a JavaScript
|
||||
* Date object.
|
||||
* @return false if the JavaScriptObject is null or if it cannot be cast
|
||||
* to JsDate, otherwise true.
|
||||
*/
|
||||
public static native boolean isDate(JavaScriptObject js) /*-{
|
||||
var result = false;
|
||||
if (js != null) {
|
||||
if (typeof js.getTime == 'function') {
|
||||
var time = js.getTime();
|
||||
if (typeof time == 'number') {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Converts a JsDate to a Java Date. If the JsDate is null, the function
|
||||
* returns null.
|
||||
*
|
||||
* @param js A JsDate.
|
||||
* @return A Java Date object, or null, if js is null.
|
||||
*/
|
||||
public static Date toJava(JsDate js) {
|
||||
return js == null ? null : new Date(js.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Java Date to a JsDate. If the Date is null, the function
|
||||
* returns null.
|
||||
*
|
||||
* @param java A Java Date.
|
||||
* @return An analogous JsDate, or null if the original Java Date was null.
|
||||
*/
|
||||
public static JsDate toJs(Date java) {
|
||||
return java == null ? null : create(java.getTime());
|
||||
}
|
||||
|
||||
protected JsDate() {
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper for the JavaScript Date's getTime() method.
|
||||
*
|
||||
* @return The time in milliseconds corresponding to this JsDate.
|
||||
*/
|
||||
public final long getTime() {
|
||||
return (long) doubleTime();
|
||||
}
|
||||
|
||||
private native double doubleTime() /*-{
|
||||
return this.getTime();
|
||||
}-*/;
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.gwt.ajaxloader.client;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptException;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* A collection of properties of arbitrary type, for interoperability with
|
||||
* non-GWT JavaScript libraries.
|
||||
*/
|
||||
public class Properties extends JavaScriptObject {
|
||||
/**
|
||||
* An exception thrown by the get methods when the key is found but the
|
||||
* value has an unexpected type.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static class TypeException extends Exception {
|
||||
private TypeException(String key, String expected, String actual) {
|
||||
super("Properties.get" + expected + "(" + key +
|
||||
") failed. Unexpected type : " + actual + ".");
|
||||
}
|
||||
|
||||
private TypeException() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty Properties object.
|
||||
* @return An empty Properties object.
|
||||
*/
|
||||
public static Properties create() {
|
||||
return JavaScriptObject.createObject().cast();
|
||||
}
|
||||
|
||||
protected Properties() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Boolean value mapped to the specified key.
|
||||
*
|
||||
* @param key The name of the Boolean property.
|
||||
* @return A Boolean value, or null if the key is not found.
|
||||
* @throws TypeException if the key is found but the object returned
|
||||
* is not a Boolean.
|
||||
*/
|
||||
public final Boolean getBoolean(String key) throws TypeException {
|
||||
if (containsKey(key)) {
|
||||
String type = typeof(key);
|
||||
if (type.equals("boolean")) {
|
||||
return nativeGetBoolean(key);
|
||||
} else {
|
||||
throw new TypeException(key, "Boolean", type);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Date object mapped to the specified key.
|
||||
*
|
||||
* @param key The name of the Date property.
|
||||
* @return A Date object, or null if the key is not found.
|
||||
* @throws JavaScriptException if the key is found but the object returned
|
||||
* is not a Date.
|
||||
* @throws TypeException If the key is found but the value is not an object.
|
||||
*/
|
||||
public final Date getDate(String key)
|
||||
throws JavaScriptException, TypeException {
|
||||
return JsDate.toJava((JsDate) getObject(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Double value mapped to the specified key.
|
||||
*
|
||||
* @param key The name of the Double property.
|
||||
* @return A Double value, or null if the key is not found.
|
||||
* @throws TypeException If the key is found but the value is not a
|
||||
* number (integers are fine).
|
||||
*/
|
||||
public final Double getNumber(String key) throws TypeException {
|
||||
if (containsKey(key)) {
|
||||
String type = typeof(key);
|
||||
if (type.equals("number")) {
|
||||
return nativeGetNumber(key);
|
||||
} else {
|
||||
throw new TypeException(key, "Number", type);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a JavaScriptObject mapped to the specified key.
|
||||
*
|
||||
* @param key The name of the JavaScriptObject property.
|
||||
* @return A JavaScriptObject, or null if the key is not found.
|
||||
* @throws TypeException If the key is found but the value is not a
|
||||
* JavaScriptObject.
|
||||
*/
|
||||
public final JavaScriptObject getObject(String key) throws TypeException {
|
||||
if (containsKey(key)) {
|
||||
String type = typeof(key);
|
||||
if (type.equals("object")) {
|
||||
return nativeGetObject(key);
|
||||
} else {
|
||||
throw new TypeException(key, "Object", type);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a String mapped to the specified key.
|
||||
*
|
||||
* @param key The name of the String property.
|
||||
* @return A String, or null if the key is not found.
|
||||
* @throws TypeException If the key is found but the value is not a
|
||||
* String.
|
||||
*/
|
||||
public final String getString(String key) throws TypeException {
|
||||
if (containsKey(key)) {
|
||||
String type = typeof(key);
|
||||
if (type.equals("string")) {
|
||||
return nativeGetString(key);
|
||||
} else {
|
||||
throw new TypeException(key, "String", type);
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the property at the specified key.
|
||||
*
|
||||
* @param key The name of the property to remove.
|
||||
*/
|
||||
public final native void remove(String key) /*-{
|
||||
delete this[key];
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Set a property.
|
||||
*
|
||||
* @param key The name of the property.
|
||||
* @param value The value of the property.
|
||||
*/
|
||||
public final void set(String key, Boolean value) {
|
||||
if (value == null) {
|
||||
remove(key);
|
||||
} else {
|
||||
setBoolean(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property.
|
||||
*
|
||||
* @param key The name of the property.
|
||||
* @param value The value of the property.
|
||||
*/
|
||||
public final void set(String key, Date value) {
|
||||
set(key, JsDate.toJs(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property.
|
||||
*
|
||||
* @param key The name of the property.
|
||||
* @param value The value of the property.
|
||||
*/
|
||||
public final void set(String key, Double value) {
|
||||
if (value == null) {
|
||||
remove(key);
|
||||
} else {
|
||||
setNumber(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a property.
|
||||
*
|
||||
* @param key The name of the property.
|
||||
* @param value The value of the property.
|
||||
*/
|
||||
public final native void set(String key, JavaScriptObject value) /*-{
|
||||
this[key] = value;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Set a property.
|
||||
*
|
||||
* @param key The name of the property.
|
||||
* @param value The value of the property.
|
||||
*/
|
||||
public final native void set(String key, String value) /*-{
|
||||
this[key] = value;
|
||||
}-*/;
|
||||
|
||||
/**
|
||||
* Executes the JavaScript typeof operator against the property with the
|
||||
* given key. Note that the typeof undefined is "undefined" and the typeof
|
||||
* null is "object".
|
||||
*
|
||||
* @param key The name of the property to type check.
|
||||
* @return The JavaScript type of the property, as defined by the JavaScipt
|
||||
* typeof operator.
|
||||
*/
|
||||
public final native String typeof(String key) /*-{
|
||||
return typeof this[key];
|
||||
}-*/;
|
||||
|
||||
private native boolean containsKey(String key) /*-{
|
||||
return this[key] != null;
|
||||
}-*/;
|
||||
|
||||
private native boolean nativeGetBoolean(String key) /*-{
|
||||
return this[key];
|
||||
}-*/;
|
||||
|
||||
private native double nativeGetNumber(String key) /*-{
|
||||
return this[key];
|
||||
}-*/;
|
||||
|
||||
private native JavaScriptObject nativeGetObject(String key) /*-{
|
||||
return this[key];
|
||||
}-*/;
|
||||
|
||||
private native String nativeGetString(String key) /*-{
|
||||
return this[key];
|
||||
}-*/;
|
||||
|
||||
private native void setBoolean(String key, boolean value) /*-{
|
||||
this[key] = value;
|
||||
}-*/;
|
||||
|
||||
private native void setNumber(String key, double value) /*-{
|
||||
this[key] = value;
|
||||
}-*/;
|
||||
}
|
||||
Reference in New Issue
Block a user