1 /* 2 * Copyright 2011-2013 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.tagcloud.maven; 17 18 import java.io.File; 19 import java.io.IOException; 20 import java.io.OutputStream; 21 22 import javax.xml.parsers.ParserConfigurationException; 23 24 import org.apache.commons.io.FileUtils; 25 import org.apache.commons.io.IOUtils; 26 import org.apache.maven.plugin.MojoExecutionException; 27 28 import de.smartics.tagcloud.TagCloud; 29 import de.smartics.tagcloud.export.XmlTagCloudExport; 30 31 /** 32 * Generates XML reports. 33 * 34 * @goal tagcloud 35 * @phase compile 36 * @requiresProject 37 * @description Generates XML reports. 38 * @author <a href="mailto:robert.reiner@smartics.de">Robert Reiner</a> 39 * @version $Revision:591 $ 40 */ 41 public class XmlExportMojo extends AbstractTagCloudMojo 42 { 43 // ********************************* Fields ********************************* 44 45 // --- constants ------------------------------------------------------------ 46 47 // --- members -------------------------------------------------------------- 48 49 /** 50 * Specifies the root directory to write the XML file to. 51 * 52 * @parameter expression="${project.build.directory}/tagcloud.xml" 53 * @since 1.0 54 */ 55 private String outputFile; 56 57 // ****************************** Initializer ******************************* 58 59 // ****************************** Constructors ****************************** 60 61 // ****************************** Inner Classes ***************************** 62 63 // ********************************* Methods ******************************** 64 65 // --- init ----------------------------------------------------------------- 66 67 // --- get&set -------------------------------------------------------------- 68 69 // --- business ------------------------------------------------------------- 70 71 /** 72 * Exports the cloud data as XML. 73 * 74 * @param tagCloud the cloud to be exported. 75 */ 76 @Override 77 protected void runWith(final TagCloud tagCloud) throws MojoExecutionException 78 { 79 try 80 { 81 final OutputStream output = 82 FileUtils.openOutputStream(new File(outputFile)); 83 try 84 { 85 final XmlTagCloudExport export = new XmlTagCloudExport(true); 86 export.export(tagCloud, output); 87 } 88 finally 89 { 90 IOUtils.closeQuietly(output); 91 } 92 } 93 catch (final IOException e) 94 { 95 throw new MojoExecutionException("Cannot generate tag cloud XML file.", e); 96 } 97 catch (final ParserConfigurationException e) 98 { 99 throw new MojoExecutionException("Cannot generate tag cloud XML file.", e); 100 } 101 } 102 103 // --- object basics -------------------------------------------------------- 104 105 }