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 */
016
017package org.ametys.plugins.userdirectory.page;
018
019import org.ametys.cms.repository.Content;
020import org.ametys.plugins.repository.AmetysRepositoryException;
021import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
022import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
023import org.ametys.plugins.repository.data.holder.impl.DefaultModelLessDataHolder;
024import org.ametys.plugins.repository.data.repositorydata.RepositoryData;
025import org.ametys.plugins.repository.data.repositorydata.impl.MemoryRepositoryData;
026import org.ametys.plugins.repository.data.type.RepositoryModelItemType;
027import org.ametys.runtime.plugin.component.AbstractThreadSafeComponentExtensionPoint;
028import org.ametys.web.repository.page.Zone;
029import org.ametys.web.repository.page.ZoneItem;
030
031/**
032 * {@link ZoneItem} holding a content.
033 */
034public class UserZoneItem implements ZoneItem
035{
036    private UserPage _page;
037    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneDataTypeExtensionPoint;
038    private AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> _zoneItemDataTypeExtensionPoint;
039    
040    /**
041     * Constructor.
042     * @param page the parent {@link UserPage}.
043     * @param zoneDataTypeExtensionPoint the extension point with available data types for zones
044     * @param zoneItemDataTypeExtensionPoint the extension point with available data types for zone items
045     */
046    public UserZoneItem(UserPage page, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneDataTypeExtensionPoint, AbstractThreadSafeComponentExtensionPoint<RepositoryModelItemType> zoneItemDataTypeExtensionPoint)
047    {
048        _page = page;
049        _zoneDataTypeExtensionPoint = zoneDataTypeExtensionPoint;
050        _zoneItemDataTypeExtensionPoint = zoneItemDataTypeExtensionPoint;
051    }
052    
053    /**
054     * Compute the zone item id of a content for a page 
055     * @param pageId The page id
056     * @return The zoneitem id
057     */
058    public static String getZoneItemId(String pageId)
059    {
060        return "uduserzoneitem://unused?pageId=" + pageId;
061    }
062    
063    @SuppressWarnings("unchecked")
064    @Override
065    public Content getContent() throws AmetysRepositoryException
066    {
067        Content content = _page.getSyncContent();
068        return content;
069    }
070
071    public String getViewName() throws AmetysRepositoryException
072    {
073        return "main";
074    }
075    
076    @Override
077    public String getServiceId() throws AmetysRepositoryException
078    {
079        throw new UnsupportedOperationException("getServiceId not supported on virtual user directory pages");
080    }
081
082    public ModelAwareDataHolder getServiceParameters() throws AmetysRepositoryException
083    {
084        throw new UnsupportedOperationException("getServiceParameters not supported on virtual user directory pages");
085    }
086
087    @Override
088    public ZoneType getType() throws AmetysRepositoryException
089    {
090        return ZoneType.CONTENT;
091    }
092
093    @Override
094    public Zone getZone()
095    {
096        return new UserZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
097    }
098
099    public ModelLessDataHolder getDataHolder()
100    {
101        RepositoryData repositoryData = new MemoryRepositoryData(Zone.ZONEITEM_DATA_NAME);
102        return new DefaultModelLessDataHolder(_zoneItemDataTypeExtensionPoint, repositoryData);
103    }
104
105    @Override
106    public String getId() throws AmetysRepositoryException
107    {
108        return getZoneItemId(_page.getId());
109    }
110
111    @Override
112    public String getName() throws AmetysRepositoryException
113    {
114        return "default";
115    }
116
117    @SuppressWarnings("unchecked")
118    @Override
119    public UserZone getParent() throws AmetysRepositoryException
120    {
121        return new UserZone(_page, _zoneDataTypeExtensionPoint, _zoneItemDataTypeExtensionPoint);
122    }
123
124    @Override
125    public String getParentPath() throws AmetysRepositoryException
126    {
127        return _page.getPath() + "/default";
128    }
129
130    @Override
131    public String getPath() throws AmetysRepositoryException
132    {
133        return _page.getPath() + "/default/default";
134    }
135
136    public ModelAwareDataHolder getZoneItemParametersHolder() throws AmetysRepositoryException
137    {
138        return null;
139    }
140
141    public ModelAwareDataHolder getContentViewParametersHolder(String contentViewName) throws AmetysRepositoryException
142    {
143        return null;
144    }
145
146    public ModelAwareDataHolder getServiceViewParametersHolder(String serviceViewName) throws AmetysRepositoryException
147    {
148        return null;
149    }
150}