1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.util.xml;
16  
17  import java.io.File;
18  
19  import org.apache.tools.ant.BuildException;
20  import org.apache.tools.ant.Task;
21  
22  /**
23   * <a href="XMLMergerTask.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Jorge Ferrer
26   */
27  public class XMLMergerTask extends Task {
28  
29      public void setMasterFile(File masterFile) {
30          _masterFile = masterFile;
31      }
32  
33      public void setOutputFile(File outputFile) {
34          _outputFile = outputFile;
35      }
36  
37      public void setSlaveFile(File slaveFile) {
38          _slaveFile = slaveFile;
39      }
40  
41      public void setType(String type) {
42          _type = type;
43      }
44  
45      public void execute() throws BuildException {
46          _validateAttributes();
47  
48          try {
49              XMLMergerRunner runner = new XMLMergerRunner(_type);
50  
51              runner.mergeAndSave(_masterFile, _slaveFile, _outputFile);
52          }
53          catch (Exception e) {
54              throw new BuildException(e);
55          }
56      }
57  
58      private void _validateAttributes() {
59          _validateMandatoryAttribute(_masterFile, "masterFile");
60          _validateMandatoryAttribute(_slaveFile, "slaveFile");
61          _validateMandatoryAttribute(_outputFile, "outputFile");
62      }
63  
64      private void _validateMandatoryAttribute(File value, String name) {
65          if (value == null) {
66              throw new BuildException(name + " is a required attribute");
67          }
68      }
69  
70      private File _masterFile;
71      private File _slaveFile;
72      private File _outputFile;
73      private String _type;
74  
75  }