Statistics
| Revision:

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 @ 40559

History | View | Annotate | Download (4.21 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
/*
25
 * Created on 01-oct-2005
26
 */
27
package org.gvsig.remoteclient.taskplanning.retrieving;
28

    
29
import java.net.MalformedURLException;
30
import java.net.URL;
31

    
32
/**
33
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
34
 */
35
public class URLRequest{
36
        public static final String HTTP = "http";
37
        private volatile int hashCode = 0;
38
        public static final int GET = 1;
39
        public static final int POST = 2;
40
        
41
        private int requestType = GET;
42
        private String protocol;
43
        private String host;
44
        private int port = -1;
45
        private String file;
46
        private String fileName;
47
        
48
        public URL getUrl() throws MalformedURLException {
49
                String u = protocol;
50
                u += "://"+host;
51
                if (port != -1)
52
                        u += ":"+port;
53
                u += "/"+file;
54
                return new URL(u);
55
        }
56
        /**
57
         * @return Returns the fileName.
58
         */
59
        public String getFileName() {
60
                return fileName;
61
        }
62
        /**
63
         * @param fileName The fileName to set.
64
         */
65
        public void setFileName(String fileName) {
66
                this.fileName = fileName;
67
        }
68
        /**
69
         * @return Returns the host.
70
         */
71
        public String getHost() {
72
                return host;
73
        }
74
        /**
75
         * @param host The host to set.
76
         */
77
        public void setHost(String host) {
78
                this.host = host;
79
        }
80
        /**
81
         * @return Returns the file.
82
         */
83
        public String getFile() {
84
                return file;
85
        }
86
        /**
87
         * @param page The file to set.
88
         */
89
        public void setFile(String page) {
90
                this.file = page;
91
        }
92
        /**
93
         * @return Returns the protocol.
94
         */
95
        public String getProtocol() {
96
                return protocol;
97
        }
98
        /**
99
         * @param protocol The protocol to set.
100
         */
101
        public void setProtocol(String protocol) {
102
                this.protocol = protocol;
103
        }
104
        /**
105
         * @return Returns the requestType.
106
         */
107
        public int getRequestType() {
108
                return requestType;
109
        }
110
        /**
111
         * @param requestType The requestType to set.
112
         */
113
        public void setRequestType(int requestType) {
114
                this.requestType = requestType;
115
        }
116
        /**
117
         * @return Returns the port.
118
         */
119
        public int getPort() {
120
                return port;
121
        }
122
        /**
123
         * @param port The port to set.
124
         */
125
        public void setPort(int port) {
126
                this.port = port;
127
        }
128

    
129
        public int hashCode() {
130
                if (hashCode == 0) {
131
                        int result = 17;
132
                        String[] stringFields = new String[] {
133
                                        fileName,
134
                                        host,
135
                                        file,
136
                                        protocol
137
                        };
138
                        for (int i = 0; i < stringFields.length; i++) {
139
                                if (stringFields[i] != null)
140
                                        for (int j = 0; j < stringFields[i].length(); j++) 
141
                                                result = 37*result + (int) stringFields[i].charAt(j);
142
                                
143
                        }
144
                        result = 37*result + port;
145
                        result = 37*result + requestType;
146
                }
147
                return hashCode;
148
        }
149
        
150
        public boolean equals(Object o) {
151
                if (this == o)
152
                        return true;
153
                if (!(o instanceof URLRequest))
154
                        return false;
155

    
156
                URLRequest other = (URLRequest) o;
157
                
158
                String[] stringFields = new String[] {
159
                                // this.fileName, NO!!! Do not check file name
160
                                this.host,
161
                                this.file,
162
                                this.protocol
163
                };
164
                String[] othersStringField = new String[] {
165
                                // other.fileName, NO!!! Do not check file name
166
                                other.host,
167
                                other.file,
168
                                other.protocol
169
                };
170
                for (int i = 0; i < stringFields.length; i++) {
171
                        if (stringFields[i] == null && othersStringField[i]!=null) return false;
172
                        if (stringFields[i] == null && othersStringField[i]!=null) return false;
173
                        if (stringFields[i] != null && othersStringField[i]!=null) 
174
                                if (!stringFields[i].equals(othersStringField[i])) return false;
175
                }
176
                
177
                if (this.port != other.port) return false;
178
                if (this.requestType != other.requestType) return false;
179
                return true;
180
        }
181
}