001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * troger 016 * 017 * $Id$ 018 */ 019 020package org.nuxeo.ecm.platform.annotations.gwt.client; 021 022import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfiguration; 023import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfigurationService; 024import org.nuxeo.ecm.platform.annotations.gwt.client.configuration.WebConfigurationServiceAsync; 025 026import com.allen_sauer.gwt.log.client.Log; 027import com.google.gwt.core.client.EntryPoint; 028import com.google.gwt.core.client.GWT; 029import com.google.gwt.user.client.Window; 030import com.google.gwt.user.client.rpc.AsyncCallback; 031 032/** 033 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a> 034 */ 035public class AnnotationModule implements EntryPoint { 036 037 private WebConfigurationServiceAsync webConfigurationService; 038 039 private WebConfiguration webConfiguration; 040 041 public void onModuleLoad() { 042 fixXMLHttpRequest(); 043 webConfigurationService = GWT.create(WebConfigurationService.class); 044 String url = Window.Location.getHref(); 045 webConfigurationService.getWebConfiguration(url, new AsyncCallback<WebConfiguration>() { 046 public void onFailure(Throwable throwable) { 047 Log.debug("onFailure: " + throwable); 048 webConfiguration = WebConfiguration.DEFAULT_WEB_CONFIGURATION; 049 initModule(); 050 } 051 052 public void onSuccess(WebConfiguration result) { 053 webConfiguration = result == null ? WebConfiguration.DEFAULT_WEB_CONFIGURATION : result; 054 initModule(); 055 Log.debug("Module initialization finished."); 056 } 057 }); 058 } 059 060 private void initModule() { 061 AnnotationApplication.build(webConfiguration); 062 } 063 064 // Fix XMLHttpRequest when using Annotations module on IE6. 065 // XMLHttpRequest is defined in $wnd, but not in window (due to sarrisa 066 // librairy use in ajax4jsf) so GWT can't instantiate a XMLHttpRequest object. 067 private native void fixXMLHttpRequest() /*-{ 068 if ($wnd.XMLHttpRequest && !window.XMLHttpRequest) { 069 window.XMLHttpRequest = $wnd.XMLHttpRequest; 070 } 071 }-*/; 072 073}