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     */
044    public SitemapElement(Sitemap sitemap, String currentPagePath, RightManager rightManager, RenderingContextHandler renderingContextHandler, UserIdentity userIdentity)
045    {
046        this(sitemap, null, rightManager, renderingContextHandler, currentPagePath, userIdentity);
047    }
048    
049    /**
050     * Constructor.
051     * @param sitemap the wrapped {@link Sitemap}.
052     * @param parent the parent container.
053     * @param rightManager the right manager
054     * @param currentPagePath the path of the current page, or null if none.
055     * @param renderingContextHandler the {@link RenderingContextHandler}.
056     * @param userIdentity the identity of the current user, or null if none.
057     */
058    public SitemapElement(Sitemap sitemap, AbstractPagesContainerElement<PagesContainer> parent, RightManager rightManager, RenderingContextHandler renderingContextHandler, String currentPagePath, UserIdentity userIdentity)
059    {
060        super(sitemap, parent, rightManager, renderingContextHandler, currentPagePath, userIdentity);
061    }
062    
063    @Override
064    public String getTagName()
065    {
066        return "sitemap";
067    }
068    
069    @Override
070    protected Map<String, AmetysAttribute> _lookupAttributes()
071    {
072        Map<String, AmetysAttribute> result = new HashMap<>();
073        
074        result.put("xmlns:sitemap", new AmetysAttribute("xmlns:sitemap", "xmlns:sitemap", null, NAMESPACE_URI, this));
075        result.put(NAMESPACE_PREFIX + ":site", new AmetysAttribute("site", NAMESPACE_PREFIX + ":site", NAMESPACE_URI, _object.getSiteName(), this));
076        result.put(NAMESPACE_PREFIX + ":lang", new AmetysAttribute("lang", NAMESPACE_PREFIX + ":lang", NAMESPACE_URI, _object.getName(), this));
077
078        result.putAll(super._lookupAttributes());
079        
080        return result;
081    }
082}