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.metadata.CompositeMetadata;
022import org.ametys.web.repository.page.Zone;
023import org.ametys.web.repository.page.ZoneItem;
024
025/**
026 * {@link ZoneItem} holding a content.
027 */
028public class UserZoneItem implements ZoneItem
029{
030    private UserPage _page;
031    
032    /**
033     * Constructor.
034     * @param page the parent {@link UserPage}.
035     */
036    public UserZoneItem(UserPage page)
037    {
038        _page = page;
039    }
040    
041    /**
042     * Compute the zone item id of a content for a page 
043     * @param pageId The page id
044     * @return The zoneitem id
045     */
046    public static String getZoneItemId(String pageId)
047    {
048        return "uduserzoneitem://unused?pageId=" + pageId;
049    }
050    
051    @SuppressWarnings("unchecked")
052    @Override
053    public Content getContent() throws AmetysRepositoryException
054    {
055        Content content = _page.getSyncContent();
056        return content;
057    }
058
059    @Override
060    public String getMetadataSetName() throws AmetysRepositoryException
061    {
062        return "main";
063    }
064    
065    @Override
066    public String getServiceId() throws AmetysRepositoryException
067    {
068        throw new UnsupportedOperationException("getServiceId not supported on virtual user directory pages");
069    }
070
071    @Override
072    public CompositeMetadata getServiceParameters() throws AmetysRepositoryException
073    {
074        throw new UnsupportedOperationException("getServiceParameters not supported on virtual user directory pages");
075    }
076
077    @Override
078    public ZoneType getType() throws AmetysRepositoryException
079    {
080        return ZoneType.CONTENT;
081    }
082
083    @Override
084    public Zone getZone()
085    {
086        return new UserZone(_page);
087    }
088
089    @Override
090    public CompositeMetadata getMetadataHolder()
091    {
092        return new StaticCompositeMetadata();
093    }
094
095    @Override
096    public String getId() throws AmetysRepositoryException
097    {
098        return getZoneItemId(_page.getId());
099    }
100
101    @Override
102    public String getName() throws AmetysRepositoryException
103    {
104        return "default";
105    }
106
107    @SuppressWarnings("unchecked")
108    @Override
109    public UserZone getParent() throws AmetysRepositoryException
110    {
111        return new UserZone(_page);
112    }
113
114    @Override
115    public String getParentPath() throws AmetysRepositoryException
116    {
117        return _page.getPath() + "/default";
118    }
119
120    @Override
121    public String getPath() throws AmetysRepositoryException
122    {
123        return _page.getPath() + "/default/default";
124    }
125}