001/* 002 * Copyright 2026 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.maps; 017 018import org.apache.avalon.framework.component.Component; 019import org.apache.avalon.framework.context.Context; 020import org.apache.avalon.framework.context.ContextException; 021import org.apache.avalon.framework.context.Contextualizable; 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024import org.apache.avalon.framework.service.Serviceable; 025import org.apache.cocoon.components.ContextHelper; 026 027import org.ametys.core.ui.Callable; 028import org.ametys.web.WebHelper; 029import org.ametys.web.repository.site.SiteManager; 030 031/** 032 * Helper to interact with Google Maps 033 */ 034public class MapsHelper implements Component, Contextualizable, Serviceable 035{ 036 private Context _context; 037 private SiteManager _siteManager; 038 039 public void contextualize(Context context) throws ContextException 040 { 041 _context = context; 042 } 043 044 public void service(ServiceManager manager) throws ServiceException 045 { 046 _siteManager = (SiteManager) manager.lookup(SiteManager.ROLE); 047 } 048 049 /** 050 * Get the Google API key 051 * @return the key 052 */ 053 @Callable(rights = "Maps_Right_Service_Maps") 054 public String getApiKey() 055 { 056 String siteName = WebHelper.getSiteName(ContextHelper.getRequest(_context)); 057 if (siteName != null) 058 { 059 return _siteManager.getSite(siteName).getValue("google-api-key"); 060 } 061 return null; 062 } 063}