svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / schemas / discoverer / Record.java @ 3566
History | View | Annotate | Download (7.69 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 es.gva.cit.catalogClient.schemas.discoverer; |
43 |
import es.gva.cit.catalogClient.metadataXML.XMLNode; |
44 |
import es.gva.cit.catalogClient.metadataXML.XMLTree; |
45 |
import java.awt.image.BufferedImage; |
46 |
import java.io.File; |
47 |
import java.io.IOException; |
48 |
import java.net.MalformedURLException; |
49 |
import java.net.URL; |
50 |
import java.util.Collection; |
51 |
import javax.imageio.ImageIO; |
52 |
|
53 |
/**
|
54 |
* All classes that implement a tag-parser must to implement this
|
55 |
* class. It only has some fields to show in the application form.
|
56 |
*
|
57 |
*
|
58 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
59 |
*/
|
60 |
public abstract class Record { |
61 |
/**
|
62 |
*
|
63 |
*
|
64 |
*/
|
65 |
private XMLNode node;
|
66 |
|
67 |
/**
|
68 |
*
|
69 |
*
|
70 |
*/
|
71 |
private String title; |
72 |
|
73 |
/**
|
74 |
*
|
75 |
*
|
76 |
*/
|
77 |
private String abstract_; |
78 |
|
79 |
/**
|
80 |
*
|
81 |
*
|
82 |
*/
|
83 |
private String purpose; |
84 |
|
85 |
/**
|
86 |
*
|
87 |
*
|
88 |
*/
|
89 |
private String[] keyWords; |
90 |
/**
|
91 |
*
|
92 |
*
|
93 |
*/
|
94 |
private BufferedImage image; |
95 |
|
96 |
/**
|
97 |
*
|
98 |
*
|
99 |
*/
|
100 |
private String fileID; |
101 |
|
102 |
/**
|
103 |
*
|
104 |
*
|
105 |
*/
|
106 |
private URL serverURL; |
107 |
|
108 |
/**
|
109 |
*
|
110 |
*
|
111 |
*/
|
112 |
private Collection resources = new java.util.ArrayList(); |
113 |
|
114 |
/**
|
115 |
*
|
116 |
*
|
117 |
*
|
118 |
* @return Returns the fileID.
|
119 |
*/
|
120 |
public String getFileID() { |
121 |
return fileID;
|
122 |
} |
123 |
/**
|
124 |
* <p></p>
|
125 |
*
|
126 |
*
|
127 |
*
|
128 |
* @poseidon-type es.gva.cit.catalogClient.schemas.discoverer.Resource
|
129 |
*/
|
130 |
public java.util.Collection resource = new java.util.ArrayList(); |
131 |
|
132 |
/**
|
133 |
*
|
134 |
*
|
135 |
*
|
136 |
* @param fileID The fileID to set.
|
137 |
*/
|
138 |
public void setFileID(String fileID) { |
139 |
this.fileID = fileID;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
*
|
144 |
*
|
145 |
*
|
146 |
* @return Returns the image.
|
147 |
*/
|
148 |
public BufferedImage getImage() { |
149 |
return image;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
*
|
154 |
*
|
155 |
*
|
156 |
* @param image The image to set.
|
157 |
*/
|
158 |
public void setImage(BufferedImage image) { |
159 |
this.image = image;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
*
|
164 |
*
|
165 |
*
|
166 |
* @return Returns the abstract_.
|
167 |
*/
|
168 |
public String getAbstract_() { |
169 |
return abstract_;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
*
|
174 |
*
|
175 |
*
|
176 |
* @param abstract_ The abstract_ to set.
|
177 |
*/
|
178 |
public void setAbstract_(String abstract_) { |
179 |
this.abstract_ = abstract_;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
*
|
184 |
*
|
185 |
*
|
186 |
* @return Returns the keyWords.
|
187 |
*/
|
188 |
public String[] getKeyWords() { |
189 |
return keyWords;
|
190 |
} |
191 |
|
192 |
/**
|
193 |
*
|
194 |
*
|
195 |
*
|
196 |
* @param keyWords The keyWords to set.
|
197 |
*/
|
198 |
public void setKeyWords(String[] keyWords) { |
199 |
this.keyWords = keyWords;
|
200 |
} |
201 |
|
202 |
/**
|
203 |
*
|
204 |
*
|
205 |
*
|
206 |
* @return Returns the purpose.
|
207 |
*/
|
208 |
public String getPurpose() { |
209 |
return purpose;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
*
|
214 |
*
|
215 |
*
|
216 |
* @param purpose The purpose to set.
|
217 |
*/
|
218 |
public void setPurpose(String purpose) { |
219 |
this.purpose = purpose;
|
220 |
} |
221 |
|
222 |
/**
|
223 |
*
|
224 |
*
|
225 |
*
|
226 |
* @return Returns the title.
|
227 |
*/
|
228 |
public String getTitle() { |
229 |
return title;
|
230 |
} |
231 |
|
232 |
/**
|
233 |
*
|
234 |
*
|
235 |
*
|
236 |
* @param title The title to set.
|
237 |
*/
|
238 |
public void setTitle(String title) { |
239 |
this.title = title;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
*
|
244 |
*
|
245 |
*
|
246 |
* @return Returns the node.
|
247 |
*/
|
248 |
public XMLNode getNode() {
|
249 |
return node;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
*
|
254 |
*
|
255 |
*
|
256 |
* @param node The node to set.
|
257 |
*/
|
258 |
public void setNode(XMLNode node) { |
259 |
this.node = node;
|
260 |
} |
261 |
|
262 |
/**
|
263 |
*
|
264 |
*
|
265 |
*
|
266 |
* @return Returns the resources.
|
267 |
*/
|
268 |
public Resource[] getResources() { |
269 |
Resource[] aux = new Resource[resources.size()]; |
270 |
for (int i=0 ; i<aux.length ; i++){ |
271 |
aux[i] = (Resource)resources.toArray()[i]; |
272 |
} |
273 |
return aux;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
*
|
278 |
*
|
279 |
*
|
280 |
* @param resources The resources to set.
|
281 |
*/
|
282 |
public void setResources(Resource[] resources) { |
283 |
this.resources = new java.util.ArrayList(); |
284 |
for (int i=0 ; i<resources.length ; i++){ |
285 |
this.resources.add(resources[i]);
|
286 |
} |
287 |
} |
288 |
|
289 |
/**
|
290 |
*
|
291 |
*
|
292 |
*
|
293 |
* @return Returns the serverURL.
|
294 |
*/
|
295 |
public URL getServerURL() { |
296 |
return serverURL;
|
297 |
} |
298 |
|
299 |
/**
|
300 |
*
|
301 |
*
|
302 |
*
|
303 |
* @param serverURL The serverURL to set.
|
304 |
*/
|
305 |
public void setServerURL(URL serverURL) { |
306 |
this.serverURL = serverURL;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* This method finds an image from an URL and returns it
|
311 |
*
|
312 |
*
|
313 |
* @return
|
314 |
* @param label XML Label where the image link is.
|
315 |
*/
|
316 |
protected BufferedImage getImageUrl(String label) { |
317 |
BufferedImage img;
|
318 |
XMLNode[] nodes = XMLTree.searchMultipleNode(getNode(), label);
|
319 |
if ((nodes == null) || (nodes.length == 0)) { |
320 |
return null; |
321 |
} |
322 |
|
323 |
//Normal Procedure
|
324 |
String imageURL = XMLTree.searchNodeValue(nodes[0], "bgFileName"); |
325 |
img = getImage(imageURL); |
326 |
if (img != null) |
327 |
return img;
|
328 |
|
329 |
//Deegree
|
330 |
img = getImage(nodes[0].getText());
|
331 |
if (img != null) |
332 |
return img;
|
333 |
|
334 |
//Is it Geonetwork running in port 8080?
|
335 |
String sUrl = getGeonetworkImageUrl(imageURL,"8080"); |
336 |
img = getImage(sUrl); |
337 |
if (img != null) |
338 |
return img;
|
339 |
|
340 |
//It is Geonetwork running in port 80?
|
341 |
sUrl = getGeonetworkImageUrl(imageURL,"80");
|
342 |
img = getImage(sUrl); |
343 |
if (img != null) |
344 |
return img;
|
345 |
|
346 |
//Calanu??a
|
347 |
img = getImage("http://delta.icc.es/wefex/images/" + nodes[0].getText() ); |
348 |
if (img != null) |
349 |
return img;
|
350 |
|
351 |
File fichero = new File("images/IcoRecord.png"); |
352 |
try {
|
353 |
return ImageIO.read(fichero); |
354 |
} catch (IOException e2) { |
355 |
// TODO Auto-generated catch block
|
356 |
System.out.println("No he podido leer la imagen desde el fichero"); |
357 |
return null; |
358 |
} |
359 |
} |
360 |
|
361 |
/**
|
362 |
* Only Used for Geonetwork
|
363 |
*
|
364 |
*
|
365 |
* @return
|
366 |
* @param imageUrl Server URL
|
367 |
* @param port Port to connect
|
368 |
*/
|
369 |
private String getGeonetworkImageUrl(String imageUrl, String port) { |
370 |
if (getServerURL() == null) |
371 |
return ""; |
372 |
return "http://" + getServerURL().getHost() + ":" + port + "/geonetwork/srv/es/resources.getgraphover?" + |
373 |
"id=" + getFileID() + "&" + |
374 |
"fname=" + imageUrl;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* It gets an image from a URL
|
379 |
*
|
380 |
*
|
381 |
* @return
|
382 |
* @param sUrl String with the image URL
|
383 |
*/
|
384 |
protected BufferedImage getImage(String sUrl) { |
385 |
try {
|
386 |
URL Url = new URL(sUrl); |
387 |
|
388 |
return ImageIO.read(Url); |
389 |
} catch (MalformedURLException e) { |
390 |
// TODO Auto-generated catch block
|
391 |
System.out.println("La URL de la imagen no es correcta: " + sUrl); |
392 |
} catch (IOException e1) { |
393 |
// TODO Auto-generated catch block
|
394 |
System.out.println("No he podido leer la imagen desde la URL: " + sUrl); |
395 |
} |
396 |
return null; |
397 |
} |
398 |
} |