--- /dev/null
+package net.sourceforge.phpdt.externaltools.variable;
+
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+/**
+ * Expands a variable into the last opened PHP file
+ * <p>
+ * This class is not intended to be extended by clients.
+ * </p>
+ */
+public class LastPHPUrlExpander extends ResourceExpander { //implements IVariableTextExpander {
+
+ /**
+ * Create an instance
+ */
+ public LastPHPUrlExpander() {
+ super();
+ }
+
+ /**
+ * Returns a string representation of the path to a file or directory
+ * for the given variable tag and value or <code>null</code>.
+ *
+ * @see IVariableTextExpander#getText(String, String, ExpandVariableContext)
+ */
+ public String getText(String varTag, String varValue, ExpandVariableContext context) {
+ IPath path = getPath(varTag, varValue, context);
+ if (path != null) {
+ IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+ String localhostURL = path.toString();
+ String lowerCaseFileName = localhostURL.toLowerCase();
+ // fileName = "http://localhost"+fileName.replaceAll("c:", "");
+ String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
+ documentRoot = documentRoot.replace('\\', '/');
+ documentRoot = documentRoot.toLowerCase();
+
+ if (lowerCaseFileName.startsWith(documentRoot)) {
+ localhostURL = localhostURL.substring(documentRoot.length());
+ } else {
+ return localhostURL;
+ }
+
+ return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL.replaceAll(documentRoot, "");
+
+ }
+ return null;
+ }
+
+}