001/* 002 * Copyright 2013 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.plugins.newsletter.ga; 017 018import java.net.URISyntaxException; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022import org.apache.avalon.framework.service.Serviceable; 023 024/** 025 * Helper which provides Google analytics URI building. 026 */ 027public class GAXsltHelper implements Serviceable 028{ 029 030 private static GAUriBuilder _gaUriBuilder; 031 032 @Override 033 public void service(ServiceManager manager) throws ServiceException 034 { 035 _gaUriBuilder = (GAUriBuilder) manager.lookup(GAUriBuilder.ROLE); 036 } 037 038 /** 039 * Get an event GIF URI. 040 * @param gaWebId the GA web ID. 041 * @param category the event category. 042 * @param action the event action. 043 * @param label the event label. 044 * @return the event GIF URI. 045 */ 046 public static String eventGifUri(String gaWebId, String category, String action, String label) 047 { 048 return _gaUriBuilder.getEventGifUri(gaWebId, category, action, label); 049 } 050 051 /** 052 * Get an event GIF URI. 053 * @param gaWebId the GA web ID. 054 * @param category the event category. 055 * @param action the event action. 056 * @param label the event label. 057 * @param value the event value. 058 * @return the event GIF URI. 059 */ 060 public static String eventGifUri(String gaWebId, String category, String action, String label, int value) 061 { 062 return _gaUriBuilder.getEventGifUri(gaWebId, category, action, label, value); 063 } 064 065 /** 066 * Get an event GIF URI. 067 * @param gaWebId the GA web ID. 068 * @param category the event category. 069 * @param action the event action. 070 * @param label the event label. 071 * @param value the event value. 072 * @param nonInteraction true if the event does not trigger an interaction. 073 * @return the event GIF URI. 074 */ 075 public static String eventGifUri(String gaWebId, String category, String action, String label, int value, boolean nonInteraction) 076 { 077 return _gaUriBuilder.getEventGifUri(gaWebId, category, action, label, value, nonInteraction); 078 } 079 080 /** 081 * Get an event GIF URI. 082 * @param gaWebId the GA web ID. 083 * @param eventIdentifier the event identifier. 084 * @return the event GIF URI. 085 */ 086 public static String eventGifUri(String gaWebId, String eventIdentifier) 087 { 088 return _gaUriBuilder.getEventGifUri(gaWebId, eventIdentifier); 089 } 090 091 /** 092 * Encode a value to use as an identifier component. 093 * @param value the value to encode. 094 * @return the encoded value. 095 */ 096 public static String encode(String value) 097 { 098 try 099 { 100 return _gaUriBuilder.encodeValue(value); 101 } 102 catch (URISyntaxException e) 103 { 104 // Ignore. 105 return ""; 106 } 107 } 108 109}