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.cms.content.external;
017
018import java.util.HashSet;
019import java.util.Set;
020
021import org.ametys.cms.repository.Content;
022import org.ametys.plugins.repository.data.external.ExternalizableDataProviderExtensionPoint;
023import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
024
025/**
026 * Extension point for {@link ExternalizableMetadataProvider}s.
027 * @deprecated Use {@link ExternalizableDataProviderExtensionPoint} instead
028 */
029@Deprecated
030public class ExternalizableMetadataProviderExtensionPoint extends AbstractThreadSafeComponentExtensionPoint<ExternalizableMetadataProvider>
031{
032    /** Avalon Role */
033    public static final String ROLE = ExternalizableMetadataProviderExtensionPoint.class.getName();
034    
035    /**
036     * Get the path of metadata that can be valued externally or locally by a {@link ExternalizableMetadataProvider}
037     * @param content The content
038     * @return The path of external or local metadata
039     */
040    public Set<String> getExternalAndLocalMetadata (Content content)
041    {
042        Set<String> metadataPaths = new HashSet<>();
043        
044        for (String id : getExtensionsIds())
045        {
046            ExternalizableMetadataProvider provider = getExtension(id);
047            
048            for (String metadataPath : provider.getExternalAndLocalMetadata(content))
049            {
050                if (metadataPaths.contains(metadataPath))
051                {
052                    throw new UnsupportedOperationException("The metadata of path " + metadataPath + " is already handled by a externalisable metadata provider");
053                }
054                metadataPaths.add(metadataPath);
055            }
056        }
057        return metadataPaths;
058    }
059    
060}