1 /* 2 * Copyright 2012 smartics, Kronseder & Reiner GmbH 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package de.smartics.ci.config.load; 17 18 import org.jdom.Document; 19 import org.jdom.JDOMException; 20 21 /** 22 * Fixes problems with elements in the Hudson job configuration files. 23 */ 24 class HudsonJobDocumentFixer 25 { 26 // ********************************* Fields ********************************* 27 28 // --- constants ------------------------------------------------------------ 29 30 // --- members -------------------------------------------------------------- 31 32 /** 33 * The loader configuration to control the loading and creation of Hudson job 34 * configuration files. 35 */ 36 private final HudsonJobConfigurationLoaderConfig loaderConfig; 37 38 /** 39 * The document to fix. 40 */ 41 private final Document document; 42 43 // ****************************** Initializer ******************************* 44 45 // ****************************** Constructors ****************************** 46 47 HudsonJobDocumentFixer(final HudsonJobConfigurationLoaderConfig loaderConfig, 48 final Document document) 49 { 50 this.loaderConfig = loaderConfig; 51 this.document = document; 52 } 53 54 // ****************************** Inner Classes ***************************** 55 56 // ********************************* Methods ******************************** 57 58 // --- init ----------------------------------------------------------------- 59 60 // --- get&set -------------------------------------------------------------- 61 62 // --- business ------------------------------------------------------------- 63 64 void fix() throws JDOMException 65 { 66 removeCascadingChildrenNamesElement(); 67 removeCascadingJobPropertiesElement(); 68 } 69 70 private void removeCascadingChildrenNamesElement() throws JDOMException 71 { 72 if (loaderConfig.isRemoveCascadingChildrenNamesElement()) 73 { 74 remove("cascadingChildrenNames"); 75 } 76 } 77 78 private void removeCascadingJobPropertiesElement() throws JDOMException 79 { 80 if (loaderConfig.isRemoveCascadingJobPropertiesElement()) 81 { 82 remove("cascading-job-properties"); 83 } 84 } 85 86 void remove(final String toLevelElementName) throws JDOMException 87 { 88 document.getRootElement().removeChild(toLevelElementName); 89 } 90 91 // --- object basics -------------------------------------------------------- 92 93 }