001/* 002 * Copyright 2018 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.odfweb.cdmfr; 017 018import org.apache.avalon.framework.service.ServiceException; 019import org.apache.avalon.framework.service.ServiceManager; 020import org.apache.cocoon.environment.Request; 021import org.xml.sax.ContentHandler; 022import org.xml.sax.SAXException; 023 024import org.ametys.odf.cdmfr.ExportCDMfrHelper; 025import org.ametys.odf.program.Program; 026import org.ametys.web.renderingcontext.RenderingContext; 027import org.ametys.web.renderingcontext.RenderingContextHandler; 028 029/** 030 * Web implementation of CDM-fr export 031 */ 032public class WebExportCDMfrHelper extends ExportCDMfrHelper 033{ 034 private RenderingContextHandler _renderingContextHandler; 035 036 @Override 037 public void service(ServiceManager smanager) throws ServiceException 038 { 039 super.service(smanager); 040 _renderingContextHandler = (RenderingContextHandler) smanager.lookup(RenderingContextHandler.ROLE); 041 } 042 043 @Override 044 protected void _prepareRequest(Program program) 045 { 046 super._prepareRequest(program); 047 048 Request request = _getRequest(); 049 String siteName = request.getParameter("siteName"); 050 if (siteName != null) 051 { 052 request.setAttribute("siteName", siteName); 053 } 054 } 055 056 @Override 057 protected void _doExport(ContentHandler contentHandler, Program program) throws SAXException 058 { 059 RenderingContext currentContext = null; 060 try 061 { 062 // Switch to FRONT rendering context 063 currentContext = _renderingContextHandler.getRenderingContext(); 064 _renderingContextHandler.setRenderingContext(RenderingContext.FRONT); 065 066 super._doExport(contentHandler, program); 067 } 068 finally 069 { 070 _renderingContextHandler.setRenderingContext(currentContext); 071 } 072 } 073}