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    private String _refModuleId;
043    
044    public void setPluginInfo(String pluginName, String featureName, String id)
045    {
046        _pluginName = pluginName;
047        _featureName = featureName;
048        _id = id;
049    }
050    
051    public void configure(Configuration configuration) throws ConfigurationException
052    {
053        _title = I18nizableText.parseI18nizableText(configuration.getChild("title"), "plugin." + _pluginName, "");
054        
055        Configuration urlConfiguration = configuration.getChild("searchUrl");
056        String pluginUrl = urlConfiguration.getAttribute("plugin", _pluginName);
057        _searchUrl = "_plugins/" + pluginUrl + "/" + urlConfiguration.getValue();
058        
059        Configuration limitConfiguration = configuration.getChild("limit");
060        _limit = limitConfiguration.getValueAsInteger();
061        
062        Configuration allModuleLimitConfiguration = configuration.getChild("minLimit", true);
063        _minLimit = allModuleLimitConfiguration.getValueAsInteger(_limit);
064        
065        Configuration orderConfiguration = configuration.getChild("order");
066        _order = orderConfiguration.getValueAsInteger();
067        
068        _refModuleId = configuration.getChild("refModuleId").getValue(null);
069        
070    }
071    
072    public String getId()
073    {
074        return _id;
075    }
076    
077    public I18nizableText getTitle()
078    {
079        return _title;
080    }
081
082    public String getSearchUrl()
083    {
084        return _searchUrl;
085    }
086
087    public int getLimit()
088    {
089        return _limit;
090    }
091
092    public int getMinLimit()
093    {
094        return _minLimit;
095    }
096
097    public int getOrder()
098    {
099        return _order;
100    }
101    
102    public String getReferenceModuleId()
103    {
104        return _refModuleId;
105    }
106}