package test.testLoadProfile; import java.io.File; import java.io.IOException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class LoadCalendarUpdater { private static Log logger = LogFactory.getLog(LoadCalendarUpdater.class); private static final String DEFAULT_UPDATE_TRANSFORMATION_FILE_NAME = "simulator/xslt/debb/LoadCalendarUpdater.xsl"; private static final String DEFAULT_SCHEDULERS_AND_ESTIMATORS_FILE_NAME = "coolemallPlugins.xml"; private static String resourceFileName; private static String loadCalendarFileName ; public LoadCalendarUpdater() { // TODO Auto-generated constructor stub } public static void main(String[] args) throws Exception { LoadCalendarUpdater loadCalendarUpdater = new LoadCalendarUpdater() ; loadCalendarUpdater.update(args); } public String update (String[] args) throws Exception { String inputFileName = null; String estimatorsFileName = DEFAULT_SCHEDULERS_AND_ESTIMATORS_FILE_NAME; if (args == null || args.length < 2) { String errorMessage = "No arguments specified. Please specify at least input files paths."; logger.error(errorMessage); throw new IOException(errorMessage); } inputFileName = args[0]; if (inputFileName == null || (inputFileName != null && inputFileName.isEmpty() == true)) { String errorMessage = "Input file not specified!"; logger.error(errorMessage); throw new IOException(errorMessage); } File inputFile = new File(inputFileName); resourceFileName = inputFile.getAbsolutePath(); if (args.length > 1) { loadCalendarFileName = args[1]; if (loadCalendarFileName == null || (loadCalendarFileName != null && loadCalendarFileName.isEmpty() == true)) { String errorMessage = "Input file not specified!"; logger.error(errorMessage); throw new IOException(errorMessage); } } inputFileName = args[1]; File inputFile2 = new File(inputFileName); loadCalendarFileName = inputFile2.getAbsolutePath(); try { TransformerFactory tFactory = TransformerFactory.newInstance(); String debbUpdateTransformationFileName = DEFAULT_UPDATE_TRANSFORMATION_FILE_NAME; Transformer updateTransformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource( debbUpdateTransformationFileName )); updateTransformer.setParameter("additionalInformationFileName", loadCalendarFileName); updateTransformer.setParameter("estimatorsInformationFileName", estimatorsFileName); updateTransformer.transform(new javax.xml.transform.stream.StreamSource(resourceFileName), new javax.xml.transform.stream.StreamResult(resourceFileName)); logger.debug("File " + resourceFileName + " has been updated"); } catch (Exception e) { e.printStackTrace(); } return resourceFileName; } }