View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.rest.actions.service;
14  
15  import com.eviware.soapui.impl.rest.RestService;
16  import com.eviware.soapui.impl.support.definition.export.WadlDefinitionExporter;
17  import com.eviware.soapui.support.UISupport;
18  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
19  
20  import java.io.File;
21  
22  /***
23   * Exports the definition (wsdls and xsds) of a WsdlInterface to the file system
24   *
25   * @author Ole.Matzura
26   */
27  
28  @SuppressWarnings("unchecked")
29  public class ExportWadlAction extends AbstractSoapUIAction<RestService>
30  {
31     public static final String SOAPUI_ACTION_ID = "ExportWadlAction";
32  
33     public ExportWadlAction()
34     {
35        super("Export WADL", "Exports the entire WADL and included/imported files to a local directory");
36     }
37  
38     public void perform(RestService iface, Object param)
39     {
40        try
41        {
42           String path = exportDefinition( null, iface );
43           if ( path != null)
44           {
45              UISupport.showInfoMessage( "WADL exported succesfully to [" + path + "]", "Export WADL" );
46           }
47        }
48        catch (Exception e1)
49        {
50           UISupport.showErrorMessage(e1);
51        }
52     }
53  
54     public String exportDefinition(String location, RestService iface) throws Exception
55     {
56        File folderName = location == null ? UISupport.getFileDialogs().openDirectory(this, "Select output directory", null)
57                : new File(location);
58  
59        if (folderName == null)
60           return null;
61  
62        WadlDefinitionExporter exporter = new WadlDefinitionExporter(iface);
63        return exporter.export(folderName.getAbsolutePath());
64     }
65  }