View Javadoc

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  import de.smartics.ci.config.utils.JDomUtils;
22  
23  /**
24   * Merges two Hudson config files.
25   */
26  class DocumentMerger
27  {
28    // ********************************* Fields *********************************
29  
30    // --- constants ------------------------------------------------------------
31  
32    // --- members --------------------------------------------------------------
33  
34    // ****************************** Initializer *******************************
35  
36    // ****************************** Constructors ******************************
37  
38    // ****************************** Inner Classes *****************************
39  
40    // ********************************* Methods ********************************
41  
42    // --- init -----------------------------------------------------------------
43  
44    // --- get&set --------------------------------------------------------------
45  
46    // --- business -------------------------------------------------------------
47  
48    /**
49     * Merges {@code newDocument} into the give {@code document}.
50     *
51     * @param document the document to have information added and is returned. May
52     *          be <code>null</code> so that the {@code newDocument} is returned.
53     * @param newDocument the document to add information to {@code document}. May
54     *          be <code>null</code> so that the {@code document} is returned.
55     * @return the merged document.
56     * @throws JDOMException on any XML problem encountered while merging the
57     *           documents.
58     */
59    Document merge(final Document document, final Document newDocument)
60      throws JDOMException
61    {
62      if (document == null)
63      {
64        return newDocument;
65      }
66      if (newDocument == null)
67      {
68        return document;
69      }
70  
71      JDomUtils.merge(document, newDocument);
72  
73      return document;
74    }
75  
76    // --- object basics --------------------------------------------------------
77  
78  }