View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2009 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 java.io.File;
16  
17  import com.eviware.soapui.impl.rest.RestService;
18  import com.eviware.soapui.impl.support.definition.export.WadlDefinitionExporter;
19  import com.eviware.soapui.support.UISupport;
20  import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
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",
57  				null ) : 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  }