001/* 002 * (C) Copyright 2012 Nuxeo SA (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 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.ui.web.reload; 018 019import java.util.ResourceBundle; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions; 024import org.nuxeo.runtime.api.Framework; 025import org.nuxeo.runtime.reload.ReloadEventNames; 026import org.nuxeo.runtime.services.event.Event; 027import org.nuxeo.runtime.services.event.EventListener; 028 029/** 030 * Handler for hot reload features. 031 * <p> 032 * Hot reload features should be enabled only if the application is in a "debug" mode, as some reloading can hurt a 033 * server in production (when altering document types declared on the platform, resetting caches, etc...) 034 * <p> 035 * Note that some hot reload features cannot be handled without additional debug configurations to be available (like 036 * the seam debug jar for instance). 037 * <p> 038 * This reload handler is supposed to handle at least (or most of) features used in Studio. 039 * 040 * @since 5.6 041 */ 042public class NuxeoJSFReloadHandler implements EventListener { 043 044 private static final Log log = LogFactory.getLog(NuxeoJSFReloadHandler.class); 045 046 @Override 047 public boolean aboutToHandleEvent(Event event) { 048 return true; 049 } 050 051 @Override 052 public void handleEvent(Event event) { 053 if (!Framework.isDevModeSet()) { 054 log.info("Do not flush the JSF application: debug mode is not set"); 055 return; 056 } 057 String id = event.getId(); 058 if (ReloadEventNames.FLUSH_EVENT_ID.equals(id)) { 059 // force i18n messages reload at the bundle level 060 ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader()); 061 // force reload of document default views. 062 DocumentModelFunctions.resetDefaultViewCache(); 063 } 064 } 065 066}