View Javadoc

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