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 */
016
017package org.ametys.plugins.odfweb.repository;
018
019import java.util.HashMap;
020import java.util.Map;
021
022import org.ametys.odf.program.Program;
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 FirstLevelZoneItem implements ZoneItem
032{
033    private FirstLevelPage _page;
034    
035    /**
036     * Constructor.
037     * @param page the parent {@link FirstLevelPage}.
038     */
039    public FirstLevelZoneItem(FirstLevelPage page)
040    {
041        _page = page;
042    }
043    
044    @SuppressWarnings("unchecked")
045    @Override
046    public Program 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(2));
068        params.put("all", new Boolean(false));
069        
070        return new StaticCompositeMetadata(params);
071    }
072
073    @Override
074    public ZoneType getType() throws AmetysRepositoryException
075    {
076        return ZoneType.SERVICE;
077    }
078
079    @Override
080    public Zone getZone()
081    {
082        return new FirstLevelZone(_page);
083    }
084
085    @Override
086    public CompositeMetadata getMetadataHolder()
087    {
088        return new StaticCompositeMetadata();
089    }
090
091    @Override
092    public String getId() throws AmetysRepositoryException
093    {
094        return "odfLevel1ZoneItem://unused?pageId=" + _page.getId();
095    }
096
097    @Override
098    public String getName() throws AmetysRepositoryException
099    {
100        return "default";
101    }
102
103    @SuppressWarnings("unchecked")
104    @Override
105    public FirstLevelZone getParent() throws AmetysRepositoryException
106    {
107        return new FirstLevelZone(_page);
108    }
109
110    @Override
111    public String getParentPath() throws AmetysRepositoryException
112    {
113        return _page.getPath() + "/default";
114    }
115
116    @Override
117    public String getPath() throws AmetysRepositoryException
118    {
119        return _page.getPath() + "/default/default";
120    }
121}