001/* 002 * Copyright 2019 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.contenttype; 017 018import java.util.Collections; 019import java.util.HashSet; 020import java.util.Set; 021 022import org.apache.avalon.framework.component.Component; 023import org.apache.avalon.framework.configuration.Configuration; 024import org.apache.avalon.framework.configuration.ConfigurationException; 025 026import org.ametys.runtime.plugin.ExtensionPoint; 027import org.ametys.runtime.plugin.component.AbstractLogEnabled; 028 029/** 030 * List of the reserved words that cannot not be used as an attribute name 031 */ 032public class ContentTypeReservedAttributeNameExtensionPoint extends AbstractLogEnabled implements ExtensionPoint<String>, Component 033{ 034 /** The component role */ 035 public static final String ROLE = ContentTypeReservedAttributeNameExtensionPoint.class.getName(); 036 037 /** The forbidden keywords */ 038 protected Set<String> _reservedNames = new HashSet<>(); 039 040 public void addExtension(String id, String pluginName, String featureName, Configuration configuration) throws ConfigurationException 041 { 042 for (Configuration nameConfiguration : configuration.getChildren("name")) 043 { 044 try 045 { 046 _reservedNames.add(nameConfiguration.getValue()); 047 } 048 catch (ConfigurationException e) 049 { 050 getLogger().warn("Ignoring the reserved word configuration", e); 051 } 052 } 053 } 054 055 public void initializeExtensions() throws Exception 056 { 057 // Nothing 058 } 059 060 public boolean hasExtension(String id) 061 { 062 return _reservedNames.contains(id); 063 } 064 065 public String getExtension(String id) 066 { 067 return hasExtension(id) ? id : null; 068 } 069 070 public Set<String> getExtensionsIds() 071 { 072 return Collections.unmodifiableSet(_reservedNames); 073 } 074}