001/* 002 * Copyright 2012 Anyware Services 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 */ 016package org.ametys.site; 017 018import java.io.File; 019import java.util.Map; 020 021import org.apache.avalon.framework.parameters.Parameters; 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.thread.ThreadSafe; 025import org.apache.cocoon.acting.ServiceableAction; 026import org.apache.cocoon.environment.Redirector; 027import org.apache.commons.io.FileUtils; 028 029/** 030 * Invalidates cached resources for a given skin. 031 */ 032public class InvalidateSkinAction extends ServiceableAction implements ThreadSafe 033{ 034 @Override 035 public void service(ServiceManager sManager) throws ServiceException 036 { 037 super.service(sManager); 038 } 039 040 @Override 041 public Map act(Redirector redirector, org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception 042 { 043 String skin = parameters.getParameter("skin"); 044 045 File root = SiteCacheHelper.getRootCache(); 046 File skinRoot = new File(root, "skins/" + skin); 047 048 if (skinRoot.exists()) 049 { 050 FileUtils.forceDelete(skinRoot); 051 052 if (getLogger().isInfoEnabled()) 053 { 054 getLogger().info("Invalidate cache for skin '" + skin + "'"); 055 } 056 } 057 058 return EMPTY_MAP; 059 } 060}