001/*
002 *  Copyright 2019 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.odfpilotage.report.consistency;
017
018import org.apache.avalon.framework.configuration.Configurable;
019import org.apache.avalon.framework.configuration.Configuration;
020import org.apache.avalon.framework.configuration.ConfigurationException;
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023import org.apache.avalon.framework.service.Serviceable;
024
025import org.ametys.odf.ODFHelper;
026import org.ametys.runtime.i18n.I18nizableText;
027import org.ametys.runtime.plugin.component.PluginAware;
028
029/**
030 * The abstract class for {@link ConsistencyAnalysis} which parse the ID, label and short ID.
031 */
032public abstract class AbstractConsistencyAnalysis implements ConsistencyAnalysis, Configurable, Serviceable, PluginAware
033{
034    /** Plugin name. */
035    protected String _pluginName;
036    
037    /** Analysis complete id. */
038    protected String _id;
039    
040    /** Analysis short id. */
041    protected String _shortId;
042    
043    /** Label. */
044    protected I18nizableText _label;
045    
046    /** Description. */
047    protected I18nizableText _description;
048    
049    /** Priority. */
050    protected int _priority;
051
052    /** The ODF helper. */
053    protected ODFHelper _odfHelper;
054    
055    @Override
056    public void service(ServiceManager manager) throws ServiceException
057    {
058        // Needed in almost all analyses
059        _odfHelper = (ODFHelper) manager.lookup(ODFHelper.ROLE);
060    }
061    
062    @Override
063    public void setPluginInfo(String pluginName, String featureName, String id)
064    {
065        _pluginName = pluginName;
066        _id = id;
067    }
068
069    @Override
070    public void configure(Configuration configuration) throws ConfigurationException
071    {
072        _label = I18nizableText.parseI18nizableText(configuration.getChild("label"), "plugin." + _pluginName);
073        _description = I18nizableText.parseI18nizableText(configuration.getChild("description"), "plugin." + _pluginName);
074        _shortId = configuration.getChild("shortId").getValue();
075        _priority = configuration.getChild("priority").getValueAsInteger(50);
076    }
077    
078    @Override
079    public String getId()
080    {
081        return _id;
082    }
083    
084    @Override
085    public I18nizableText getLabel()
086    {
087        return _label;
088    }
089
090    @Override
091    public I18nizableText getDescription()
092    {
093        return _description;
094    }
095    
096    @Override
097    public String getShortId()
098    {
099        return _shortId;
100    }
101
102    @Override
103    public int getPriority()
104    {
105        return _priority;
106    }
107}