001/*
002 *  Copyright 2023 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.transformation.xslt;
017
018import org.apache.avalon.framework.service.ServiceException;
019import org.apache.avalon.framework.service.ServiceManager;
020import org.apache.cocoon.components.ContextHelper;
021import org.apache.cocoon.environment.Request;
022
023import org.ametys.web.URIPrefixHandler;
024import org.ametys.web.WebHelper;
025
026/**
027 * Web implementation of {@link org.ametys.plugins.core.ui.user.ProfileImageResolverHelper}
028 *
029 */
030public class ProfileImageResolverHelper extends org.ametys.cms.transformation.xslt.ProfileImageResolverHelper
031{
032    private URIPrefixHandler _webPrefixHandler;
033
034    @Override
035    public void service(ServiceManager manager) throws ServiceException
036    {
037        super.service(manager);
038        _webPrefixHandler = (URIPrefixHandler) manager.lookup(URIPrefixHandler.ROLE);
039    }
040    
041    @Override
042    protected String getUri(String path, boolean absolute, boolean internal)
043    {
044        Request request = ContextHelper.getRequest(_context);
045        String siteName = WebHelper.getSiteName(request);
046        
047        String fullPath = "/_plugins" + path;
048        
049        if (internal)
050        {
051            return "cocoon:/" + fullPath;
052        }
053        else if (absolute)
054        {
055            return _webPrefixHandler.getAbsoluteUriPrefix(siteName) + fullPath;
056        }
057        else
058        {
059            return _webPrefixHandler.getUriPrefix(siteName) + fullPath;
060        }
061    }
062}