001/* 002 * Copyright 2018 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.repository.model.parsing; 017 018import org.apache.avalon.framework.configuration.Configuration; 019import org.apache.avalon.framework.configuration.ConfigurationException; 020import org.apache.avalon.framework.service.ServiceManager; 021 022import org.ametys.plugins.repository.data.type.ModelItemTypeConstants; 023import org.ametys.plugins.repository.model.RepeaterDefinition; 024import org.ametys.runtime.model.AbstractModelItemParser; 025import org.ametys.runtime.model.ItemParserHelper; 026import org.ametys.runtime.model.Model; 027import org.ametys.runtime.model.ModelItem; 028import org.ametys.runtime.model.ModelItemGroup; 029import org.ametys.runtime.model.type.ModelItemType; 030import org.ametys.runtime.model.type.ModelItemTypeExtensionPoint; 031 032/** 033 * This class parses the repeater definition 034 */ 035public class RepeaterDefinitionParser extends AbstractModelItemParser 036{ 037 /** 038 * Creates a repeater definition parser. 039 * @param modelItemTypeExtensionPoint the extension point to use to get available model items types 040 */ 041 public RepeaterDefinitionParser(ModelItemTypeExtensionPoint modelItemTypeExtensionPoint) 042 { 043 super(modelItemTypeExtensionPoint); 044 } 045 046 @Override 047 @SuppressWarnings("unchecked") 048 public <T extends ModelItem> T parse(ServiceManager serviceManager, String pluginName, String catalog, Configuration definitionConfig, Model model, ModelItemGroup parent) throws ConfigurationException 049 { 050 RepeaterDefinition definition = (RepeaterDefinition) super.parse(serviceManager, pluginName, catalog, definitionConfig, model, parent); 051 052 definition.setAddLabel(_parseI18nizableText(definitionConfig, catalog, "add-label", "plugin.repository", "PLUGINS_REPOSITORY_REPEATER_DEFAULT_ADD_LABEL")); 053 definition.setDeleteLabel(_parseI18nizableText(definitionConfig, catalog, "del-label", "plugin.repository", "PLUGINS_REPOSITORY_REPEATER_DEFAULT_DELETE_LABEL")); 054 definition.setHeaderLabel(definitionConfig.getChild("header-label").getValue(null)); 055 definition.setInitialSize(definitionConfig.getAttributeAsInteger("initial-size", 0)); 056 definition.setMinSize(definitionConfig.getAttributeAsInteger("min-size", 0)); 057 definition.setMaxSize(definitionConfig.getAttributeAsInteger("max-size", -1)); 058 059 return (T) definition; 060 } 061 062 @Override 063 protected RepeaterDefinition _createModelItem(Configuration itemConfig) throws ConfigurationException 064 { 065 return new RepeaterDefinition(); 066 } 067 068 @Override 069 protected String _parseName(Configuration itemConfig) throws ConfigurationException 070 { 071 return ItemParserHelper.parseName(itemConfig, _getNameConfigurationAttribute(), false); 072 } 073 074 @Override 075 protected ModelItemType _parseType(Configuration config) throws ConfigurationException 076 { 077 return _modelItemTypeExtensionPoint.getExtension(ModelItemTypeConstants.REPEATER_TYPE_ID); 078 } 079}