1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.model.propertyexpansion.resolvers.providers;
14
15 import java.io.File;
16 import java.net.MalformedURLException;
17 import java.net.URL;
18
19 import com.eviware.soapui.model.project.Project;
20 import com.eviware.soapui.model.propertyexpansion.PropertyExpansionContext;
21 import com.eviware.soapui.model.propertyexpansion.resolvers.DynamicPropertyResolver.ValueProvider;
22 import com.eviware.soapui.model.support.ModelSupport;
23
24 public class ProjectDirProvider implements ValueProvider
25 {
26 public String getValue( PropertyExpansionContext context )
27 {
28 Project project = ModelSupport.getModelItemProject( context.getModelItem() );
29 if( project != null )
30 {
31 return getProjectFolder( project );
32 }
33
34 return null;
35 }
36
37 public static String getProjectFolder( Project project )
38 {
39 if( project.getPath() != null )
40 {
41 File file = new File( project.getPath() );
42 if( file.exists() )
43 {
44 return new File( file.getAbsolutePath() ).getParent();
45 }
46 else
47 {
48 try
49 {
50 URL url = new URL( project.getPath() );
51 String str = url.getProtocol() + "://" + url.getHost()
52 + ( ( url.getPort() != -1 ? ":" + url.getPort() : "" ) ) + url.getPath();
53 int ix = str.lastIndexOf( '/' );
54 if( ix != -1 )
55 return str.substring( 0, ix );
56 }
57 catch( MalformedURLException e )
58 {
59 }
60 }
61 }
62
63 return null;
64 }
65 }