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.config; 017 018import org.apache.avalon.framework.configuration.Configuration; 019import org.apache.avalon.framework.configuration.ConfigurationException; 020 021import org.ametys.runtime.i18n.I18nizableText; 022import org.ametys.runtime.model.ItemParserHelper; 023import org.ametys.runtime.model.ItemParserHelper.ConfigurationAndPluginName; 024import org.ametys.runtime.model.checker.ItemChecker; 025import org.ametys.runtime.model.checker.ItemCheckerParser; 026import org.ametys.runtime.plugin.component.ThreadSafeComponentManager; 027 028/** 029 * Parameter checker parser for configuration parameters 030 */ 031public class ConfigParameterCheckerParser extends ItemCheckerParser 032{ 033 /** 034 * Instantiate a configuration parameter checker parser 035 * @param paramCheckerManager the parameter checker. 036 */ 037 public ConfigParameterCheckerParser(ThreadSafeComponentManager<ItemChecker> paramCheckerManager) 038 { 039 super(paramCheckerManager); 040 } 041 042 /** 043 * Parse a configuration parameter checker from an XML configuration. 044 * @param pluginName the plugin's name declaring this parameter. 045 * @param paramCheckerConfig the XML configuration. 046 * @return the {@link ConfigParameterCheckerDescriptor} for the parsed configuration parameter checker 047 * @throws ConfigurationException if the configuration is not valid. 048 */ 049 @Override 050 public ConfigParameterCheckerDescriptor parseParameterChecker(String pluginName, Configuration paramCheckerConfig) throws ConfigurationException 051 { 052 ConfigParameterCheckerDescriptor configParamChecker = (ConfigParameterCheckerDescriptor) super.parseParameterChecker(pluginName, paramCheckerConfig); 053 054 Configuration uiRefConfig = paramCheckerConfig.getChild("ui-ref"); 055 056 String uiRefParamId = null; 057 Configuration uiRefParamConfig = uiRefConfig.getChild("param-ref", false); 058 if (uiRefParamConfig != null) 059 { 060 uiRefParamId = uiRefParamConfig.getAttribute("id"); 061 } 062 063 I18nizableText uiRefGroup = null; 064 Configuration uiRefGroupConfig = uiRefConfig.getChild("group", false); 065 if (uiRefGroupConfig != null) 066 { 067 uiRefGroup = ItemParserHelper.parseI18nizableText(new ConfigurationAndPluginName(uiRefConfig, pluginName), "group"); 068 } 069 070 I18nizableText uiRefCategory = null; 071 Configuration uiRefCategoryConfig = uiRefConfig.getChild("category", false); 072 if (uiRefCategoryConfig != null) 073 { 074 uiRefCategory = ItemParserHelper.parseI18nizableText(new ConfigurationAndPluginName(uiRefConfig, pluginName), "category"); 075 } 076 077 configParamChecker.setUiRefParamPath(uiRefParamId); 078 configParamChecker.setUiRefGroup(uiRefGroup); 079 configParamChecker.setUiRefCategory(uiRefCategory); 080 081 return configParamChecker; 082 } 083 084 @Override 085 protected ConfigParameterCheckerDescriptor _getParameterCheckerDescriptorInstance() 086 { 087 return new ConfigParameterCheckerDescriptor(); 088 } 089}