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.odfweb.course; 017 018import org.apache.avalon.framework.context.Context; 019import org.apache.avalon.framework.context.ContextException; 020import org.apache.avalon.framework.context.Contextualizable; 021import org.apache.cocoon.components.ContextHelper; 022import org.apache.cocoon.environment.Request; 023 024import org.ametys.cms.repository.Content; 025import org.ametys.core.util.URIUtils; 026import org.ametys.odf.course.ShareableCourseStatusHelper; 027import org.ametys.web.WebHelper; 028 029/** 030 * Helper for web shareable course status 031 */ 032public class WebShareableCourseStatusHelper extends ShareableCourseStatusHelper implements Contextualizable 033{ 034 private Context _context; 035 036 public void contextualize(Context context) throws ContextException 037 { 038 _context = context; 039 } 040 041 @Override 042 protected String _getContentUri(Content content) 043 { 044 String siteName = _getSiteName(content); 045 return _getRequestUri() + "/" + siteName + "/index.html?uitool=uitool-content,id:%27" + URIUtils.encodeParameter(content.getId()) + "%27"; 046 } 047 048 /** 049 * Get the site name 050 * @param content the content 051 * @return the site name 052 */ 053 protected String _getSiteName(Content content) 054 { 055 Request request = ContextHelper.getRequest(_context); 056 return WebHelper.getSiteName(request, content); 057 } 058}