01: /*
02: * soapUI, copyright (C) 2004-2007 eviware.com
03: *
04: * soapUI is free software; you can redistribute it and/or modify it under the
05: * terms of version 2.1 of the GNU Lesser General Public License as published by
06: * the Free Software Foundation.
07: *
08: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
09: * 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.wsdl.actions.iface;
14:
15: import java.io.File;
16:
17: import com.eviware.soapui.impl.wsdl.WsdlInterface;
18: import com.eviware.soapui.impl.wsdl.support.wsdl.CachedWsdlLoader;
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: public class ExportDefinitionAction extends
29: AbstractSoapUIAction<WsdlInterface> {
30: public static final String SOAPUI_ACTION_ID = "ExportDefinitionAction";
31:
32: public ExportDefinitionAction() {
33: super ("Export Definition",
34: "Exports the entire WSDL and included/imported files to a local directory");
35: }
36:
37: public void perform(WsdlInterface iface, Object param) {
38: try {
39: if (exportDefinition(null, iface) != null)
40: UISupport
41: .showInfoMessage("Definition exported succesfully");
42: } catch (Exception e1) {
43: UISupport.showErrorMessage(e1);
44: }
45: }
46:
47: public String exportDefinition(String location, WsdlInterface iface)
48: throws Exception {
49: File folderName = location == null ? UISupport.getFileDialogs()
50: .openDirectory(this , "Select output directory", null)
51: : new File(location);
52:
53: if (folderName == null)
54: return null;
55:
56: CachedWsdlLoader loader = null;
57:
58: if (iface.isCached()) {
59: loader = (CachedWsdlLoader) iface.createWsdlLoader();
60: } else {
61: loader = new CachedWsdlLoader(iface.getDefinition());
62: }
63:
64: return loader.saveDefinition(folderName.getAbsolutePath());
65: }
66: }
|