1 package de.matthias_burbach.mosaique4eclipse.views;
2
3 import java.io.File;
4
5 import org.eclipse.core.resources.IFile;
6 import org.eclipse.core.runtime.IPath;
7 import org.eclipse.core.runtime.Path;
8
9 import de.matthias_burbach.mosaique.core.model.PathFinder;
10 import de.matthias_burbach.mosaique4eclipse.util.Util;
11
12 /***
13 * Implements the special VRP logic to derive the correct absolute path
14 * from a relative path of a resource and from the Eclipse project context.
15 *
16 * @author Matthias Burbach
17 */
18 public class VrpEclipsePathFinder implements PathFinder {
19
20 /***
21 * The path src/web relative to the project that houses the given Struts
22 * config file.
23 */
24 private IPath webSrcPath;
25
26 /***
27 * The root directory of the brand project that houses the given Struts
28 * config file.
29 */
30 private String brandRoot;
31
32 /***
33 * The name of the brand project that houses the given Struts
34 * config file, e. g. 'wlb'.
35 */
36 private String brandName;
37
38 /***
39 * @param strutsConfigIFile The Struts config file to hook on the path
40 * finder logic for this instance.
41 */
42 public VrpEclipsePathFinder(final IFile strutsConfigIFile) {
43 IPath strutsConfigPath = strutsConfigIFile.getFullPath();
44 IPath brandWebSrcPath = strutsConfigPath.removeLastSegments(2);
45 webSrcPath = brandWebSrcPath.removeFirstSegments(1);
46 brandRoot = Util.iPathToAbsolutePath(brandWebSrcPath);
47 String[] brandProjectNameParts =
48 brandWebSrcPath.segment(0).split("-");
49 brandName =
50 brandProjectNameParts[brandProjectNameParts.length - 1];
51 }
52
53
54
55
56
57
58 /***
59 * {@inheritDoc}
60 * A path is first looked up in the brand project that contains the given
61 * Struts config file. If the path does not exist there, it tries to find it
62 * in a presentation component project.
63 * As a last resort, it tries to resolve the path against the local deploy
64 * directory.
65 */
66 public String findAbsolutePath(final String relativePath) {
67
68 String path = brandRoot + relativePath;
69 if (!Util.existsInOpenProject(path)) {
70
71 String cmp = (new Path(relativePath)).segment(0);
72 IPath cmpPath = new Path("/vrp-presentation-" + cmp);
73 cmpPath = cmpPath.append(webSrcPath);
74 cmpPath = cmpPath.append(new Path(relativePath));
75 path = Util.iPathToAbsolutePath(cmpPath);
76 }
77 if (!Util.existsInOpenProject(path)) {
78
79 path = "D://vrp-localdeploy//applications//"
80 + brandName + "//"
81 + brandName.toUpperCase() + "//"
82 + relativePath;
83 }
84 String result = null;
85 if ((new File(path)).exists()) {
86 result = path;
87 }
88 return result;
89 }
90 }