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.HashMap;
020import java.util.Map;
021
022import org.ametys.cms.repository.Content;
023import org.ametys.plugins.repository.AmetysRepositoryException;
024import org.ametys.plugins.repository.metadata.CompositeMetadata;
025import org.ametys.web.repository.page.Zone;
026import org.ametys.web.repository.page.ZoneItem;
027
028/**
029 * {@link ZoneItem} holding a Sitemap service
030 */
031public class TransitionalZoneItem implements ZoneItem
032{
033    private TransitionalPage _page;
034    
035    /**
036     * Constructor.
037     * @param page the parent {@link TransitionalPage}.
038     */
039    public TransitionalZoneItem(TransitionalPage page)
040    {
041        _page = page;
042    }
043    
044    @SuppressWarnings("unchecked")
045    @Override
046    public Content getContent() throws AmetysRepositoryException
047    {
048        throw new UnsupportedOperationException("getContent not supported on virtual degree pages");
049    }
050
051    @Override
052    public String getMetadataSetName() throws AmetysRepositoryException
053    {
054        return "main";
055    }
056    
057    @Override
058    public String getServiceId() throws AmetysRepositoryException
059    {
060        return "org.ametys.web.service.SitemapService";
061    }
062
063    @Override
064    public CompositeMetadata getServiceParameters() throws AmetysRepositoryException
065    {
066        Map<String, Object> params = new HashMap<>();
067        params.put("depth", new Long(1));
068        params.put("all", new Boolean(false));
069        params.put("includeInvisiblePage", new Boolean(true));
070        
071        return new StaticCompositeMetadata(params);
072    }
073
074    @Override
075    public ZoneType getType() throws AmetysRepositoryException
076    {
077        return ZoneType.SERVICE;
078    }
079
080    @Override
081    public Zone getZone()
082    {
083        return new TransitionalZone(_page);
084    }
085
086    @Override
087    public CompositeMetadata getMetadataHolder()
088    {
089        return new StaticCompositeMetadata();
090    }
091
092    @Override
093    public String getId() throws AmetysRepositoryException
094    {
095        return "udtransionalzoneitem://unused?pageId=" + _page.getId();
096    }
097
098    @Override
099    public String getName() throws AmetysRepositoryException
100    {
101        return "default";
102    }
103
104    @SuppressWarnings("unchecked")
105    @Override
106    public TransitionalZone getParent() throws AmetysRepositoryException
107    {
108        return new TransitionalZone(_page);
109    }
110
111    @Override
112    public String getParentPath() throws AmetysRepositoryException
113    {
114        return _page.getPath() + "/default";
115    }
116
117    @Override
118    public String getPath() throws AmetysRepositoryException
119    {
120        return _page.getPath() + "/default/default";
121    }
122}