001/*
002 *  Copyright 2012 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.core.cocoon;
018
019import java.util.HashSet;
020import java.util.Set;
021
022import org.apache.avalon.framework.configuration.Configuration;
023import org.apache.avalon.framework.configuration.ConfigurationException;
024
025import org.ametys.runtime.plugin.AbstractExtensionPoint;
026
027/**
028 * This extension point allows to configure the xhtml serializer by adding new plugins
029 */
030public class XHTMLSerializerExtensionPoint extends AbstractExtensionPoint<String>
031{
032    /** The avalon role */
033    public static final String ROLE = XHTMLSerializerExtensionPoint.class.getName(); 
034    
035    private Set<String> _allowedNamespaces;
036    
037    @Override
038    public void addExtension(String id, String pluginName, String featureName, Configuration configuration) throws ConfigurationException
039    {
040        String namespace = configuration.getChild("namespace-allowed").getValue("");
041        _extensions.put(id, namespace);
042        
043        if (getLogger().isDebugEnabled())
044        {
045            getLogger().debug("Adding namespace '" + namespace + "' from '" + pluginName + "/" + featureName + "/" + id + "'.");
046        }
047    }
048
049    @Override
050    public void initializeExtensions() throws Exception
051    {
052        _allowedNamespaces = new HashSet<>(_extensions.values());
053    }
054    
055    /**
056     * Get the list of allowed namespace
057     * @return The non null list of namespaces
058     */
059    public Set<String> getAllowedNamespaces()
060    {
061        return _allowedNamespaces;
062    }
063}