Fix SourceLookupMessage constant.(SourceLookupMessages.DefaultSourceContainer_0 eclip...
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / variable / UrlExpander.java
1 package net.sourceforge.phpdt.externaltools.variable;
2
3 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
4 import net.sourceforge.phpeclipse.ui.WebUI;
5
6 import org.eclipse.core.runtime.IPath;
7 import org.eclipse.jface.preference.IPreferenceStore;
8
9 /**
10  * Expands a variable into a localhost/documentRoot URL string
11  * <p>
12  * This class is not intended to be extended by clients.
13  * </p>
14  */
15 public class UrlExpander extends ResourceExpander { // implements
16                                                                                                         // IVariableTextExpander {
17
18         /**
19          * Create an instance
20          */
21         public UrlExpander() {
22                 super();
23         }
24
25         /**
26          * Returns a string representation to a localhost/documentRoot URL for the
27          * given variable tag and value or <code>null</code>.
28          * 
29          * @see IVariableTextExpander#getText(String, String, ExpandVariableContext)
30          */
31         public String getText(String varTag, String varValue,
32                         ExpandVariableContext context) {
33                 IPath path = getPath(varTag, varValue, context);
34                 if (path != null) {
35                         IPreferenceStore store = ExternalToolsPlugin.getDefault()
36                                         .getPreferenceStore();
37                         String localhostURL = path.toString();
38                         String lowerCaseFileName = localhostURL.toLowerCase();
39                         String documentRoot = store.getString(WebUI.PHP_DOCUMENTROOT_PREF);
40                         documentRoot = documentRoot.replace('\\', '/');
41                         documentRoot = documentRoot.toLowerCase();
42
43                         if (lowerCaseFileName.startsWith(documentRoot)) {
44                                 localhostURL = localhostURL.substring(documentRoot.length());
45                                 localhostURL = store.getString(WebUI.PHP_LOCALHOST_PREF)
46                                                 + localhostURL;
47                         }
48                         return localhostURL;
49                 }
50                 return "<no file selected>";
51         }
52
53 }