001/*
002 *  Copyright 2020 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 */
016
017package org.ametys.plugins.workspaces.search;
018
019import org.apache.avalon.framework.configuration.Configurable;
020import org.apache.avalon.framework.configuration.Configuration;
021import org.apache.avalon.framework.configuration.ConfigurationException;
022
023import org.ametys.runtime.i18n.I18nizableText;
024import org.ametys.runtime.plugin.component.PluginAware;
025
026/**
027 * Static implementation of a {@link SearchModule}
028 */
029public class StaticSearchModule implements SearchModule, Configurable, PluginAware
030{
031    /** The plugin name */
032    protected String _pluginName;
033    /** The feature name */
034    protected String _featureName;
035    
036    private String _id;
037    private I18nizableText _title;
038    private String _searchUrl;
039    private int _limit;
040    private int _minLimit;
041    private int _order;
042    
043    public void setPluginInfo(String pluginName, String featureName, String id)
044    {
045        _pluginName = pluginName;
046        _featureName = featureName;
047        _id = id;
048    }
049    
050    public void configure(Configuration configuration) throws ConfigurationException
051    {
052        _title = I18nizableText.parseI18nizableText(configuration.getChild("title"), "plugin." + _pluginName, "");
053        
054        Configuration urlConfiguration = configuration.getChild("searchUrl");
055        String pluginUrl = urlConfiguration.getAttribute("plugin", _pluginName);
056        _searchUrl = "_plugins/" + pluginUrl + "/" + urlConfiguration.getValue();
057        
058        Configuration limitConfiguration = configuration.getChild("limit");
059        _limit = limitConfiguration.getValueAsInteger();
060        
061        Configuration allModuleLimitConfiguration = configuration.getChild("minLimit", true);
062        _minLimit = allModuleLimitConfiguration.getValueAsInteger(_limit);
063        
064        Configuration orderConfiguration = configuration.getChild("order");
065        _order = orderConfiguration.getValueAsInteger();
066    }
067    
068    public String getId()
069    {
070        return _id;
071    }
072    
073    public I18nizableText getTitle()
074    {
075        return _title;
076    }
077
078    public String getSearchUrl()
079    {
080        return _searchUrl;
081    }
082
083    public int getLimit()
084    {
085        return _limit;
086    }
087
088    public int getMinLimit()
089    {
090        return _minLimit;
091    }
092
093    public int getOrder()
094    {
095        return _order;
096    }
097}