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.model.propertyexpansion.resolvers.providers;
14  
15  import com.eviware.soapui.SoapUI;
16  import com.eviware.soapui.impl.wsdl.support.PathUtils;
17  import com.eviware.soapui.model.ModelItem;
18  import com.eviware.soapui.model.project.Project;
19  import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
20  import com.eviware.soapui.model.propertyexpansion.resolvers.DynamicPropertyResolver.ValueProvider;
21  import com.eviware.soapui.model.support.ModelSupport;
22  import com.eviware.soapui.model.workspace.Workspace;
23  
24  public class WorkspaceDirProvider implements ValueProvider
25  {
26  	public String getValue( PropertyExpansionContext context )
27  	{
28  		Workspace workspace = SoapUI.getWorkspace();
29  
30  		if( workspace == null )
31  		{
32  			ModelItem modelItem = context.getModelItem();
33  			if( modelItem instanceof Workspace )
34  			{
35  				workspace = ( Workspace )modelItem;
36  			}
37  			else
38  			{
39  				Project project = ModelSupport.getModelItemProject( modelItem );
40  				if( project != null )
41  					workspace = project.getWorkspace();
42  			}
43  		}
44  
45  		return workspace == null ? null : PathUtils.getAbsoluteFolder( workspace.getPath() );
46  	}
47  }