001/* 002 * Copyright 2015 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.blog; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020import org.apache.avalon.framework.service.Serviceable; 021 022import org.ametys.cms.transformation.xslt.AmetysXSLTHelper; 023import org.ametys.web.repository.page.Page; 024import org.ametys.web.repository.page.SitemapElement; 025 026/** 027 * Helper component to be used from XSL stylesheets. 028 */ 029public class BlogXSLTHelper implements Serviceable 030{ 031 private static BlogPageHandler _blogPageHandler; 032 033 @Override 034 public void service(ServiceManager smanager) throws ServiceException 035 { 036 _blogPageHandler = (BlogPageHandler) smanager.lookup(BlogPageHandler.ROLE); 037 } 038 039 /** 040 * Get the path in sitemap of the blog root page 041 * @param siteName The site name 042 * @param lang The sitemap map 043 * @return The path in sitemap or null if there is no root blog page 044 */ 045 public static String blogRootPath (String siteName, String lang) 046 { 047 SitemapElement rootPage = _blogPageHandler.getBlogRootPage(siteName, lang); 048 if (rootPage != null) 049 { 050 return rootPage.getPathInSitemap(); 051 } 052 return null; 053 } 054 055 /** 056 * Get the id of the page holding the given tag 057 * @param siteName The site name 058 * @param lang The sitemap map 059 * @param tagName The tag's name 060 * @return the id of the page or null if not found 061 */ 062 public static String blogTagPage (String siteName, String lang, String tagName) 063 { 064 String tagPath = AmetysXSLTHelper.tagPath(siteName, tagName); 065 066 Page tagPage = _blogPageHandler.getTagPage(siteName, lang, tagPath); 067 if (tagPage != null) 068 { 069 return tagPage.getId(); 070 } 071 return null; 072 } 073}