001/*
002 *  Copyright 2017 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.contenttypeseditor;
017
018import java.io.File;
019import java.util.Collections;
020import java.util.List;
021import java.util.Map;
022
023import org.ametys.core.ui.StaticClientSideElement;
024
025import net.sourceforge.plantuml.cucadiagram.dot.ExeState;
026import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
027
028/**
029 * This implementation creates an element from a PlantUML configuration
030 */
031public class PlantUMLClientSideElement extends StaticClientSideElement
032{
033
034    @Override
035    public List<Script> getScripts(boolean ignoreRights, Map<String, Object> contextParameters)
036    {
037        List<Script> scripts = super.getScripts(ignoreRights, contextParameters);
038        
039        if (scripts.size() == 1)
040        {
041            File dotExe = GraphvizUtils.getDotExe();
042            ExeState exeState = ExeState.checkFile(dotExe);
043            if (exeState != ExeState.OK)
044            {
045                Script script = new Script(scripts.get(0));
046                script.getParameters().put("disabled", "true");
047                return Collections.singletonList(script);       
048            }
049        }
050        
051        return scripts;
052    }
053
054}