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