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 */
016package org.ametys.web.repository.sitemap;
017
018import javax.jcr.Node;
019
020import org.ametys.plugins.repository.AmetysObject;
021import org.ametys.plugins.repository.AmetysRepositoryException;
022import org.ametys.plugins.repository.RepositoryConstants;
023import org.ametys.web.repository.page.jcr.AbstractSitemapElement;
024import org.ametys.web.repository.site.Site;
025
026/**
027 * Sitemap of a web site. A sitemap is a hierarchical view of the site. It is composed by <code>Page</code>s A single web site may have many sitemaps.
028 */
029public final class Sitemap extends AbstractSitemapElement<SitemapFactory>
030{
031    /** Sitemap node type name. */
032    public static final String NODE_TYPE = RepositoryConstants.NAMESPACE_PREFIX + ":sitemap";
033    
034    /**
035     * Creates a {@link Sitemap}.
036     * @param node the node backing this {@link AmetysObject}.
037     * @param parentPath the parent path in the Ametys hierarchy.
038     * @param factory the {@link SitemapFactory} which creates the AmetysObject.
039     */
040    public Sitemap(Node node, String parentPath, SitemapFactory factory)
041    {
042        super(node, parentPath, factory);
043    }
044    
045    @Override
046    public String getPathInSitemap() throws AmetysRepositoryException
047    {
048        return "";
049    }
050    
051    @Override
052    public Site getSite() throws AmetysRepositoryException
053    {
054        return getParent().getParent();
055    }
056
057    @Override
058    public String getSiteName() throws AmetysRepositoryException
059    {
060        return getSite().getName();
061    }
062
063    @Override
064    public Sitemap getSitemap() throws AmetysRepositoryException
065    {
066        return this;
067    }
068
069    @Override
070    public String getSitemapName() throws AmetysRepositoryException
071    {
072        return getName();
073    }
074    
075    public String getTitle() throws AmetysRepositoryException
076    {
077        return getName();
078    }
079    
080    public String getTemplate() throws AmetysRepositoryException
081    {
082        return _getFactory().sitemapTemplateExists(this) ? "sitemap" : null;
083    }
084}