001/* 002 * Copyright 2023 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.analytics; 017 018 019import java.net.URI; 020import java.net.URISyntaxException; 021 022import org.apache.avalon.framework.configuration.Configurable; 023import org.apache.avalon.framework.configuration.Configuration; 024import org.apache.avalon.framework.configuration.ConfigurationException; 025 026import org.ametys.runtime.i18n.I18nizableText; 027import org.ametys.runtime.plugin.component.AbstractLogEnabled; 028import org.ametys.runtime.plugin.component.PluginAware; 029 030/** 031 * Abstract web analytics provider for static configuration 032 */ 033public abstract class AbstractWebAnalyticsProvider extends AbstractLogEnabled implements WebAnalyticsProvider, Configurable, PluginAware 034{ 035 /** Token to replace in the url by a random id value */ 036 public static final String RANDOM_NUMBER_TOKEN = "#random_number_token#"; 037 038 /** The provider id */ 039 protected String _id; 040 041 /** The provider label */ 042 protected I18nizableText _label; 043 044 /** The plugin name */ 045 protected String _pluginName; 046 047 public void setPluginInfo(String pluginName, String featureName, String id) 048 { 049 _pluginName = pluginName; 050 } 051 052 public void configure(Configuration configuration) throws ConfigurationException 053 { 054 _id = configuration.getAttribute("id"); 055 _label = I18nizableText.parseI18nizableText(configuration.getChild("label"), "plugin." + _pluginName, ""); 056 } 057 058 public String getId() 059 { 060 return _id; 061 } 062 063 public I18nizableText getLabel() 064 { 065 return _label; 066 } 067 068 /** 069 * Encode a value to use as an identifier component. 070 * @param value the value to encode. 071 * @return the encoded value. 072 * @throws URISyntaxException if an error occurs encoding the value. 073 */ 074 protected String _encodeValue(String value) throws URISyntaxException 075 { 076 URI uri = new URI(null, null, null, value, null); 077 return uri.getRawQuery().replace("/", "%2F"); 078 } 079}