[1327] | 1 | package test.testLoadProfile; |
---|
| 2 | |
---|
| 3 | import java.io.File; |
---|
| 4 | import java.io.IOException; |
---|
| 5 | |
---|
| 6 | import javax.xml.transform.Transformer; |
---|
| 7 | import javax.xml.transform.TransformerFactory; |
---|
| 8 | |
---|
| 9 | import org.apache.commons.logging.Log; |
---|
| 10 | import org.apache.commons.logging.LogFactory; |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | public class LoadCalendarUpdater { |
---|
| 14 | |
---|
| 15 | private static Log logger = LogFactory.getLog(LoadCalendarUpdater.class); |
---|
| 16 | |
---|
| 17 | private static final String DEFAULT_UPDATE_TRANSFORMATION_FILE_NAME = "simulator/xslt/debb/LoadCalendarUpdater.xsl"; |
---|
| 18 | private static final String DEFAULT_SCHEDULERS_AND_ESTIMATORS_FILE_NAME = "coolemallPlugins.xml"; |
---|
| 19 | |
---|
| 20 | private static String resourceFileName; |
---|
| 21 | private static String loadCalendarFileName ; |
---|
| 22 | |
---|
| 23 | public LoadCalendarUpdater() { |
---|
| 24 | // TODO Auto-generated constructor stub |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | |
---|
| 28 | public static void main(String[] args) throws Exception { |
---|
| 29 | LoadCalendarUpdater loadCalendarUpdater = new LoadCalendarUpdater() ; |
---|
| 30 | loadCalendarUpdater.update(args); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | public String update (String[] args) throws Exception { |
---|
| 34 | |
---|
| 35 | String inputFileName = null; |
---|
| 36 | String estimatorsFileName = DEFAULT_SCHEDULERS_AND_ESTIMATORS_FILE_NAME; |
---|
| 37 | |
---|
| 38 | if (args == null || args.length < 2) { |
---|
| 39 | String errorMessage = "No arguments specified. Please specify at least input files paths."; |
---|
| 40 | logger.error(errorMessage); |
---|
| 41 | throw new IOException(errorMessage); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | inputFileName = args[0]; |
---|
| 45 | if (inputFileName == null |
---|
| 46 | || (inputFileName != null && inputFileName.isEmpty() == true)) { |
---|
| 47 | |
---|
| 48 | String errorMessage = "Input file not specified!"; |
---|
| 49 | logger.error(errorMessage); |
---|
| 50 | |
---|
| 51 | throw new IOException(errorMessage); |
---|
| 52 | } |
---|
| 53 | File inputFile = new File(inputFileName); |
---|
| 54 | resourceFileName = inputFile.getAbsolutePath(); |
---|
| 55 | |
---|
| 56 | if (args.length > 1) { |
---|
| 57 | loadCalendarFileName = args[1]; |
---|
| 58 | if (loadCalendarFileName == null |
---|
| 59 | || (loadCalendarFileName != null && loadCalendarFileName.isEmpty() == true)) { |
---|
| 60 | String errorMessage = "Input file not specified!"; |
---|
| 61 | logger.error(errorMessage); |
---|
| 62 | |
---|
| 63 | throw new IOException(errorMessage); |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | inputFileName = args[1]; |
---|
| 67 | File inputFile2 = new File(inputFileName); |
---|
| 68 | loadCalendarFileName = inputFile2.getAbsolutePath(); |
---|
| 69 | |
---|
| 70 | try { |
---|
| 71 | TransformerFactory tFactory = TransformerFactory.newInstance(); |
---|
| 72 | |
---|
| 73 | String debbUpdateTransformationFileName = DEFAULT_UPDATE_TRANSFORMATION_FILE_NAME; |
---|
| 74 | |
---|
| 75 | Transformer updateTransformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource( |
---|
| 76 | debbUpdateTransformationFileName )); |
---|
| 77 | updateTransformer.setParameter("additionalInformationFileName", loadCalendarFileName); |
---|
| 78 | updateTransformer.setParameter("estimatorsInformationFileName", estimatorsFileName); |
---|
| 79 | updateTransformer.transform(new javax.xml.transform.stream.StreamSource(resourceFileName), |
---|
| 80 | new javax.xml.transform.stream.StreamResult(resourceFileName)); |
---|
| 81 | logger.debug("File " + resourceFileName + " has been updated"); |
---|
| 82 | } catch (Exception e) { |
---|
| 83 | e.printStackTrace(); |
---|
| 84 | } |
---|
| 85 | return resourceFileName; |
---|
| 86 | } |
---|
| 87 | } |
---|