buildframework/helium/sf/java/core/src/com/nokia/helium/core/ant/types/FMPPMessage.java
changeset 628 7c4a911dc066
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18  
       
    19 package com.nokia.helium.core.ant.types;
       
    20 
       
    21 import java.io.File;
       
    22 import org.apache.tools.ant.BuildException;
       
    23 import org.apache.tools.ant.types.DataType;
       
    24 import org.apache.log4j.Logger;
       
    25 import fmpp.tools.AntTask;
       
    26 import fmpp.tools.AntTask.AntAttributeSubstitution;
       
    27 
       
    28 import java.io.IOException;
       
    29 import java.io.InputStream;
       
    30 import java.io.FileInputStream;
       
    31 import com.nokia.helium.core.MessageCreationException;
       
    32 import com.nokia.helium.core.ant.Message;
       
    33 
       
    34 
       
    35 /**
       
    36  * Helper class to store the list of targets to be recorded and to be sent for diamonds.
       
    37  *
       
    38  * Example 1:
       
    39  * <pre>
       
    40  *   &lt;hlm:fmppMessage target="diamonds" sourceFile="tool.xml.ftl"&gt;
       
    41  *        &lt;data expandProperties="yes"&gt;
       
    42  *           ant: antProperties()
       
    43  *       &lt;/data&gt;
       
    44  *   &lt;/hlm:fmppMessage&gt;
       
    45  * </pre>
       
    46  * @ant.type name="fmppMessage" category="Core" 
       
    47  */
       
    48 public class FMPPMessage extends DataType implements Message {
       
    49 
       
    50     private File outputFile;
       
    51 
       
    52     private AntTask task = new AntTask();
       
    53     
       
    54     private Logger log = Logger.getLogger(FMPPMessage.class);
       
    55 
       
    56     public void setSourceFile(File sourceFile) {
       
    57         if (!sourceFile.exists()) {
       
    58             throw new BuildException("input file : " + sourceFile + " doesn't exists");
       
    59         }
       
    60         task.setSourceFile(sourceFile);
       
    61     }
       
    62     
       
    63     public void setFreemarkerLinks(String freemarkerLinks) {
       
    64         task.setFreemarkerLinks(freemarkerLinks);
       
    65     }
       
    66 
       
    67     public void addConfiguredData(AntAttributeSubstitution ats) {
       
    68         task.addConfiguredData(ats);
       
    69     }
       
    70 
       
    71     public void addConfiguredFreemarkerLinks(AntAttributeSubstitution ats) {
       
    72         task.addConfiguredFreemarkerLinks(ats);
       
    73     }
       
    74     public void setTemplateData(String templateData) {
       
    75         task.setTemplateData(templateData);
       
    76     }
       
    77 
       
    78     public InputStream getInputStream() throws MessageCreationException {
       
    79         InputStream stream = null;
       
    80         try {
       
    81             task.setProject(getProject());
       
    82             outputFile = File.createTempFile("fmppmessage", ".xml");
       
    83             outputFile.deleteOnExit();
       
    84             task.setTaskName("fmpp");
       
    85             task.setOutputFile(outputFile);
       
    86             task.execute();
       
    87             log.debug("outputfile in getinputstream: " + outputFile);
       
    88             stream = new FileInputStream(outputFile);
       
    89         } catch (BuildException bex) {
       
    90             throw new MessageCreationException(bex.getMessage());
       
    91         }
       
    92         catch (IOException iex) {
       
    93             throw new MessageCreationException(iex.getMessage());
       
    94         }
       
    95         return stream;
       
    96     }
       
    97 }