001/*
002 *  Copyright 2019 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 */
016package org.ametys.plugins.odfweb.repository;
017
018import java.util.Collections;
019import java.util.Set;
020
021import org.apache.commons.lang.StringUtils;
022
023import org.ametys.plugins.explorer.resources.ResourceCollection;
024import org.ametys.plugins.repository.AmetysObject;
025import org.ametys.plugins.repository.AmetysObjectIterable;
026import org.ametys.plugins.repository.AmetysRepositoryException;
027import org.ametys.plugins.repository.EmptyIterable;
028import org.ametys.plugins.repository.UnknownAmetysObjectException;
029import org.ametys.plugins.repository.data.holder.ModelAwareDataHolder;
030import org.ametys.plugins.repository.data.holder.ModelLessDataHolder;
031import org.ametys.web.repository.page.Page;
032import org.ametys.web.repository.page.UnknownZoneException;
033import org.ametys.web.repository.page.Zone;
034import org.ametys.web.repository.site.Site;
035import org.ametys.web.repository.sitemap.Sitemap;
036
037/**
038 * This class is used for legacy purpose only
039 * Old program's page's name is built with program's title and program's name such as 'master-droits-program-fruai1452h45g81'.
040 * For program page requested with a name such as 'master-droits-program-fruai1452h45g81', a page of redirection will be served
041 * to the new program's page url built with program's title and program's code such as 'master-droits-H45G81'.
042 */
043public class RedirectPage implements Page
044{
045    private Page _page;
046
047    /**
048     * Constructor for redirect page to a {@link Page} for legacy purpose
049     * @param page the program or course page
050     */
051    public RedirectPage(Page page)
052    {
053        _page = page;
054    }
055    
056    /**
057     * Returns the wrapped {@link Page}.
058     * @return the wrapped page
059     */
060    public Page getRedirectPage()
061    {
062        return _page;
063    }
064    
065    public PageType getType() throws AmetysRepositoryException
066    {
067        return PageType.LINK;
068    }
069    
070    public String getURL() throws AmetysRepositoryException
071    {
072        return _page.getId();
073    }
074
075    public LinkType getURLType() throws AmetysRepositoryException
076    {
077        return LinkType.PAGE;
078    }
079
080    public Sitemap getSitemap() throws AmetysRepositoryException
081    {
082        return _page.getSitemap();
083    }
084
085    public String getSitemapName() throws AmetysRepositoryException
086    {
087        return _page.getSitemapName();
088    }
089
090    public String getPathInSitemap() throws AmetysRepositoryException
091    {
092        return getParent().getPathInSitemap() + "/" + getName();
093    }
094
095    public AmetysObjectIterable< ? extends Page> getChildrenPages() throws AmetysRepositoryException
096    {
097        return new EmptyIterable<>();
098    }
099
100    public AmetysObjectIterable< ? extends Page> getChildrenPages(boolean includeInvisiblePages) throws AmetysRepositoryException
101    {
102        return new EmptyIterable<>();
103    }
104
105    public Page getChildPageAt(int index) throws UnknownAmetysObjectException, AmetysRepositoryException
106    {
107        return null;
108    }
109
110    public <A extends AmetysObject> AmetysObjectIterable<A> getChildren() throws AmetysRepositoryException
111    {
112        return new EmptyIterable<>();
113    }
114
115    public boolean hasChild(String name) throws AmetysRepositoryException
116    {
117        return false;
118    }
119
120    public <A extends AmetysObject> A getChild(String path) throws AmetysRepositoryException, UnknownAmetysObjectException
121    {
122        return null;
123    }
124
125    public String getName() throws AmetysRepositoryException
126    {
127        return _page.getName();
128    }
129
130    public String getPath() throws AmetysRepositoryException
131    {
132        return getParentPath() + "/" + getName();
133    }
134
135    public String getId() throws AmetysRepositoryException
136    {
137        return StringUtils.replace(_page.getId(), "program://", "unused://");
138    }
139    
140    public String getTitle() throws AmetysRepositoryException
141    {
142        return _page.getTitle();
143    }
144
145    public String getLongTitle() throws AmetysRepositoryException
146    {
147        return _page.getLongTitle();
148    }
149
150    @SuppressWarnings("unchecked")
151    public Page getParent() throws AmetysRepositoryException
152    {
153        return _page.getParent();
154    }
155
156    public String getParentPath() throws AmetysRepositoryException
157    {
158        return _page.getParentPath();
159    }
160
161    public String getSiteName() throws AmetysRepositoryException
162    {
163        return _page.getSiteName();
164    }
165
166    public Site getSite() throws AmetysRepositoryException
167    {
168        return _page.getSite();
169    }
170
171    public ModelLessDataHolder getDataHolder()
172    {
173        throw new UnsupportedOperationException("getDataHolder not supported on legacy redirect odf pages");
174    }
175
176    public Set<String> getTags() throws AmetysRepositoryException
177    {
178        return Collections.emptySet();
179    }
180
181    public int getDepth() throws AmetysRepositoryException
182    {
183        return 0;
184    }
185
186    public String getTemplate() throws AmetysRepositoryException
187    {
188        return null;
189    }
190
191    public AmetysObjectIterable< ? extends Zone> getZones() throws AmetysRepositoryException
192    {
193        return null;
194    }
195
196    public boolean hasZone(String name) throws AmetysRepositoryException
197    {
198        return false;
199    }
200
201    public Zone getZone(String name) throws UnknownZoneException, AmetysRepositoryException
202    {
203        return null;
204    }
205
206    public ResourceCollection getRootAttachments() throws AmetysRepositoryException
207    {
208        throw new UnsupportedOperationException("getRootAttachments not supported on legacy redirect odf pages");
209    }
210
211    public Set<String> getReferers() throws AmetysRepositoryException
212    {
213        throw new UnsupportedOperationException("getReferers not supported on legacy redirect odf pages");
214    }
215
216    public boolean isVisible() throws AmetysRepositoryException
217    {
218        return false;
219    }
220    
221    public ModelAwareDataHolder getTemplateParametersHolder() throws AmetysRepositoryException
222    {
223        return null;
224    }
225}