Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / core / PathMapItem.java
1 package net.sourceforge.phpeclipse.xdebug.core;
2
3 //import java.net.MalformedURLException;
4 //import java.net.URL;
5
6 import org.eclipse.core.runtime.IPath;
7 import org.eclipse.core.runtime.Path;
8
9 public class PathMapItem {
10         private IPath local;
11         private IPath remote;
12
13         // String.split() uses regular expressions
14         static final String DELIMITER_REGEX = "\\+\\*\\+";
15         static final String DELIMITER = "+*+";
16         
17         static private String MakeStringData(IPath local, IPath remote) {
18                 //IPath b = new Path("file:/var/www/index.php");
19                 
20                 if(local.getDevice() == "file://") {
21                         local = local.setDevice("");
22                 }
23                 String data = local.toString()+DELIMITER+remote.toString();
24                 return data;
25         }
26         
27         public PathMapItem(String newLocal, String newRemote) {
28                 IPath localPath = sanitizePath(newLocal);
29                 IPath remotePath = sanitizePath(newRemote);
30                 local = localPath;
31                 remote = remotePath;
32         }
33
34         private IPath sanitizePath(String newPath) {
35                 IPath sanitizePath = null;
36                 IPath computePath = new Path(newPath);
37                 /*if(computePath.getDevice() == null) {
38                         sanitizePath = new Path("file://", newPath);
39                 } else {
40                         if(computePath.getDevice() == "file:") {
41                                 sanitizePath = computePath;
42                         } else {*/
43                                 sanitizePath = computePath;                             
44                         /*}
45                 }*/
46                 return sanitizePath;
47         }
48         
49         public PathMapItem(String data) {
50                 String[] strData = data.split(DELIMITER_REGEX);
51                 IPath localPath = sanitizePath(strData[0]);
52                 IPath remotePath = sanitizePath(strData[1]);
53                 local = localPath;
54                 remote = remotePath;
55         }
56         
57         public String getStringData() {
58                 return PathMapItem.MakeStringData(local, remote);
59         }
60         
61         /**
62          * Returns the local path, which serves as the key in the local/remote
63          * pair this variable represents
64          * 
65          * @return local path
66          */
67         public IPath getLocalPath() {
68                 return new Path(local.toString());
69         }
70         
71         /**
72          * Returns the remote path.
73          * 
74          * @return remote path
75          */
76         public IPath getRemotePath() {
77                 return new Path(remote.toString());
78         }
79
80         /**
81          * Sets the local path
82          * @param local path
83          * @throws MalformedURLException 
84          */
85         public void setLocalPath(String path) {
86                 this.local = sanitizePath(path);
87         }
88         
89         /**
90          * Sets the local path
91          * @param local path
92          */
93         public void setLocalPath(IPath path) {
94                 this.local = path;
95         }
96
97         /**
98          * Sets the remote path
99          * @param remote path
100          */
101         public void setRemotePath(IPath path) {
102                 this.remote = path;
103         }
104
105         /**
106          * Sets the remote path
107          * @param remote path
108          * @throws MalformedURLException 
109          */
110         public void setRemotePath(String path) {
111                 this.remote = sanitizePath(path);
112         }
113         
114         /* (non-Javadoc)
115          * @see java.lang.Object#toString()
116          */
117         public String toString() {
118                 return local.toString()+"->"+remote.toString();
119         }
120
121         /* (non-Javadoc)
122          * @see java.lang.Object#equals(java.lang.Object)
123          */
124         public boolean equals(Object obj) {
125                 boolean equal = false;
126                 if (obj instanceof PathMapItem) {
127                         PathMapItem var = (PathMapItem) obj;
128                         equal = var.getLocalPath().equals(local);
129                 }
130                 return equal;           
131         }
132 }