001/*
002 *  Copyright 2011 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.web.repository.dom;
018
019import java.util.HashMap;
020import java.util.Map;
021
022import org.w3c.dom.Element;
023
024import org.ametys.core.right.RightManager;
025import org.ametys.core.user.UserIdentity;
026import org.ametys.core.util.dom.AmetysAttribute;
027import org.ametys.web.renderingcontext.RenderingContextHandler;
028import org.ametys.web.repository.page.PagesContainer;
029import org.ametys.web.repository.sitemap.Sitemap;
030
031/**
032 * DOM {@link Element} wrapping a {@link Sitemap}.
033 */
034public class SitemapElement extends AbstractPagesContainerElement<Sitemap>
035{
036    /**
037     * Constructor.
038     * @param sitemap the wrapped {@link Sitemap}.
039     * @param currentPagePath the path of the current page, or null if none.
040     * @param rightManager the right manager
041     * @param renderingContextHandler the {@link RenderingContextHandler}.
042     * @param userIdentity the identity of the current user, or null if none.
043     * @param includeInvisiblePages Should return child invisible pages
044     */
045    public SitemapElement(Sitemap sitemap, String currentPagePath, RightManager rightManager, RenderingContextHandler renderingContextHandler, UserIdentity userIdentity, boolean includeInvisiblePages)
046    {
047        this(sitemap, null, rightManager, renderingContextHandler, currentPagePath, userIdentity, includeInvisiblePages);
048    }
049    
050    /**
051     * Constructor.
052     * @param sitemap the wrapped {@link Sitemap}.
053     * @param parent the parent container.
054     * @param rightManager the right manager
055     * @param currentPagePath the path of the current page, or null if none.
056     * @param renderingContextHandler the {@link RenderingContextHandler}.
057     * @param userIdentity the identity of the current user, or null if none.
058     * @param includeInvisiblePages Should return child invisible pages
059     */
060    public SitemapElement(Sitemap sitemap, AbstractPagesContainerElement<PagesContainer> parent, RightManager rightManager, RenderingContextHandler renderingContextHandler, String currentPagePath, UserIdentity userIdentity, boolean includeInvisiblePages)
061    {
062        super(sitemap, parent, rightManager, renderingContextHandler, currentPagePath, userIdentity, includeInvisiblePages);
063    }
064    
065    @Override
066    public String getTagName()
067    {
068        return "sitemap";
069    }
070    
071    @Override
072    protected Map<String, AmetysAttribute> _lookupAttributes()
073    {
074        Map<String, AmetysAttribute> result = new HashMap<>();
075        
076        result.put("xmlns:sitemap", new AmetysAttribute("xmlns:sitemap", "xmlns:sitemap", null, NAMESPACE_URI, this));
077        result.put(NAMESPACE_PREFIX + ":site", new AmetysAttribute("site", NAMESPACE_PREFIX + ":site", NAMESPACE_URI, _object.getSiteName(), this));
078        result.put(NAMESPACE_PREFIX + ":lang", new AmetysAttribute("lang", NAMESPACE_PREFIX + ":lang", NAMESPACE_URI, _object.getName(), this));
079        result.put(NAMESPACE_PREFIX + ":id", new AmetysAttribute("id", NAMESPACE_PREFIX + ":id", NAMESPACE_URI, _object.getId(), this));
080
081        result.putAll(super._lookupAttributes());
082        
083        return result;
084    }
085}