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.web.skin;
017
018import org.apache.avalon.framework.configuration.Configuration;
019import org.apache.avalon.framework.configuration.ConfigurationException;
020
021import org.ametys.cms.model.ElementDefinitionParser;
022import org.ametys.runtime.i18n.I18nizableText;
023import org.ametys.runtime.model.CategorizedElementDefinitionWrapper;
024import org.ametys.runtime.parameter.Validator;
025import org.ametys.runtime.plugin.component.ThreadSafeComponentManager;
026import org.ametys.web.data.type.ModelItemTypeExtensionPoint;
027
028/**
029 * Parser for {@link CategorizedElementDefinitionWrapper} parameter.
030 */
031public class SkinParameterParser extends ElementDefinitionParser
032{
033    private String _i18nCatalogueLocation;
034
035    /**
036     * Creates a categorized element definition parser for the skin.
037     * @param elementTypeExtensionPoint the extension point to use to get available element types
038     * @param enumeratorManager the enumerator component manager.
039     * @param validatorManager the validator component manager.
040     * @param i18nCatalogueLocation the path of the i18n folder of the skin
041     */
042    public SkinParameterParser(ModelItemTypeExtensionPoint elementTypeExtensionPoint,
043            ThreadSafeComponentManager<org.ametys.runtime.model.Enumerator> enumeratorManager, ThreadSafeComponentManager<Validator> validatorManager, String i18nCatalogueLocation)
044    {
045        super(elementTypeExtensionPoint, enumeratorManager, validatorManager);
046        _i18nCatalogueLocation = i18nCatalogueLocation;
047    }
048
049    @Override
050    protected String _getNameConfigurationAttribute()
051    {
052        return "id";
053    }
054    
055    @Override
056    protected I18nizableText _parseI18nizableText(Configuration config, String catalog, String name) throws ConfigurationException
057    {
058        return I18nizableText.parseI18nizableText(config.getChild(name), _i18nCatalogueLocation, "messages", null);
059    }
060}