001/* 002 * Copyright 2020 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.welcome; 017 018import java.io.IOException; 019import java.util.Map; 020 021import org.apache.avalon.framework.service.ServiceException; 022import org.apache.avalon.framework.service.ServiceManager; 023 024import org.ametys.web.repository.site.Site; 025import org.ametys.web.repository.site.SiteManager; 026 027/** 028 * Helper for the welcome button / tool / page 029 */ 030public class WelcomeHelper extends org.ametys.cms.welcome.WelcomeHelper 031{ 032 /** Site Manager */ 033 protected static SiteManager _siteManager; 034 035 @Override 036 public void service(ServiceManager smanager) throws ServiceException 037 { 038 super.service(smanager); 039 _siteManager = (SiteManager) smanager.lookup(SiteManager.ROLE); 040 } 041 042 @Override 043 public String getXsltPath(Map<String, Object> parameters) 044 { 045 String language = (String) parameters.get("language"); 046 String siteName = (String) parameters.get("siteName"); 047 048 try 049 { 050 Site site = _siteManager.getSite(siteName); 051 052 String skinId = site.getSkinId(); 053 054 String skinRootPath = "skin:" + skinId + "://welcome/"; 055 056 String languagePath = skinRootPath + "index_" + language + ".xsl"; 057 String noLanguagePath = skinRootPath + "index.xsl"; 058 if (_resolver.resolveURI(languagePath).exists()) 059 { 060 return languagePath; 061 } 062 else if (_resolver.resolveURI(noLanguagePath).exists()) 063 { 064 return noLanguagePath; 065 } 066 } 067 catch (IOException e) 068 { 069 getLogger().warn("Unable to retrieve XSLT file for welcome tool from the current skin", e); 070 } 071 072 return super.getXsltPath(parameters); 073 } 074}