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;
14  
15  import java.io.File;
16  import java.io.FileInputStream;
17  
18  import com.eviware.soapui.config.SoapuiSettingsDocumentConfig;
19  import com.eviware.soapui.impl.rest.panels.request.inspectors.representations.RestRepresentationsInspectorFactory;
20  import com.eviware.soapui.impl.rest.panels.request.inspectors.schema.InferredSchemaInspectorFactory;
21  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.SwingToolHost;
22  import com.eviware.soapui.model.settings.Settings;
23  import com.eviware.soapui.model.workspace.Workspace;
24  import com.eviware.soapui.support.UISupport;
25  import com.eviware.soapui.support.editor.inspectors.attachments.AttachmentsInspectorFactory;
26  import com.eviware.soapui.support.editor.inspectors.aut.AutInspectorFactory;
27  import com.eviware.soapui.support.editor.inspectors.httpheaders.HttpHeadersInspectorFactory;
28  import com.eviware.soapui.support.editor.inspectors.script.ScriptInspectorFactory;
29  import com.eviware.soapui.support.editor.inspectors.ssl.SSLInspectorFactory;
30  import com.eviware.soapui.support.editor.inspectors.wsa.WsaInspectorFactory;
31  import com.eviware.soapui.support.editor.inspectors.wsrm.WsrmInspectorFactory;
32  import com.eviware.soapui.support.editor.inspectors.wss.WssInspectorFactory;
33  import com.eviware.soapui.support.editor.registry.InspectorRegistry;
34  import com.eviware.x.form.XFormFactory;
35  import com.eviware.x.impl.swing.SwingFormFactory;
36  
37  public class SwingSoapUICore extends DefaultSoapUICore
38  {
39  	public SwingSoapUICore()
40  	{
41  		super();
42  	}
43  
44  	public SwingSoapUICore( String root, String settingsFile )
45  	{
46  		super( root, settingsFile );
47  	}
48  
49  	public SwingSoapUICore( boolean settingPassword, String soapUISettingsPassword )
50  	{
51  		super( settingPassword, soapUISettingsPassword );
52  	}
53  
54  	public void prepareUI()
55  	{
56  		UISupport.setToolHost( new SwingToolHost() );
57  		XFormFactory.Factory.instance = new SwingFormFactory();
58  	}
59  
60  	public void afterStartup( Workspace workspace )
61  	{
62  		InspectorRegistry inspectorRegistry = InspectorRegistry.getInstance();
63  		inspectorRegistry.addFactory( new ScriptInspectorFactory() );
64  		inspectorRegistry.addFactory( new AutInspectorFactory() );
65  		inspectorRegistry.addFactory( new HttpHeadersInspectorFactory() );
66  		inspectorRegistry.addFactory( new AttachmentsInspectorFactory() );
67  		inspectorRegistry.addFactory( new SSLInspectorFactory() );
68  		inspectorRegistry.addFactory( new WssInspectorFactory() );
69  		inspectorRegistry.addFactory( new WsaInspectorFactory() );
70  		inspectorRegistry.addFactory( new WsrmInspectorFactory() );
71  		// inspectorRegistry.addFactory( new WsrmPiggybackInspectorFactory());
72  		inspectorRegistry.addFactory( new RestRepresentationsInspectorFactory() );
73  		inspectorRegistry.addFactory( new InferredSchemaInspectorFactory() );
74  
75  		String actionsDir = System.getProperty( "soapui.ext.actions" );
76  		addExternalActions( actionsDir == null ? getRoot() == null ? "actions" : getRoot() + File.separatorChar
77  				+ "actions" : actionsDir, getExtensionClassLoader() );
78  	}
79  
80  	@Override
81  	protected Settings initSettings( String fileName )
82  	{
83  		String fn = fileName;
84  
85  		if( !new File( fileName ).exists() )
86  		{
87  			try
88  			{
89  				fileName = importSettingsOnStartup( fileName );
90  			}
91  			catch( Exception e )
92  			{
93  				e.printStackTrace();
94  			}
95  		}
96  
97  		Settings result = super.initSettings( fileName );
98  
99  		if( !fileName.equals( fn ) )
100 			setSettingsFile( fn );
101 
102 		return result;
103 	}
104 
105 	protected String importSettingsOnStartup( String fileName ) throws Exception
106 	{
107 		if( UISupport.getDialogs().confirm( "Missing soapUI Settings, import from existing installation?",
108 				"Import Preferences" ) )
109 		{
110 			while( true )
111 			{
112 				File settingsFile = UISupport.getFileDialogs().open( null, "Import Preferences", ".xml",
113 						"soapUI settings XML", fileName );
114 				if( settingsFile != null )
115 				{
116 					try
117 					{
118 						SoapuiSettingsDocumentConfig.Factory.parse( settingsFile );
119 						log.info( "imported soapui-settings from [" + settingsFile.getAbsolutePath() + "]" );
120 						return settingsFile.getAbsolutePath();
121 					}
122 					catch( Exception e )
123 					{
124 						if( !UISupport.getDialogs().confirm(
125 								"Error loading settings from [" + settingsFile.getAbsolutePath() + "]\r\nspecify another?",
126 								"Error Importing" ) )
127 						{
128 							break;
129 						}
130 					}
131 				}
132 			}
133 		}
134 
135 		return fileName;
136 	}
137 
138 	private void addExternalActions( String folder, ClassLoader classLoader )
139 	{
140 		File[] actionFiles = new File( folder ).listFiles();
141 		if( actionFiles != null )
142 		{
143 			for( File actionFile : actionFiles )
144 			{
145 				if( actionFile.isDirectory() )
146 				{
147 					addExternalActions( actionFile.getAbsolutePath(), classLoader );
148 					continue;
149 				}
150 
151 				if( !actionFile.getName().toLowerCase().endsWith( "-actions.xml" ) )
152 					continue;
153 
154 				try
155 				{
156 					log.info( "Adding actions from [" + actionFile.getAbsolutePath() + "]" );
157 
158 					SoapUI.getActionRegistry().addConfig( new FileInputStream( actionFile ), classLoader );
159 				}
160 				catch( Exception e )
161 				{
162 					SoapUI.logError( e );
163 				}
164 			}
165 		}
166 	}
167 }