Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appCatalog / src / org / gvsig / catalog / protocols / HTTPGetProtocol.java @ 37871

History | View | Annotate | Download (2.8 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package org.gvsig.catalog.protocols;
43
import java.io.File;
44
import java.net.URL;
45
import java.util.Collection;
46

    
47
import org.apache.commons.httpclient.NameValuePair;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

    
51
import org.gvsig.catalog.metadataxml.XMLTree;
52
import org.gvsig.remoteclient.utils.Utilities;
53

    
54

    
55
/**
56
 * 
57
 * 
58
 * 
59
 * @author Jorge Piera Llodra (piera_jor@gva.es)
60
 */
61
public class HTTPGetProtocol implements IProtocols {
62
    private static final Logger LOG =
63
        LoggerFactory.getLogger(HTTPGetProtocol.class);
64
    
65
        /**
66
         * 
67
         * 
68
         * 
69
         * @return 
70
         * @param url 
71
         * @param object 
72
         * @param firstRecord 
73
         */
74
        public Collection doQuery(URL url, Object object, int firstRecord) {        
75
                NameValuePair[] parameters = (NameValuePair[]) object;
76
                File file = null;
77

    
78
                String sUrl = "http://" + url.getHost() + ":" +
79
                url.getPort() + url.getPath();
80
                sUrl = sUrl + createURLParams(parameters);
81
                
82
                try {        
83
                        file = Utilities.downloadFile(new URL(sUrl),
84
                                        "catalog-", null);
85

    
86
                } catch (Exception e) {
87
                    LOG.error("Error sending the request", e);
88
                    return null;
89
                }
90

    
91
                Collection col = new java.util.ArrayList();
92
                col.add(XMLTree.xmlToTree(file));
93
                return col;
94
        } 
95

    
96
        /**
97
         * Create and string for a list of params
98
         * @param params
99
         * @return
100
         */
101
        private String createURLParams(NameValuePair[] params){
102
                StringBuffer buffer = new StringBuffer();
103
                for (int i=0 ; i<params.length ; i++){
104
                        if (i==0){
105
                                buffer.append("?");
106
                        }else{
107
                                buffer.append("&");
108
                        }
109
                        buffer.append(params[i].getName());
110
                        buffer.append("=");
111
                        buffer.append(params[i].getValue());
112
                }
113
                return buffer.toString();
114
        }
115

    
116
}