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 return file.getParentFile().getAbsolutePath();
44 else
45 {
46 try
47 {
48 URL url = new URL( project.getPath() );
49 String str = url.getProtocol() + "://" + url.getHost() + ((url.getPort() != -1 ? ":" + url.getPort() : "")) + url.getPath();
50 int ix = str.lastIndexOf( '/' );
51 if( ix != -1 )
52 return str.substring( 0, ix );
53 }
54 catch( MalformedURLException e )
55 {
56 }
57 }
58 }
59
60 return null;
61 }
62 }