001/* 002 * Copyright 2022 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.properties; 017 018import java.util.ArrayList; 019import java.util.List; 020 021import org.apache.avalon.framework.configuration.Configuration; 022import org.apache.avalon.framework.configuration.ConfigurationException; 023 024import org.ametys.cms.model.properties.ElementRefProperty; 025import org.ametys.cms.model.properties.Property; 026import org.ametys.cms.repository.Content; 027import org.ametys.runtime.model.Enumerator; 028 029/** 030 * {@link Property} referencing multiple values in one property. 031 * @param <T> Type of the element value 032 */ 033public abstract class AbstractMultiValuesProperty<T> extends ElementRefProperty<T, Content> 034{ 035 /** The attribute paths. */ 036 protected List<String> _attributePaths; 037 038 @Override 039 protected void configureReferencedElementPath(Configuration configuration) throws ConfigurationException 040 { 041 _attributePaths = new ArrayList<>(); 042 for (Configuration attributeConf : configuration.getChildren("attribute")) 043 { 044 _attributePaths.add(attributeConf.getAttribute("path")); 045 } 046 047 if (!_attributePaths.isEmpty()) 048 { 049 setElementPath(_attributePaths.get(0)); 050 } 051 else 052 { 053 throw new ConfigurationException("The property '" + getName() + "' has to reference at least one attribute", configuration); 054 055 } 056 } 057 058 @Override 059 public boolean isMultiple() 060 { 061 return true; 062 } 063 064 @Override 065 public Enumerator<T> getEnumerator() 066 { 067 // There is no sense to retrieve the enumerator of the first referenced attribute -> it could lead to errors 068 return null; 069 } 070}