001/* 002 * Copyright 2019 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.linkdirectory; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022 023import org.ametys.core.util.dom.MapElement; 024import org.ametys.web.transformation.xslt.AmetysXSLTHelper; 025 026/** 027 * XSLT Helper with link directory specificity 028 */ 029public class LinkDirectoryXSLTHelper extends AmetysXSLTHelper 030{ 031 private static LinkDirectoryColorsComponent _linkDirectoryColorsComponent; 032 033 @Override 034 public void service(ServiceManager manager) throws ServiceException 035 { 036 super.service(manager); 037 _linkDirectoryColorsComponent = (LinkDirectoryColorsComponent) manager.lookup(LinkDirectoryColorsComponent.ROLE); 038 } 039 040 /** 041 * Get all the colors for the current site 042 * @return all colors available for the current site 043 */ 044 public static MapElement getColors() 045 { 046 String siteName = site(); 047 return getColors(siteName); 048 } 049 050 /** 051 * Get all the colors for a site 052 * @param siteName site to check 053 * @return all colors available for this site 054 */ 055 public static MapElement getColors(String siteName) 056 { 057 Map<String, Map<String, String>> colors = _linkDirectoryColorsComponent.getColors(siteName); 058 059 return new MapElement("colors", colors); 060 } 061 062 /** 063 * Get the default color index for the current site 064 * @return the default color index for the current site 065 */ 066 public static String getDefaultColorIndex() 067 { 068 String siteName = site(); 069 return getDefaultColorIndex(siteName); 070 } 071 072 /** 073 * Get the default color index for a site 074 * @param siteName site to check 075 * @return the default color index for this site 076 */ 077 public static String getDefaultColorIndex(String siteName) 078 { 079 return _linkDirectoryColorsComponent.getDefaultKey(siteName); 080 } 081 082}