Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / parsers / z3950 / Z3959RecordsParser.java @ 3081

History | View | Annotate | Download (5.87 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.catalogClient.parsers.z3950;
42

    
43
import es.gva.cit.catalogClient.metadataXML.XMLNode;
44
import es.gva.cit.catalogClient.metadataXML.XMLTree;
45
import es.gva.cit.catalogClient.parsers.AbstractTags;
46
import es.gva.cit.catalogClient.parsers.Resource;
47
import es.gva.cit.catalogClient.querys.Coordinates;
48
import java.awt.image.BufferedImage;
49

    
50
import java.io.File;
51
import java.io.IOException;
52

    
53
import java.net.MalformedURLException;
54
import java.net.URL;
55

    
56
import javax.imageio.ImageIO;
57

    
58

    
59

    
60
/**
61
 * @author Jorge Piera Llodra (piera_jor@gva.es)
62
 */
63

    
64
public class Z3959RecordsParser extends AbstractTags {
65
/**
66
 * Constructor
67
 * @param node
68
 * Node with the answer
69
 * @param serverURL
70
 * Server URL. Necessary to load the image (just Geonetwork)
71
 * 
72
 */
73
    public Z3959RecordsParser(XMLNode node,URL serverURL) {
74
        setNode(node);
75
        setTitle(XMLTree.searchNodeValue(node,
76
                "dataIdInfo->idCitation->resTitle"));
77
        setAbstract_(XMLTree.searchNodeValue(node, "dataIdInfo->idAbs"));
78
        setPurpose(XMLTree.searchNodeValue(node, "dataIdInfo->idPurp"));
79
        setKeyWords(XMLTree.searchMultipleNodeValue(node,
80
                "dataIdInfo->descKeys->keyword"));
81
        setResources(getResources("distInfo->distTranOps->onLineSrc"));
82
        setFileID(XMLTree.searchNodeValue(node,"mdFileID"));
83
        setServerURL(serverURL);
84
        //Caution: getImageUrl uses serverURL and FileID!!!
85
        setImage(getImageUrl("dataIdInfo->graphOver"));
86
        
87
   }
88

    
89
    private Resource[] getResources(String label) {
90
        XMLNode[] nodes = XMLTree.searchMultipleNode(getNode(), label);
91
        Coordinates coordinates = null;
92
        String srs = null;
93
        
94
        if (nodes == null) {
95
            return null;
96
        }
97

    
98
        Resource[] resources = new Resource[nodes.length];
99

    
100
        if (nodes.length > 0){
101
                srs = XMLTree.searchNodeValue(getNode(),"refSysInfo->MdCoRefSys->refSysID->identCode");
102
                coordinates = new Coordinates(XMLTree.searchNodeValue(getNode(),"dataIdInfo->geoBox->westBL"),
103
                                XMLTree.searchNodeValue(getNode(),"dataIdInfo->geoBox->northBL"),
104
                                        XMLTree.searchNodeValue(getNode(),"dataIdInfo->geoBox->eastBL"),
105
                                        XMLTree.searchNodeValue(getNode(),"dataIdInfo->geoBox->southBL"));
106
        }
107
                
108
                
109
        for (int i = 0; i < resources.length; i++)
110
            
111
                resources[i] = new Resource(XMLTree.searchNodeValue(nodes[i],
112
                        "linkage"),
113
                    XMLTree.searchNodeValue(nodes[i], "protocol"),
114
                    XMLTree.searchNodeValue(nodes[i], "orName"),
115
                    XMLTree.searchNodeValue(nodes[i], "orDesc"),
116
                    XMLTree.searchNodeAtribute(nodes[i], "orFunct->OnFunctCd",
117
                        "value"),
118
                                        srs,        
119
                            coordinates);
120

    
121
        return resources;
122
    }
123

    
124
    private BufferedImage getImageUrl(String label) {
125
        URL Url;
126
        BufferedImage img;
127
        XMLNode[] nodes = XMLTree.searchMultipleNode(getNode(), label);
128

    
129
        if ((nodes == null) || (nodes.length == 0)) {
130
            return null;
131
        }
132

    
133
        //Normal Procedure
134
        String imageURL = XMLTree.searchNodeValue(nodes[0], "bgFileName");
135
     
136
        img = getImage(imageURL);
137
        if (img != null)
138
            return img;
139
                     
140
        //Is it Geonetwork running in port  8080?
141
        String sUrl = getGeonetworkImageUrl(imageURL,"8080");              
142
        img = getImage(sUrl);
143
        if (img != null)
144
            return img;
145
        
146
        //It is Geonetwork running in port 80?
147
        sUrl = getGeonetworkImageUrl(imageURL,"80");   
148
        img = getImage(sUrl);
149
        if (img != null)
150
            return img;
151
        
152
        File fichero = new File("images/IcoRecord.png");
153

    
154
        try {
155
            return ImageIO.read(fichero);
156
        } catch (IOException e2) {
157
            // TODO Auto-generated catch block
158
            System.out.println("No he podido leer la imagen desde el fichero");
159

    
160
            return null;
161
        }
162
    }
163
    
164
    private String getGeonetworkImageUrl(String imageUrl,String port){
165
        return "http://" + getServerURL().getHost() + ":" + port + "/geonetwork/srv/es/resources.getgraphover?" +
166
            "id=" + getFileID() + "&" +
167
            "fname=" + imageUrl;
168
    }
169
    
170
    private BufferedImage getImage(String sUrl){
171
        try {
172
            URL Url = new URL(sUrl);
173
        
174
            return ImageIO.read(Url);
175
        } catch (MalformedURLException e) {
176
            // TODO Auto-generated catch block
177
            System.out.println("La URL de la imagen no es correcta: " + sUrl);
178
        } catch (IOException e1) {
179
            // TODO Auto-generated catch block
180
            System.out.println("No he podido leer la imagen desde la URL: " + sUrl);
181
        }
182
        return null;
183
    }
184
}