001/* 002 * Copyright 2015 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.cms.tag; 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.PluginAware; 024 025/** 026 * Class representing a static tag target type. 027 */ 028public class StaticTagTargetType implements TagTargetType, Configurable, PluginAware 029{ 030 /** The name */ 031 protected String _name; 032 /** The label */ 033 protected I18nizableText _label; 034 /** The description */ 035 protected I18nizableText _description; 036 /** The plugin name */ 037 protected String _pluginName; 038 /** The feature name */ 039 protected String _featureName; 040 041 @Override 042 public void setPluginInfo(String pluginName, String featureName, String id) 043 { 044 _pluginName = pluginName; 045 _featureName = featureName; 046 } 047 048 /** 049 * Get the plugin name 050 * @return the plugin name 051 */ 052 public String getPluginName() 053 { 054 return _pluginName; 055 } 056 057 @Override 058 public void configure(Configuration configuration) throws ConfigurationException 059 { 060 _name = configuration.getChild("name").getValue(); 061 _label = configureLabel(configuration, "plugin." + _pluginName); 062 _description = configureDescription(configuration, "plugin." + _pluginName); 063 } 064 065 public String getName() 066 { 067 return _name; 068 } 069 070 public I18nizableText getLabel() 071 { 072 return _label; 073 } 074 075 public I18nizableText getDescription() 076 { 077 return _description; 078 } 079 080 /** 081 * Configure label from the passed configuration 082 * @param configuration The configuration 083 * @param defaultCatalogue The default catalogue 084 * @return The label 085 * @throws ConfigurationException If an error occurred 086 */ 087 protected I18nizableText configureLabel (Configuration configuration, String defaultCatalogue) throws ConfigurationException 088 { 089 Configuration labelConfiguration = configuration.getChild("label"); 090 091 if (labelConfiguration.getAttributeAsBoolean("i18n", false)) 092 { 093 return new I18nizableText(defaultCatalogue, labelConfiguration.getValue("")); 094 } 095 else 096 { 097 return new I18nizableText(labelConfiguration.getValue("")); 098 } 099 } 100 101 /** 102 * Configure description from the passed configuration 103 * @param configuration The configuration 104 * @param defaultCatalogue The default catalogue 105 * @return The description 106 * @throws ConfigurationException If an error occurred 107 */ 108 protected I18nizableText configureDescription (Configuration configuration, String defaultCatalogue) throws ConfigurationException 109 { 110 Configuration descConfiguration = configuration.getChild("description"); 111 112 if (descConfiguration.getAttributeAsBoolean("i18n", false)) 113 { 114 return new I18nizableText(defaultCatalogue, descConfiguration.getValue("")); 115 } 116 else 117 { 118 return new I18nizableText(descConfiguration.getValue("")); 119 } 120 } 121 122}