View Javadoc

    1   /*
    2    *  soapUI, copyright (C) 2004-2007 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 javax.swing.JOptionPane;
    19  import javax.swing.UIManager;
    20
    21  import com.eviware.soapui.config.SoapuiSettingsDocumentConfig;
    22  import com.eviware.soapui.impl.wsdl.actions.iface.tools.support.SwingToolHost;
    23  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.attachments.AttachmentsInspectorFactory;
    24  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.httpheaders.HttpHeadersInspectorFactory;
    25  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.registry.XmlInspectorRegistry;
    26  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.script.ScriptInspectorFactory;
    27  import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.ssl.SSLInspectorFactory;
    28  import com.eviware.soapui.model.settings.Settings;
    29  import com.eviware.soapui.model.workspace.Workspace;
    30  import com.eviware.soapui.support.UISupport;
    31  import com.eviware.x.form.XFormFactory;
    32  import com.eviware.x.impl.swing.SwingFileDialogs;
    33  import com.eviware.x.impl.swing.SwingFormFactory;
    34
    35  public class SwingSoapUICore extends DefaultSoapUICore
    36  {
    37  	public SwingSoapUICore()
    38  	{
    39  		super();
    40  	}
    41
    42  	public SwingSoapUICore( String settingsFile )
    43  	{
    44  		super( null, settingsFile );
    45  	}
    46
    47  	public void prepareUI()
    48  	{
    49  		UISupport.setToolHost( new SwingToolHost() );
    50        XFormFactory.Factory.instance = new SwingFormFactory();
    51  	}
    52
    53  	public void afterStartup(Workspace workspace)
    54  	{
    55  		XmlInspectorRegistry inspectorRegistry = XmlInspectorRegistry.getInstance();
    56  		inspectorRegistry.addFactory( new ScriptInspectorFactory() );
    57  		inspectorRegistry.addFactory( new HttpHeadersInspectorFactory() );
    58  		inspectorRegistry.addFactory( new AttachmentsInspectorFactory() );
    59  		inspectorRegistry.addFactory( new SSLInspectorFactory() );
    60
    61  		addExternalActions( getRoot() == null ? "actions" : getRoot() + File.separatorChar + "actions",
    62  					getExtensionClassLoader() );
    63  	}
    64
    65  	@Override
    66  	protected Settings initSettings( String fileName )
    67  	{
    68  		if( !new File( fileName ).exists() )
    69  		{
    70  			try
    71  			{
    72  				fileName = importSettingsOnStartup( fileName );
    73  			}
    74  			catch( Exception e )
    75  			{
    76  				e.printStackTrace();
    77  			}
    78  		}
    79
    80  		return super.initSettings( fileName );
    81  	}
    82
    83  	protected String importSettingsOnStartup( String fileName ) throws Exception
    84  	{
    85  		javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    86
    87  		if( JOptionPane.showConfirmDialog( null, "Missing soapUI Settings, import from existing installation?",
    88  					"Import Preferences", JOptionPane.YES_NO_OPTION ) == JOptionPane.YES_OPTION )
    89  		{
    90  			while( true )
    91  			{
    92  				File settingsFile = SwingFileDialogs.openFile( null, "Import Preferences", ".xml", "soapUI settings XML", fileName );
    93  				if( settingsFile != null )
    94  				{
    95  					try
    96  					{
    97  						SoapuiSettingsDocumentConfig.Factory.parse( settingsFile );
    98  						log.info( "imported soapui-settings from [" + settingsFile.getAbsolutePath() + "]" );
    99  						return settingsFile.getAbsolutePath();
    100 					}
    101 					catch( Exception e )
    102 					{
    103 						if( JOptionPane.showConfirmDialog( null, "Error loading settings from [" + settingsFile.getAbsolutePath() + "]\r\nspecify another?",
    104 									"Error Importing", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE ) == JOptionPane.CANCEL_OPTION )
    105 						{
    106 							break;
    107 						}
    108 					}
    109 				}
    110 			}
    111 		}
    112
    113 		return fileName;
    114 	}
    115
    116 	private void addExternalActions( String folder, ClassLoader classLoader )
    117 	{
    118 		File[] actionFiles = new File( folder ).listFiles();
    119       if( actionFiles != null )
    120       {
    121 	      for( File actionFile : actionFiles )
    122 	      {
    123 	      	if( actionFile.isDirectory() )
    124 	      	{
    125 	      		addExternalActions( actionFile.getAbsolutePath(), classLoader );
    126 	      		continue;
    127 	      	}
    128
    129 	      	if( !actionFile.getName().toLowerCase().endsWith( "-actions.xml" ))
    130 	      		continue;
    131
    132 	      	try
    133 				{
    134 	      		log.info( "Adding actions from [" + actionFile.getAbsolutePath() + "]" );
    135
    136 					SoapUI.getActionRegistry().addConfig( new FileInputStream( actionFile ),
    137 								classLoader);
    138 				}
    139 				catch( Exception e )
    140 				{
    141 					SoapUI.logError( e );
    142 				}
    143 	      }
    144       }
    145 	}
    146 }