001/* 002 * Copyright 2025 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.Configurable; 019import org.apache.avalon.framework.configuration.Configuration; 020import org.apache.avalon.framework.configuration.ConfigurationException; 021 022import org.ametys.runtime.i18n.I18nizableText; 023import org.ametys.runtime.plugin.component.AbstractLogEnabled; 024import org.ametys.runtime.plugin.component.PluginAware; 025 026/** 027 * Abstract class for implementing a sitemap tree's indicator 028 */ 029public abstract class AbstractStaticSitemapIndicator extends AbstractLogEnabled implements SitemapTreeIndicator, PluginAware, Configurable 030{ 031 private String _id; 032 private String _pluginName; 033 private I18nizableText _label; 034 private int _priority; 035 private String _iconGlyph; 036 private String _iconDecorator; 037 private String _iconPath; 038 039 public void configure(Configuration configuration) throws ConfigurationException 040 { 041 configure(null, configuration, "plugin." + _pluginName, "/plugins/" + _pluginName + "/resources/"); 042 } 043 044 /** 045 * Configure sitemap indicator 046 * @param id the unique id. Can be null to get id from configuration 047 * @param configuration the configuration 048 * @param defaultI18nCatalog the default i18n catalogue 049 * @param iconPathPrefix the prefix path for icon 050 * @throws ConfigurationException if configuration is invalid 051 */ 052 public void configure(String id, Configuration configuration, String defaultI18nCatalog, String iconPathPrefix) throws ConfigurationException 053 { 054 this._id = id != null ? id : configuration.getAttribute("id", null); 055 this._label = I18nizableText.parseI18nizableText(configuration.getChild("label", false), defaultI18nCatalog); // label can be null for sitemap icons 056 this._priority = configuration.getChild("order").getValueAsInteger(50); 057 this._iconGlyph = configuration.getChild("glyph").getValue(null); 058 this._iconDecorator = configuration.getChild("decorator").getValue(null); 059 String iconRelPath = configuration.getChild("image").getValue(null); 060 if (iconRelPath != null) 061 { 062 this._iconPath = iconPathPrefix + iconRelPath; 063 } 064 } 065 066 public void setPluginInfo(String pluginName, String featureName, String id) 067 { 068 _pluginName = pluginName; 069 } 070 071 public String getId() 072 { 073 return this._id; 074 } 075 076 public I18nizableText getLabel() 077 { 078 return this._label; 079 } 080 081 public int getPriority() 082 { 083 return this._priority; 084 } 085 086 public String getIcon() 087 { 088 return this._iconPath; 089 } 090 091 public String getIconGlyph() 092 { 093 return _iconGlyph; 094 } 095 096 public String getIconDecorator() 097 { 098 return _iconDecorator; 099 } 100}