001/*
002 *  Copyright 2011 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.plugins.artisteer.actions;
017
018import java.io.File;
019import java.io.IOException;
020
021import org.apache.commons.io.FileUtils;
022
023import org.ametys.web.skin.actions.UploadSkinAction;
024
025/**
026 * This action receive a form with the "importfile" zip file as an artisteer exported skin.
027 * Replace existing skin 
028 */
029public class UploadArtisteerSkinAction extends UploadSkinAction
030{
031    @Override
032    protected void _filter(File skinDir, String absoluteSkinPath, boolean isModel) throws IOException
033    {
034        super._filter(skinDir, absoluteSkinPath, isModel);
035        
036        File[] files = skinDir.listFiles();
037        for (File file : files)
038        {
039            if ("style.ie6.css".equals(file.getName())
040                   || "style.ie7.css".equals(file.getName())
041                   || "style.css".equals(file.getName())
042                   || "swfobject.js".equals(file.getName())
043                   || "container.swf".equals(file.getName())
044                   || "expressInstall.swf".equals(file.getName())
045                   || "images_artisteer".equals(file.getName()))
046            {
047                FileUtils.deleteQuietly(file);
048            }
049            else if ("images".equals(file.getAbsolutePath().substring(absoluteSkinPath.length() + 1)) && file.isDirectory())
050            {
051                FileUtils.moveDirectory(file, new File(skinDir, "resources/img"));
052            }
053            else if ("favicon.ico".equals(file.getName()) && !file.isDirectory())
054            {
055                if (new File(skinDir, "resources/img").exists())
056                {
057                    FileUtils.moveFile(file, new File(skinDir, "resources/img/favicon.ico"));
058                }
059                else
060                {
061                    FileUtils.moveFile(file, new File(skinDir, "images/favicon.ico"));
062                }
063            }
064        }
065    }
066}