svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / taskplanning / retrieving / URLRequest.java @ 40769
History | View | Annotate | Download (4.18 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.remoteclient.taskplanning.retrieving; |
25 |
|
26 |
import java.net.MalformedURLException; |
27 |
import java.net.URL; |
28 |
|
29 |
/**
|
30 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
31 |
*/
|
32 |
public class URLRequest{ |
33 |
public static final String HTTP = "http"; |
34 |
private volatile int hashCode = 0; |
35 |
public static final int GET = 1; |
36 |
public static final int POST = 2; |
37 |
|
38 |
private int requestType = GET; |
39 |
private String protocol; |
40 |
private String host; |
41 |
private int port = -1; |
42 |
private String file; |
43 |
private String fileName; |
44 |
|
45 |
public URL getUrl() throws MalformedURLException { |
46 |
String u = protocol;
|
47 |
u += "://"+host;
|
48 |
if (port != -1) |
49 |
u += ":"+port;
|
50 |
u += "/"+file;
|
51 |
return new URL(u); |
52 |
} |
53 |
/**
|
54 |
* @return Returns the fileName.
|
55 |
*/
|
56 |
public String getFileName() { |
57 |
return fileName;
|
58 |
} |
59 |
/**
|
60 |
* @param fileName The fileName to set.
|
61 |
*/
|
62 |
public void setFileName(String fileName) { |
63 |
this.fileName = fileName;
|
64 |
} |
65 |
/**
|
66 |
* @return Returns the host.
|
67 |
*/
|
68 |
public String getHost() { |
69 |
return host;
|
70 |
} |
71 |
/**
|
72 |
* @param host The host to set.
|
73 |
*/
|
74 |
public void setHost(String host) { |
75 |
this.host = host;
|
76 |
} |
77 |
/**
|
78 |
* @return Returns the file.
|
79 |
*/
|
80 |
public String getFile() { |
81 |
return file;
|
82 |
} |
83 |
/**
|
84 |
* @param page The file to set.
|
85 |
*/
|
86 |
public void setFile(String page) { |
87 |
this.file = page;
|
88 |
} |
89 |
/**
|
90 |
* @return Returns the protocol.
|
91 |
*/
|
92 |
public String getProtocol() { |
93 |
return protocol;
|
94 |
} |
95 |
/**
|
96 |
* @param protocol The protocol to set.
|
97 |
*/
|
98 |
public void setProtocol(String protocol) { |
99 |
this.protocol = protocol;
|
100 |
} |
101 |
/**
|
102 |
* @return Returns the requestType.
|
103 |
*/
|
104 |
public int getRequestType() { |
105 |
return requestType;
|
106 |
} |
107 |
/**
|
108 |
* @param requestType The requestType to set.
|
109 |
*/
|
110 |
public void setRequestType(int requestType) { |
111 |
this.requestType = requestType;
|
112 |
} |
113 |
/**
|
114 |
* @return Returns the port.
|
115 |
*/
|
116 |
public int getPort() { |
117 |
return port;
|
118 |
} |
119 |
/**
|
120 |
* @param port The port to set.
|
121 |
*/
|
122 |
public void setPort(int port) { |
123 |
this.port = port;
|
124 |
} |
125 |
|
126 |
public int hashCode() { |
127 |
if (hashCode == 0) { |
128 |
int result = 17; |
129 |
String[] stringFields = new String[] { |
130 |
fileName, |
131 |
host, |
132 |
file, |
133 |
protocol |
134 |
}; |
135 |
for (int i = 0; i < stringFields.length; i++) { |
136 |
if (stringFields[i] != null) |
137 |
for (int j = 0; j < stringFields[i].length(); j++) |
138 |
result = 37*result + (int) stringFields[i].charAt(j); |
139 |
|
140 |
} |
141 |
result = 37*result + port;
|
142 |
result = 37*result + requestType;
|
143 |
} |
144 |
return hashCode;
|
145 |
} |
146 |
|
147 |
public boolean equals(Object o) { |
148 |
if (this == o) |
149 |
return true; |
150 |
if (!(o instanceof URLRequest)) |
151 |
return false; |
152 |
|
153 |
URLRequest other = (URLRequest) o; |
154 |
|
155 |
String[] stringFields = new String[] { |
156 |
// this.fileName, NO!!! Do not check file name
|
157 |
this.host,
|
158 |
this.file,
|
159 |
this.protocol
|
160 |
}; |
161 |
String[] othersStringField = new String[] { |
162 |
// other.fileName, NO!!! Do not check file name
|
163 |
other.host, |
164 |
other.file, |
165 |
other.protocol |
166 |
}; |
167 |
for (int i = 0; i < stringFields.length; i++) { |
168 |
if (stringFields[i] == null && othersStringField[i]!=null) return false; |
169 |
if (stringFields[i] == null && othersStringField[i]!=null) return false; |
170 |
if (stringFields[i] != null && othersStringField[i]!=null) |
171 |
if (!stringFields[i].equals(othersStringField[i])) return false; |
172 |
} |
173 |
|
174 |
if (this.port != other.port) return false; |
175 |
if (this.requestType != other.requestType) return false; |
176 |
return true; |
177 |
} |
178 |
} |