001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.util.xml;
016    
017    import java.io.File;
018    
019    import org.apache.tools.ant.BuildException;
020    import org.apache.tools.ant.Task;
021    
022    /**
023     * @author Jorge Ferrer
024     */
025    public class XMLMergerTask extends Task {
026    
027            @Override
028            public void execute() throws BuildException {
029                    _validateAttributes();
030    
031                    try {
032                            XMLMergerRunner runner = new XMLMergerRunner(_type);
033    
034                            runner.mergeAndSave(_masterFile, _slaveFile, _outputFile);
035                    }
036                    catch (Exception e) {
037                            throw new BuildException(e);
038                    }
039            }
040    
041            public void setMasterFile(File masterFile) {
042                    _masterFile = masterFile;
043            }
044    
045            public void setOutputFile(File outputFile) {
046                    _outputFile = outputFile;
047            }
048    
049            public void setSlaveFile(File slaveFile) {
050                    _slaveFile = slaveFile;
051            }
052    
053            public void setType(String type) {
054                    _type = type;
055            }
056    
057            private void _validateAttributes() {
058                    _validateMandatoryAttribute(_masterFile, "masterFile");
059                    _validateMandatoryAttribute(_slaveFile, "slaveFile");
060                    _validateMandatoryAttribute(_outputFile, "outputFile");
061            }
062    
063            private void _validateMandatoryAttribute(File value, String name) {
064                    if (value == null) {
065                            throw new BuildException(name + " is a required attribute");
066                    }
067            }
068    
069            private File _masterFile;
070            private File _outputFile;
071            private File _slaveFile;
072            private String _type;
073    
074    }