001/* 002 * (C) Copyright 2006-2008 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * troger 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.annotations.gwt.client; 023 024import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfiguration; 025import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfigurationService; 026import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfigurationServiceAsync; 027 028import com.allen_sauer.gwt.log.client.Log; 029import com.google.gwt.core.client.EntryPoint; 030import com.google.gwt.core.client.GWT; 031import com.google.gwt.user.client.Window; 032import com.google.gwt.user.client.rpc.AsyncCallback; 033 034/** 035 * @author <a href="mailto:[email protected]">Thomas Roger</a> 036 */ 037public class AnnotationModule implements EntryPoint { 038 039 private WebConfigurationServiceAsync webConfigurationService; 040 041 private WebConfiguration webConfiguration; 042 043 public void onModuleLoad() { 044 fixXMLHttpRequest(); 045 webConfigurationService = GWT.create(WebConfigurationService.class); 046 String url = Window.Location.getHref(); 047 webConfigurationService.getWebConfiguration(url, new AsyncCallback<WebConfiguration>() { 048 public void onFailure(Throwable throwable) { 049 Log.debug("onFailure: " + throwable); 050 webConfiguration = WebConfiguration.DEFAULT_WEB_CONFIGURATION; 051 initModule(); 052 } 053 054 public void onSuccess(WebConfiguration result) { 055 webConfiguration = result == null ? WebConfiguration.DEFAULT_WEB_CONFIGURATION : result; 056 initModule(); 057 Log.debug("Module initialization finished."); 058 } 059 }); 060 } 061 062 private void initModule() { 063 AnnotationApplication.build(webConfiguration); 064 } 065 066 // Fix XMLHttpRequest when using Annotations module on IE6. 067 // XMLHttpRequest is defined in $wnd, but not in window (due to sarrisa 068 // librairy use in ajax4jsf) so GWT can't instantiate a XMLHttpRequest object. 069 private native void fixXMLHttpRequest() /*-{ 070 if ($wnd.XMLHttpRequest && !window.XMLHttpRequest) { 071 window.XMLHttpRequest = $wnd.XMLHttpRequest; 072 } 073 }-*/; 074 075}