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 java.util.ArrayList;
020
021import org.ametys.plugins.repository.AmetysObjectIterable;
022import org.ametys.plugins.repository.AmetysRepositoryException;
023import org.ametys.plugins.repository.CollectionIterable;
024import org.ametys.plugins.repository.metadata.CompositeMetadata;
025import org.ametys.web.repository.page.Page;
026import org.ametys.web.repository.page.Zone;
027import org.ametys.web.repository.page.ZoneItem;
028
029/**
030 * {@link Zone} holding a sitemap.
031 */
032public class TransitionalZone implements Zone
033{
034    private TransitionalPage _page;
035    
036    /**
037     * Constructor
038     * @param page the parent {@link TransitionalPage}.
039     */
040    public TransitionalZone(TransitionalPage page)
041    {
042        _page = page;
043    }
044    
045    @Override
046    public Page getPage()
047    {
048        return _page;
049    }
050
051    @Override
052    public AmetysObjectIterable<? extends ZoneItem> getZoneItems() throws AmetysRepositoryException
053    {
054        ArrayList<ZoneItem> zoneItems = new ArrayList<>();
055        zoneItems.add(new TransitionalZoneItem(_page));
056        return new CollectionIterable<>(zoneItems);
057    }
058
059    @Override
060    public CompositeMetadata getMetadataHolder()
061    {
062        return new StaticCompositeMetadata();
063    }
064
065    @Override
066    public String getId() throws AmetysRepositoryException
067    {
068        return "udtransitionalzone://unused?pageId=" + _page.getId();
069    }
070
071    @Override
072    public String getName() throws AmetysRepositoryException
073    {
074        return "default";
075    }
076
077    @SuppressWarnings("unchecked")
078    @Override
079    public Page getParent() throws AmetysRepositoryException
080    {
081        return _page;
082    }
083
084    @Override
085    public String getParentPath() throws AmetysRepositoryException
086    {
087        return _page.getPath();
088    }
089
090    @Override
091    public String getPath() throws AmetysRepositoryException
092    {
093        return _page.getPath() + "/default";
094    }
095}