OSDN Git Service

update command line interface, and introduce command pattern in Main class
[stigmata/stigmata.git] / src / main / java / jp / sourceforge / stigmata / command / ExportConfigCommand.java
1 package jp.sourceforge.stigmata.command;
2
3 /*
4  * $Id$
5  */
6
7 import java.io.FileWriter;
8 import java.io.IOException;
9 import java.io.PrintWriter;
10
11 import jp.sourceforge.stigmata.BirthmarkContext;
12 import jp.sourceforge.stigmata.Stigmata;
13 import jp.sourceforge.stigmata.utils.ConfigFileExporter;
14
15 /**
16  * 
17  * @author Haruaki Tamada
18  * @version $Revision$
19  */
20 public class ExportConfigCommand extends AbstractStigmataCommand{
21
22     @Override
23     public String getCommandString(){
24         return "export-config";
25     }
26
27     public void perform(Stigmata stigmata, BirthmarkContext context, String[] args){
28         try{
29             PrintWriter out;
30             if(args == null || args.length == 0){
31                 out = new PrintWriter(System.out);
32             }
33             else{
34                 if(!args[0].endsWith(".xml")){
35                     args[0] = args[0] + ".xml";
36                 }
37                 out = new PrintWriter(new FileWriter(args[0]));
38             }
39
40             new ConfigFileExporter(context.getEnvironment()).export(out);
41             out.close();
42         }catch(IOException e){
43         }
44     }
45 }