deleted dependency from net.sourceforge.phpeclipse module
[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 IVariableTextExpander {
16
17   /**
18    * Create an instance
19    */
20   public UrlExpander() {
21     super();
22   }
23
24   /**
25    * Returns a string representation to a localhost/documentRoot URL 
26    * for the given variable tag and value or <code>null</code>.
27    * 
28    * @see IVariableTextExpander#getText(String, String, ExpandVariableContext)
29    */
30   public String getText(String varTag, String varValue, ExpandVariableContext context) {
31     IPath path = getPath(varTag, varValue, context);
32     if (path != null) {
33       IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore();
34       String localhostURL = path.toString();
35       String lowerCaseFileName = localhostURL.toLowerCase();
36       String documentRoot = store.getString(WebUI.PHP_DOCUMENTROOT_PREF);
37       documentRoot = documentRoot.replace('\\', '/');
38       documentRoot = documentRoot.toLowerCase();
39
40       if (lowerCaseFileName.startsWith(documentRoot)) {
41         localhostURL = localhostURL.substring(documentRoot.length());
42         localhostURL = store.getString(WebUI.PHP_LOCALHOST_PREF)+ localhostURL;
43       }
44       return localhostURL;
45     }
46     return "<no file selected>";
47   }
48
49 }