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 view 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 view name, or null if not set.
061     * @throws AmetysRepositoryException if an error occurs.
062     * TODO NEWATTRIBUTEAPI_SERVICE: remove the default implementation when all zone items implement the method
063     */
064    public default String getViewName() throws AmetysRepositoryException
065    {
066        throw new UnsupportedOperationException();
067    }
068    
069    /**
070     * Retrieves the service id.
071     * @return the service id.
072     * @throws AmetysRepositoryException if an error occurs.
073     */
074    public String getServiceId() throws AmetysRepositoryException;
075
076    /**
077     * Get the service parameters
078     * @return the service parameters
079     * @throws AmetysRepositoryException if an error occurs.
080     */
081    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException;
082    
083    /**
084     * Get the view parameters
085     * @return the view parameters
086     * @throws AmetysRepositoryException if an error occurs.
087     */
088    public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException;
089    
090    /**
091     * Get the parent zone.
092     * @return the parent zone of the zone item. cannot be null
093     */
094    public Zone getZone();
095
096    /**
097     * Get the content view parameters for a given view
098     * @param contentViewName the view name
099     * @return the content view parameters
100     * @throws AmetysRepositoryException if an error occurs.
101     */
102    public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException;
103    
104    /**
105     * Get the service view parameters for a given view
106     * @param serviceViewName the view name
107     * @return the service view parameters
108     * @throws AmetysRepositoryException if an error occurs.
109     */
110    public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException;
111}