001/* 002 * Copyright 2022 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.odf.cdmfr; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.context.Context; 021import org.apache.avalon.framework.context.ContextException; 022import org.apache.avalon.framework.context.Contextualizable; 023import org.apache.cocoon.components.ContextHelper; 024import org.apache.cocoon.environment.ObjectModelHelper; 025import org.apache.cocoon.transformation.Transformer; 026import org.apache.cocoon.xml.XMLConsumer; 027 028import org.ametys.cms.data.LocalMediaObjectHandler; 029import org.ametys.cms.transformation.AbstractEnhancementTransformer; 030import org.ametys.runtime.model.type.DataContext; 031 032/** 033 * Cocoon {@link Transformer} to trnasform docboock to CDM-Fr 034 */ 035public class Docbook2CDMFrTransformer extends AbstractEnhancementTransformer implements Contextualizable 036{ 037 /** The avalon context */ 038 protected Context _context; 039 040 public void contextualize(Context context) throws ContextException 041 { 042 _context = context; 043 } 044 045 @Override 046 public void setConsumer(XMLConsumer consumer) 047 { 048 Map objectModel = ContextHelper.getObjectModel(_context); 049 Map parentContextParameters = (Map) objectModel.get(ObjectModelHelper.PARENT_CONTEXT); 050 DataContext dataContext = (DataContext) parentContextParameters.get("dataContext"); 051 052 _contentHandler = new LocalMediaObjectHandler(consumer, dataContext); 053 _lexicalHandler = consumer; 054 } 055}