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.docbook; 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 DocbookEnhancementExtensionPoint. 030 * <ul> 031 * <li>htmleditor2docbook.xsl</li> 032 * <li>docbook2htmleditor.xsl</li> 033 * </ul> 034 */ 035public class DocbookSourceFactory implements SourceFactory, Serviceable 036{ 037 // class creation timestamp, used for 038 private long _timestamp = System.currentTimeMillis(); 039 private DocbookEnhancementExtensionPoint _docDocbookEnhancementExtensionPoint; 040 041 @Override 042 public void service(ServiceManager manager) throws ServiceException 043 { 044 _docDocbookEnhancementExtensionPoint = (DocbookEnhancementExtensionPoint) manager.lookup(DocbookEnhancementExtensionPoint.ROLE); 045 } 046 047 @Override 048 public Source getSource(String location, Map parameters) throws IOException, MalformedURLException 049 { 050 if (location.endsWith("://docbook2htmleditor.xsl")) 051 { 052 return new DocbookEnhancementSource(location, _docDocbookEnhancementExtensionPoint.getDocbook2htmleditorXSLT(), _timestamp); 053 } 054 else if (location.endsWith("://docbook2html.xsl")) 055 { 056 return new DocbookEnhancementSource(location, _docDocbookEnhancementExtensionPoint.getDocbook2htmlXSLT(), _timestamp); 057 } 058 else if (location.endsWith("://htmleditor2docbook.xsl")) 059 { 060 return new DocbookEnhancementSource(location, _docDocbookEnhancementExtensionPoint.getHTMLEditor2docbookXSLT(), _timestamp); 061 } 062 else if (location.endsWith("://docbook2outgoingreferences.xsl")) 063 { 064 return new DocbookEnhancementSource(location, _docDocbookEnhancementExtensionPoint.getDocbook2outgoingReferencesXSLT(), _timestamp); 065 } 066 else 067 { 068 return null; 069 } 070 } 071 072 @Override 073 public void release(Source source) 074 { 075 // empty 076 } 077}