001/*
002  *  Copyright 2010 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.repository.page;
017
018import org.ametys.cms.repository.Content;
019import org.ametys.plugins.repository.AmetysRepositoryException;
020import org.ametys.plugins.repository.data.ametysobject.ModelLessDataAwareAmetysObject;
021import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
022
023/**
024 * A {@link ZoneItem} is an ordered part of {@link Zone}
025 * It can be a content ref or a service
026 */
027public interface ZoneItem extends ModelLessDataAwareAmetysObject
028{
029    /** Constant for the name of the data containing the service parameters. */
030    public static final String SERVICE_PARAMETERS_DATA_NAME = "service_parameters";
031    
032    /** Type of an zone. */
033    public enum ZoneType
034    {
035        /** Content zone. */
036        CONTENT,
037        /** Service zone. */
038        SERVICE
039    }
040    
041    /**
042     * Retrieves the type.<br>
043     * @return the type.
044     * @throws AmetysRepositoryException if an error occurs.
045     * @see ZoneType
046     */
047    public ZoneType getType() throws AmetysRepositoryException;
048
049    /**
050     * Retrieves the content reference.
051     * @param <C> the actual type of {@link Content}.
052     * @return the service id.
053     * @throws AmetysRepositoryException if an error occurs.
054     */
055    public <C extends Content> C getContent() throws AmetysRepositoryException;
056
057    /**
058     * Get the name of the metadata set to render the Content with. It only makes sense if the ZoneItem is a Content reference.<br>
059     * If null is returned, in most cases, "main" should be assumed.
060     * @return the metadata set name, or null if not set.
061     * @throws AmetysRepositoryException if an error occurs.
062     * @deprecated Use {@link #getViewName()} instead
063     */
064    @Deprecated
065    public String getMetadataSetName() throws AmetysRepositoryException;
066    
067    /**
068     * Get the name of the view to render the Content with. It only makes sense if the ZoneItem is a Content reference.<br>
069     * If null is returned, in most cases, "main" should be assumed.
070     * @return the view name, or null if not set.
071     * @throws AmetysRepositoryException if an error occurs.
072     * TODO NEWATTRIBUTEAPI_SERVICE: remove the default implementation when all zone items implement the method
073     */
074    public default String getViewName() throws AmetysRepositoryException
075    {
076        throw new UnsupportedOperationException();
077    }
078    
079    /**
080     * Retrieves the service id.
081     * @return the service id.
082     * @throws AmetysRepositoryException if an error occurs.
083     */
084    public String getServiceId() throws AmetysRepositoryException;
085
086    /**
087     * Get the service parameters
088     * @return the service parameters
089     * @throws AmetysRepositoryException if an error occurs.
090     */
091    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException;
092    
093    /**
094     * Get the parent zone.
095     * @return the parent zone of the zone item. cannot be null
096     */
097    public Zone getZone();
098}