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.cms.tag.TagProviderExtensionPoint;
025import org.ametys.core.right.RightManager;
026import org.ametys.core.user.UserIdentity;
027import org.ametys.core.util.dom.AmetysAttribute;
028import org.ametys.web.renderingcontext.RenderingContextHandler;
029import org.ametys.web.repository.sitemap.Sitemap;
030
031/**
032 * DOM {@link Element} wrapping a {@link Sitemap}.
033 */
034public class SitemapElement extends AbstractSitemapElementElement<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 depth The depth to get. 1 for root pages, 0 for this node only, -1 for infinite.
044     * @param includeInvisiblePages Should return child invisible pages
045     * @param tagProviderExtensionPoint the tag provider extension point
046     */
047    public SitemapElement(Sitemap sitemap, String currentPagePath, RightManager rightManager, RenderingContextHandler renderingContextHandler, UserIdentity userIdentity, long depth, boolean includeInvisiblePages, TagProviderExtensionPoint tagProviderExtensionPoint)
048    {
049        this(sitemap, null, rightManager, renderingContextHandler, currentPagePath, userIdentity, depth, includeInvisiblePages, tagProviderExtensionPoint);
050    }
051    
052    /**
053     * Constructor.
054     * @param sitemap the wrapped {@link Sitemap}.
055     * @param parent the parent container.
056     * @param rightManager the right manager
057     * @param currentPagePath the path of the current page, or null if none.
058     * @param renderingContextHandler the {@link RenderingContextHandler}.
059     * @param userIdentity the identity of the current user, or null if none.
060     * @param depth The depth to get. 1 for root pages, 0 for this node only, -1 for infinite.
061     * @param includeInvisiblePages Should return child invisible pages
062     * @param tagProviderExtensionPoint the tag provider extension point
063     */
064    public SitemapElement(Sitemap sitemap, AbstractSitemapElementElement<org.ametys.web.repository.page.SitemapElement> parent, RightManager rightManager, RenderingContextHandler renderingContextHandler, String currentPagePath, UserIdentity userIdentity, long depth, boolean includeInvisiblePages, TagProviderExtensionPoint tagProviderExtensionPoint)
065    {
066        super(sitemap, parent, rightManager, renderingContextHandler, currentPagePath, userIdentity, depth, includeInvisiblePages, tagProviderExtensionPoint);
067    }
068    
069    @Override
070    public String getTagName()
071    {
072        return "sitemap";
073    }
074    
075    @Override
076    protected Map<String, AmetysAttribute> _lookupAttributes()
077    {
078        Map<String, AmetysAttribute> result = new HashMap<>();
079        
080        result.put("xmlns:sitemap", new AmetysAttribute("xmlns:sitemap", "xmlns:sitemap", null, NAMESPACE_URI, this));
081        result.put(NAMESPACE_PREFIX + ":site", new AmetysAttribute("site", NAMESPACE_PREFIX + ":site", NAMESPACE_URI, _object.getSiteName(), this));
082        result.put(NAMESPACE_PREFIX + ":lang", new AmetysAttribute("lang", NAMESPACE_PREFIX + ":lang", NAMESPACE_URI, _object.getName(), this));
083        result.put(NAMESPACE_PREFIX + ":id", new AmetysAttribute("id", NAMESPACE_PREFIX + ":id", NAMESPACE_URI, _object.getId(), this));
084
085        result.putAll(super._lookupAttributes());
086        
087        return result;
088    }
089}