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.odfpilotage.helper; 017 018import java.io.File; 019 020import org.apache.avalon.framework.activity.Initializable; 021import org.apache.avalon.framework.component.Component; 022import org.apache.avalon.framework.context.Context; 023import org.apache.avalon.framework.context.ContextException; 024import org.apache.avalon.framework.context.Contextualizable; 025import org.apache.cocoon.Constants; 026import org.apache.commons.io.FileUtils; 027 028import org.ametys.runtime.util.AmetysHomeHelper; 029 030/** 031 * The pilotage helper. 032 */ 033public class PilotageHelper implements Component, Initializable, Contextualizable 034{ 035 /** The avalon role */ 036 public static final String ROLE = PilotageHelper.class.getName(); 037 038 /** MCC Course nature */ 039 public static final String MCC_MODALITE_SESSION1 = "odf-enumeration.MccModaliteSession1"; 040 041 /** MCC Course nature */ 042 public static final String MCC_MODALITE_SESSION2 = "odf-enumeration.MccModaliteSession2"; 043 044 /** MCC Course nature */ 045 public static final String MCC_SESSION_NATURE = "odf-enumeration.MccSessionNature"; 046 047 /** Norme */ 048 public static final String NORME = "odf-enumeration.Norme"; 049 050 /** The cocoon context */ 051 protected org.apache.cocoon.environment.Context _cocoonContext; 052 053 private File _pilotageFolder; 054 private File _pilotageTmpFolder; 055 056 @Override 057 public void contextualize(Context context) throws ContextException 058 { 059 _cocoonContext = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); 060 } 061 062 @Override 063 public void initialize() throws Exception 064 { 065 _pilotageFolder = new File(AmetysHomeHelper.getAmetysHomeData(), "odf/gestion"); 066 _pilotageTmpFolder = new File(AmetysHomeHelper.getAmetysHomeData(), "odf/gestion/tmp"); 067 068 FileUtils.forceMkdir(_pilotageTmpFolder); 069 } 070 071 /** 072 * Get the pilotage folder. 073 * @return The pilotage folder 074 */ 075 public File getPilotageFolder() 076 { 077 return _pilotageFolder; 078 } 079 080 /** 081 * Get the temp pilotage folder. 082 * @return The sub folder tmp in the pilotage folder 083 */ 084 public File getTmpPilotageFolder() 085 { 086 return _pilotageTmpFolder; 087 } 088}