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.workspaces.html;
017
018import java.io.IOException;
019import java.net.MalformedURLException;
020import java.util.Map;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024import org.apache.avalon.framework.service.Serviceable;
025import org.apache.excalibur.source.Source;
026import org.apache.excalibur.source.SourceFactory;
027
028import org.ametys.cms.transformation.html.HTMLEnhancementSource;
029
030/**
031 * This factory return files upon the HTMLEnhancementExtensionPoint.
032 * <ul>
033 *  <li>htmleditor2html.xsl</li>
034 *  <li>html2htmleditor.xsl</li>
035 * </ul> 
036 */
037public class HTMLSourceFactory implements SourceFactory, Serviceable
038{
039    private HTMLEnhancementExtensionPoint _htmlEnhancementExtensionPoint;
040    
041    @Override
042    public void service(ServiceManager manager) throws ServiceException
043    {
044        _htmlEnhancementExtensionPoint = (HTMLEnhancementExtensionPoint) manager.lookup(HTMLEnhancementExtensionPoint.ROLE);
045    }
046    
047    @Override
048    public Source getSource(String location, Map parameters) throws IOException, MalformedURLException
049    {
050        if (location.endsWith("://html2htmleditor.xsl"))
051        {
052            return new HTMLEnhancementSource(location, _htmlEnhancementExtensionPoint.getHtml2htmleditorXSLT());
053        }
054        else if (location.endsWith("://html2html.xsl"))
055        {
056            return new HTMLEnhancementSource(location, _htmlEnhancementExtensionPoint.getHtml2htmlXSLT());
057        }
058        else if (location.endsWith("://htmleditor2html.xsl"))
059        {
060            return new HTMLEnhancementSource(location, _htmlEnhancementExtensionPoint.getHtmlEditor2HTMLXSLT());
061        }
062        else if (location.endsWith("://html2outgoingreferences.xsl"))
063        {
064            return new HTMLEnhancementSource(location, _htmlEnhancementExtensionPoint.getHtml2outgoingReferencesXSLT());
065        }
066        else
067        {
068            return null;
069        }
070    }
071
072    @Override
073    public void release(Source source)
074    {
075        // empty
076    }
077
078}