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 */
016package org.ametys.web.sitemap;
017
018import org.apache.avalon.framework.configuration.Configuration;
019import org.apache.avalon.framework.configuration.ConfigurationException;
020
021import org.ametys.runtime.i18n.I18nizableText;
022
023/**
024 * A decorator for page in sitemap
025 * 
026 */
027public class SitemapDecorator extends SitemapIcon
028{
029    private I18nizableText _label;
030    private String _id;
031    /**
032     * Constructor
033     */
034    public SitemapDecorator ()
035    {
036        // nothing
037    }
038    
039    @Override
040    public void configure(Configuration configuration, String iconPathPrefix) throws ConfigurationException
041    {
042        configure(configuration, iconPathPrefix, "application");
043    }
044    
045    /**
046     * Configure decoration
047     * @param configuration the configuration
048     * @param iconPathPrefix the prefix for icon path
049     * @param defaultCatalog default catalog used if none is declared in the config
050     * @throws ConfigurationException if configuration is invalid
051     */
052    public void configure (Configuration configuration, String iconPathPrefix, String defaultCatalog) throws ConfigurationException
053    {
054        super.configure(configuration, iconPathPrefix);
055        
056        this._id = configuration.getAttribute("id");
057        this._label = _configureI18n(configuration.getChild("label"), defaultCatalog);
058    }
059    
060    /**
061     * The id
062     * @return the id
063     */
064    public String getId ()
065    {
066        return _id;
067    }
068    
069    /**
070     * The decorator label
071     * @return The label
072     */
073    public I18nizableText getLabel()
074    {
075        return _label;
076    }
077    
078    private I18nizableText _configureI18n(Configuration child, String defaultCatalog)
079    {
080        String value = child.getValue("");
081        if (child.getAttributeAsBoolean("i18n", false))
082        {
083            return new I18nizableText(defaultCatalog, value);
084        }
085        else
086        {
087            return new I18nizableText(value);
088        }
089    }
090}