1
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
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 }