001/*
002 *  Copyright 2016 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.runtime.plugins.admin.notificator;
017
018import org.apache.avalon.framework.configuration.Configurable;
019import org.apache.avalon.framework.configuration.Configuration;
020import org.apache.avalon.framework.configuration.ConfigurationException;
021
022import org.ametys.runtime.i18n.I18nizableText;
023import org.ametys.runtime.plugin.component.PluginAware;
024import org.ametys.runtime.plugins.admin.notificator.Notification.NotificationType;
025
026/**
027 * Abstract {@link AdministratorNotificator} which is {@link Configurable}.
028 */
029public abstract class AbstractConfigurableAdministratorNotificator implements AdministratorNotificator, Configurable, PluginAware
030{
031    /** The name of the plugin that has declared this component */
032    protected String _pluginName;
033    /** The type of the notifications */
034    protected NotificationType _type;
035    /** The glyph icon of the  notifications */
036    protected String _iconGlyph;
037    /** The i18n key of the title of the notifications */
038    protected I18nizableText _title;
039    /** The i18n key of the description of the notifications */
040    protected I18nizableText _message;
041    /** The client-side action of the notifications */
042    protected String _action;
043    
044    @Override
045    public void setPluginInfo(String pluginName, String featureName, String id)
046    {
047        _pluginName = pluginName;
048    }
049    
050    @Override
051    public void configure(Configuration configuration) throws ConfigurationException
052    {
053        _type = NotificationType.valueOf(configuration.getChild("type").getValue("warn").toUpperCase());
054        _iconGlyph = configuration.getChild("icon-glyph").getValue("");
055        
056        _title = I18nizableText.parseI18nizableText(configuration.getChild("title"), "plugin." + _pluginName);
057        _message = I18nizableText.parseI18nizableText(configuration.getChild("message"), "plugin." + _pluginName);
058        
059        _action = configuration.getChild("action").getValue("Ext.emptyFn");
060    }
061}