001/* 002 * Copyright 2016 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.odfweb.cdmfr; 017 018import java.util.Set; 019 020import org.apache.avalon.framework.service.ServiceException; 021import org.apache.avalon.framework.service.ServiceManager; 022import org.apache.avalon.framework.service.Serviceable; 023import org.apache.cocoon.xml.XMLUtils; 024import org.apache.commons.lang.StringUtils; 025import org.xml.sax.ContentHandler; 026import org.xml.sax.SAXException; 027 028import org.ametys.odf.cdmfr.CDMFRTagsConstants; 029import org.ametys.odf.cdmfr.CDMfrExtension; 030import org.ametys.odf.course.Course; 031import org.ametys.odf.orgunit.OrgUnit; 032import org.ametys.odf.person.Person; 033import org.ametys.odf.program.AbstractProgram; 034import org.ametys.odf.program.Container; 035import org.ametys.odf.program.Program; 036import org.ametys.odf.program.ProgramFactory; 037import org.ametys.plugins.odfweb.repository.OdfPageResolver; 038import org.ametys.plugins.odfweb.repository.ProgramPage; 039import org.ametys.web.repository.site.SiteManager; 040 041/** 042 * Web CDMfr extension for Ametys 043 */ 044public class WebAmetysCDMfrExtension implements CDMfrExtension, Serviceable 045{ 046 private OdfPageResolver _odfPageResolver; 047 private SiteManager _siteManager; 048 049 @Override 050 public void service(ServiceManager manager) throws ServiceException 051 { 052 _odfPageResolver = (OdfPageResolver) manager.lookup(OdfPageResolver.ROLE); 053 _siteManager = (SiteManager) manager.lookup(SiteManager.ROLE); 054 } 055 056 @Override 057 public void abstractProgram2CDM(ContentHandler contentHandler, AbstractProgram<? extends ProgramFactory> program, Set<String> persons, Set<String> orgUnits) throws SAXException 058 { 059 // Empty 060 } 061 062 public void program2CDM(ContentHandler contentHandler, Program program, Set<String> persons, Set<String> orgUnits) throws SAXException 063 { 064 ProgramPage page = _odfPageResolver.getProgramPage(program); 065 066 if (page != null) 067 { 068 String pagePath = page.getSitemap().getName() + "/" + page.getPathInSitemap() + ".html"; 069 String siteName = page.getSiteName(); 070 071 String url = _siteManager.getSite(siteName).getUrl(); 072 if (!StringUtils.endsWith("/", url)) 073 { 074 url += "/"; 075 } 076 url += pagePath; 077 XMLUtils.createElement(contentHandler, CDMFRTagsConstants.NAMESPACE_AMETYS_CDM + "webLink", url); 078 } 079 } 080 081 public void course2CDM(ContentHandler contentHandler, Course course, Set<String> persons, Set<String> orgUnits) throws SAXException 082 { 083 // Empty 084 } 085 086 public void orgunit2CDM(ContentHandler contentHandler, OrgUnit orgunit) throws SAXException 087 { 088 // Empty 089 } 090 091 public void person2CDM(ContentHandler contentHandler, Person person) throws SAXException 092 { 093 // Empty 094 } 095 096 public void container2CDM(ContentHandler contentHandler, Container container, Set<String> persons, Set<String> orgUnits) throws SAXException 097 { 098 // Empty 099 } 100}