Revision 3358
trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/catalogClient/parsers/ISO19115Deegree/DeegreeRecordsParser.java | ||
---|---|---|
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.ISO19115Deegree; |
|
42 |
|
|
43 |
import java.awt.image.BufferedImage; |
|
44 |
import java.io.File; |
|
45 |
import java.io.IOException; |
|
46 |
import java.net.MalformedURLException; |
|
47 |
import java.net.URL; |
|
48 |
|
|
49 |
import javax.imageio.ImageIO; |
|
50 |
|
|
51 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
|
52 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
|
53 |
import es.gva.cit.catalogClient.parsers.AbstractTags; |
|
54 |
import es.gva.cit.catalogClient.parsers.Resource; |
|
55 |
|
|
56 |
/** |
|
57 |
* This class is used to parse the metadata retreived using |
|
58 |
* the CSW deegree server. |
|
59 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
|
60 |
*/ |
|
61 |
public class DeegreeRecordsParser extends AbstractTags { |
|
62 |
|
|
63 |
public DeegreeRecordsParser(XMLNode node) { |
|
64 |
setNode(node); |
|
65 |
|
|
66 |
setTitle(XMLTree.searchNodeValue(node, |
|
67 |
"iso19115:identificationInfo->smXML:MD_DataIdentification->smXML:citation->smXML:CI_Citation->smXML:title->smXML:CharacterString")); |
|
68 |
setAbstract_(XMLTree.searchNodeValue(node, |
|
69 |
"iso19115:identificationInfo->smXML:MD_DataIdentification->smXML:abstract->smXML:CharacterString")); |
|
70 |
setPurpose(XMLTree.searchNodeValue(node, |
|
71 |
"iso19115:identificationInfo->smXML:MD_DataIdentification->smXML:purpose->smXML:CharacterString")); |
|
72 |
setKeyWords(XMLTree.searchMultipleNodeValue(node, |
|
73 |
"iso19115:identificationInfo->smXML:MD_DataIdentification->smXML:descriptiveKeywords->smXML:MD_Keywords->smXML:keyword->smXML:CharacterString")); |
|
74 |
setResources(getResources("iso19115:distributionInfo->smXML:distributor->smXML:distributorTransferOptions->smXML:onLine")); |
|
75 |
setImage(getImageUrl("iso19115:identificationInfo->smXML:MD_DataIdentification->smXMLgraphicOverview->fileName")); |
|
76 |
} |
|
77 |
|
|
78 |
/** |
|
79 |
* It parses the online resources |
|
80 |
* @param label |
|
81 |
* Label that contains the resource root |
|
82 |
* @return |
|
83 |
* Resource |
|
84 |
*/ |
|
85 |
private Resource[] getResources(String label) { |
|
86 |
XMLNode[] nodes = XMLTree.searchMultipleNode(getNode(), label); |
|
87 |
|
|
88 |
if (nodes == null) { |
|
89 |
return null; |
|
90 |
} |
|
91 |
|
|
92 |
Resource[] resources = new Resource[nodes.length]; |
|
93 |
|
|
94 |
for (int i = 0; i < resources.length; i++) |
|
95 |
resources[i] = new Resource(XMLTree.searchNodeValue(nodes[i], |
|
96 |
"linkage"), |
|
97 |
"www:link", |
|
98 |
"orName", |
|
99 |
"orDesc", |
|
100 |
"", |
|
101 |
"", |
|
102 |
null); |
|
103 |
|
|
104 |
return resources; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* This method finds an image from an URL and returns it |
|
109 |
* @param label |
|
110 |
* XML Label where the image link is. |
|
111 |
* @return |
|
112 |
*/ |
|
113 |
private BufferedImage getImageUrl(String label) { |
|
114 |
BufferedImage img; |
|
115 |
|
|
116 |
XMLNode[] nodes = XMLTree.searchMultipleNode(getNode(), label); |
|
117 |
|
|
118 |
if ((nodes == null) || (nodes.length == 0)) { |
|
119 |
return null; |
|
120 |
} |
|
121 |
|
|
122 |
img = getImage("http://delta.icc.es/wefex/images/" + nodes[0].getText() ); |
|
123 |
if (img != null) |
|
124 |
return img; |
|
125 |
|
|
126 |
File fichero = new File("images/IcoRecord.png"); |
|
127 |
|
|
128 |
try { |
|
129 |
return ImageIO.read(fichero); |
|
130 |
} catch (IOException e2) { |
|
131 |
// TODO Auto-generated catch block |
|
132 |
System.out.println("No he podido leer la imagen desde el fichero"); |
|
133 |
|
|
134 |
return null; |
|
135 |
} |
|
136 |
|
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* It gets an image from a URL |
|
141 |
* @param sUrl |
|
142 |
* String with the image URL |
|
143 |
* @return |
|
144 |
*/ |
|
145 |
private BufferedImage getImage(String sUrl){ |
|
146 |
try { |
|
147 |
URL Url = new URL(sUrl); |
|
148 |
|
|
149 |
return ImageIO.read(Url); |
|
150 |
} catch (MalformedURLException e) { |
|
151 |
// TODO Auto-generated catch block |
|
152 |
System.out.println("La URL de la imagen no es correcta: " + sUrl); |
|
153 |
} catch (IOException e1) { |
|
154 |
// TODO Auto-generated catch block |
|
155 |
System.out.println("No he podido leer la imagen desde la URL: " + sUrl); |
|
156 |
} |
|
157 |
return null; |
|
158 |
} |
|
159 |
} |
|
0 | 160 |
Also available in: Unified diff