1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.actions.iface;
14
15 import java.awt.event.ActionEvent;
16 import java.io.File;
17
18 import javax.swing.AbstractAction;
19 import javax.swing.Action;
20
21 import com.eviware.soapui.impl.wsdl.WsdlInterface;
22 import com.eviware.soapui.impl.wsdl.support.wsdl.CachedWsdlLoader;
23 import com.eviware.soapui.support.UISupport;
24
25 /***
26 * Exports the definition (wsdls and xsds) of a WsdlInterface.
27 *
28 * @author Ole.Matzura
29 */
30
31 public class ExportDefinitionAction extends AbstractAction
32 {
33 private final WsdlInterface iface;
34
35 public ExportDefinitionAction( WsdlInterface iface )
36 {
37 super("Export Definition");
38 this.iface = iface;
39 putValue( Action.SMALL_ICON, UISupport.createImageIcon( "/exportDefinition.gif" ));
40 putValue( Action.SHORT_DESCRIPTION, "Exports the entire WSDL and included/imported files to a local directory");
41 putValue( Action.ACCELERATOR_KEY, UISupport.getKeyStroke( "menu P" ));
42 }
43
44 public void actionPerformed(ActionEvent e)
45 {
46 try
47 {
48 if( exportDefinition( null ) != null )
49 UISupport.showInfoMessage( "Definition exported succesfully" );
50 }
51 catch (Exception e1)
52 {
53 UISupport.showErrorMessage( e1 );
54 }
55 }
56
57 public String exportDefinition( String location ) throws Exception
58 {
59 File folderName =location == null ? UISupport.getFileDialogs().openDirectory( this, "Select output directory", null )
60 : new File( location );
61
62 if( folderName == null )
63 return null;
64
65 CachedWsdlLoader loader = null;
66
67 if( iface.isCached() )
68 {
69 loader = (CachedWsdlLoader) iface.createWsdlLoader();
70 }
71 else
72 {
73 loader = new CachedWsdlLoader( iface.getDefinition() );
74 }
75
76 return loader.saveDefinition( folderName.getAbsolutePath() );
77 }
78 }