svn-gvsig-desktop / branches / v10 / extensions / extPublishGeoserver / src / org / gvsig / publish / geoserver / conf / GSServer.java @ 19432
History | View | Annotate | Download (15.6 KB)
1 |
/* gvSIG. Sistema de Información Geográfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004-2006 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 Ibañ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 |
|
42 |
package org.gvsig.publish.geoserver.conf; |
43 |
|
44 |
import java.io.File; |
45 |
import java.io.FileOutputStream; |
46 |
import java.io.IOException; |
47 |
|
48 |
import javax.xml.parsers.DocumentBuilder; |
49 |
import javax.xml.parsers.DocumentBuilderFactory; |
50 |
import javax.xml.parsers.ParserConfigurationException; |
51 |
|
52 |
import org.gvsig.publish.PublishLogger; |
53 |
import org.w3c.dom.Document; |
54 |
import org.w3c.dom.Element; |
55 |
import org.w3c.dom.Node; |
56 |
import org.w3c.dom.Text; |
57 |
|
58 |
import com.sun.org.apache.xml.internal.serialize.OutputFormat; |
59 |
import com.sun.org.apache.xml.internal.serialize.XMLSerializer; |
60 |
|
61 |
/**
|
62 |
* This class represents the global information about Geoserver's services
|
63 |
*
|
64 |
* @author jvhigon (josevicente.higon@iver.es)
|
65 |
*
|
66 |
*/
|
67 |
public class GSServer { |
68 |
//constants
|
69 |
public static final String LOG_SEVERE="SEVERE"; |
70 |
public static final String LOG_WARNING="WARNING"; |
71 |
public static final String LOG_INFO="INFO"; |
72 |
public static final String LOG_CONFIG="CONFIG"; |
73 |
public static final String LOG_FINNER="FINNER"; |
74 |
public static final String LOG_FINNEST="FINNEST"; |
75 |
|
76 |
//Attributes
|
77 |
private boolean loginToFile; |
78 |
private double jaiMemoryCapacity; |
79 |
private double jaiMemoryThreshold; |
80 |
private int jaiTileThreads; |
81 |
private int jaiTilePriority; |
82 |
private boolean jaiRecycling; |
83 |
private boolean ImageIOCache; |
84 |
private boolean JaiJPEGNative; |
85 |
private boolean jaiPNGNative; |
86 |
private boolean verbose; |
87 |
private boolean verboseExceptions; |
88 |
private int numDecimals; |
89 |
private String logginLevel; |
90 |
private int maxFeatures; |
91 |
private String charset; |
92 |
private String user; |
93 |
private String password; |
94 |
|
95 |
//Attributes from associations
|
96 |
private GSWFS wfs;
|
97 |
private GSWMS wms;
|
98 |
/**
|
99 |
* Default constructor
|
100 |
*/
|
101 |
public GSServer (){
|
102 |
//Attributes
|
103 |
this.loginToFile = false; |
104 |
this.jaiMemoryCapacity = 0.0d; |
105 |
this.jaiMemoryThreshold = 0.0d; |
106 |
this.jaiTileThreads = 0; |
107 |
this.jaiTilePriority = 0; |
108 |
this.jaiRecycling = false; |
109 |
this.ImageIOCache = false; |
110 |
this.JaiJPEGNative = false; |
111 |
this.jaiPNGNative = false; |
112 |
this.verbose = false; |
113 |
this.verboseExceptions = false; |
114 |
this.numDecimals = 0; |
115 |
this.maxFeatures = 1000; |
116 |
//create services
|
117 |
this.wfs = new GSWFS(); |
118 |
this.wms = new GSWMS(); |
119 |
} |
120 |
|
121 |
//Accessors
|
122 |
/**
|
123 |
* @return administrator user
|
124 |
*/
|
125 |
public String getAdminUser(){ |
126 |
return this.user; |
127 |
} |
128 |
/**
|
129 |
*
|
130 |
* @return administrator password
|
131 |
*/
|
132 |
public String getAdminPassword(){ |
133 |
return this.password; |
134 |
} |
135 |
/**
|
136 |
* This could use some more testing
|
137 |
* from international users, but what it does is sets the encoding
|
138 |
* globally for all postgis database connections (the charset tag
|
139 |
* in FeatureTypeConfig), as well as specifying the encoding in the return
|
140 |
* config.xml header and mime type. The default is UTF-8. Also be warned
|
141 |
* that GeoServer does not check if the CharSet is valid before
|
142 |
* attempting to use it, so it will fail miserably if a bad charset
|
143 |
* is used.
|
144 |
* @return charset
|
145 |
*/
|
146 |
public String getCharset(){ |
147 |
return this.charset; |
148 |
} |
149 |
|
150 |
/**
|
151 |
* Return loginToFile
|
152 |
* @return boolean
|
153 |
*/
|
154 |
public boolean getLoginToFile(){ |
155 |
return this.loginToFile; |
156 |
} |
157 |
/**
|
158 |
*
|
159 |
* @return max features the service wfs can return
|
160 |
*/
|
161 |
public int getMaxFeatures(){ |
162 |
return this.maxFeatures; |
163 |
} |
164 |
/**
|
165 |
* Return LoginLevel
|
166 |
* @return string SEVERE, WARNING, INFO, CONFIG, FINER, FINEST
|
167 |
*/
|
168 |
public String getLoginLevel(){ |
169 |
return this.logginLevel; |
170 |
} |
171 |
/**
|
172 |
* Set the value of loginToFile.
|
173 |
* @param myloginToFile
|
174 |
*/
|
175 |
public void setLoginToFile(boolean myloginToFile){ |
176 |
this.loginToFile = myloginToFile;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* Return jaiMemoryCapacity
|
181 |
* @return double
|
182 |
*/
|
183 |
public double getJaiMemoryCapacity(){ |
184 |
return this.jaiMemoryCapacity; |
185 |
} |
186 |
|
187 |
/**
|
188 |
* Set the value of jaiMemoryCapacity.
|
189 |
* @param myjaiMemoryCapacity
|
190 |
*/
|
191 |
public void setJaiMemoryCapacity(double myjaiMemoryCapacity){ |
192 |
this.jaiMemoryCapacity = myjaiMemoryCapacity;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Return jaiMemoryThreshold
|
197 |
* @return double
|
198 |
*/
|
199 |
public double getJaiMemoryThreshold(){ |
200 |
return this.jaiMemoryThreshold; |
201 |
} |
202 |
|
203 |
/**
|
204 |
* Set the value of jaiMemoryThreshold.
|
205 |
* @param myjaiMemoryThreshold
|
206 |
*/
|
207 |
public void setJaiMemoryThreshold(double myjaiMemoryThreshold){ |
208 |
this.jaiMemoryThreshold = myjaiMemoryThreshold;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* Return jaiTileThreads
|
213 |
* @return int
|
214 |
*/
|
215 |
public int getJaiTileThreads(){ |
216 |
return this.jaiTileThreads; |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Set the value of jaiTileThreads.
|
221 |
* @param myjaiTileThreads
|
222 |
*/
|
223 |
public void setJaiTileThreads(int myjaiTileThreads){ |
224 |
this.jaiTileThreads = myjaiTileThreads;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Return jaiTilePriority
|
229 |
* @return int
|
230 |
*/
|
231 |
public int getJaiTilePriority(){ |
232 |
return this.jaiTilePriority; |
233 |
} |
234 |
|
235 |
/**
|
236 |
* Set the value of jaiTilePriority.
|
237 |
* @param myjaiTilePriority
|
238 |
*/
|
239 |
public void setJaiTilePriority(int myjaiTilePriority){ |
240 |
this.jaiTilePriority = myjaiTilePriority;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* Return jaiRecycling
|
245 |
* @return boolean
|
246 |
*/
|
247 |
public boolean getJaiRecycling(){ |
248 |
return this.jaiRecycling; |
249 |
} |
250 |
|
251 |
/**
|
252 |
* Set the value of jaiRecycling.
|
253 |
* @param myjaiRecycling
|
254 |
*/
|
255 |
public void setJaiRecycling(boolean myjaiRecycling){ |
256 |
this.jaiRecycling = myjaiRecycling;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* Return ImageIOCache
|
261 |
* @return boolean
|
262 |
*/
|
263 |
public boolean getImageIOCache(){ |
264 |
return this.ImageIOCache; |
265 |
} |
266 |
|
267 |
/**
|
268 |
* Set the value of ImageIOCache.
|
269 |
* @param myImageIOCache
|
270 |
*/
|
271 |
public void setImageIOCache(boolean myImageIOCache){ |
272 |
this.ImageIOCache = myImageIOCache;
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* Return JaiJPEGNative
|
277 |
* @return boolean
|
278 |
*/
|
279 |
public boolean getJaiJPEGNative(){ |
280 |
return this.JaiJPEGNative; |
281 |
} |
282 |
|
283 |
/**
|
284 |
* Set the value of JaiJPEGNative.
|
285 |
* @param myJaiJPEGNative
|
286 |
*/
|
287 |
public void setJaiJPEGNative(boolean myJaiJPEGNative){ |
288 |
this.JaiJPEGNative = myJaiJPEGNative;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* Return jaiPNGNative
|
293 |
* @return boolean
|
294 |
*/
|
295 |
public boolean getJaiPNGNative(){ |
296 |
return this.jaiPNGNative; |
297 |
} |
298 |
|
299 |
/**
|
300 |
* Set the value of jaiPNGNative.
|
301 |
* @param myjaiPNGNative
|
302 |
*/
|
303 |
public void setJaiPNGNative(boolean myjaiPNGNative){ |
304 |
this.jaiPNGNative = myjaiPNGNative;
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* Return verbose
|
309 |
* @return boolean
|
310 |
*/
|
311 |
public boolean getVerbose(){ |
312 |
return this.verbose; |
313 |
} |
314 |
|
315 |
/**
|
316 |
* Whether newlines and indents should be returned in
|
317 |
* XML responses. Default is false
|
318 |
* @param myverbose
|
319 |
*/
|
320 |
public void setVerbose(boolean myverbose){ |
321 |
this.verbose = myverbose;
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* Return verboseExceptions
|
326 |
* @return boolean
|
327 |
*/
|
328 |
public boolean getVerboseExceptions(){ |
329 |
return this.verboseExceptions; |
330 |
} |
331 |
|
332 |
/**
|
333 |
* Set the value of verboseExceptions.
|
334 |
* @param myverboseExceptions
|
335 |
*/
|
336 |
public void setVerboseExceptions(boolean myverboseExceptions){ |
337 |
this.verboseExceptions = myverboseExceptions;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* Return numDecimals
|
342 |
* @return int
|
343 |
*/
|
344 |
public int getNumDecimals(){ |
345 |
return this.numDecimals; |
346 |
} |
347 |
|
348 |
/**
|
349 |
* Sets the max number of decimal places past the zero returned in
|
350 |
* a GetFeature response. Default is 4
|
351 |
* @param mynumDecimals
|
352 |
*/
|
353 |
public void setNumDecimals(int mynumDecimals){ |
354 |
this.numDecimals = mynumDecimals;
|
355 |
} |
356 |
|
357 |
/**
|
358 |
* Return wfs
|
359 |
* @return GSWFS
|
360 |
*/
|
361 |
public GSWFS getWFS(){
|
362 |
return this.wfs; |
363 |
} |
364 |
/**
|
365 |
*
|
366 |
* @return Geoserver service WMS
|
367 |
*/
|
368 |
public GSWMS getWMS() {
|
369 |
return this.wms; |
370 |
} |
371 |
|
372 |
//Methods
|
373 |
|
374 |
/**
|
375 |
* Defines the logging level. Common options are SEVERE,
|
376 |
* WARNING, INFO, CONFIG, FINER, FINEST, in order of
|
377 |
* Increasing statements logged.
|
378 |
* @param level SEVERE, WARNING, INFO, CONFIG, FINER, FINEST
|
379 |
*
|
380 |
*/
|
381 |
public void setLoginLevel(String level) { |
382 |
this.logginLevel = level;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* Sets the max number of Features returned by GetFeature
|
387 |
* @param max
|
388 |
*/
|
389 |
public void setMaxFeatures(int max) { |
390 |
this.maxFeatures = max;
|
391 |
} |
392 |
|
393 |
/**
|
394 |
* Sets the global character set. This could use some more testing
|
395 |
* from international users, but what it does is sets the encoding
|
396 |
* globally for all postgis database connections (the charset tag
|
397 |
* in FeatureTypeConfig), as well as specifying the encoding in the return
|
398 |
* config.xml header and mime type. The default is UTF-8. Also be warned
|
399 |
* that GeoServer does not check if the CharSet is valid before
|
400 |
* attempting to use it, so it will fail miserably if a bad charset
|
401 |
* is used.
|
402 |
* @param charset UTF-8, ISO-8859-1, ...
|
403 |
*/
|
404 |
public void setCharset(String charset) { |
405 |
this.charset = charset;
|
406 |
} |
407 |
|
408 |
/**
|
409 |
* Defines the user name of the administrator for log in
|
410 |
* to the web based administration tool.
|
411 |
* @param user
|
412 |
*/
|
413 |
public void setAdminUser(String user) { |
414 |
this.user = user;
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* Defines the password of the administrator for log in
|
419 |
* to the web based administration tool.
|
420 |
* @param pass
|
421 |
*/
|
422 |
public void setAdminPassword(String pass) { |
423 |
this.password = pass;
|
424 |
} |
425 |
|
426 |
/**
|
427 |
* Writes the services.xml
|
428 |
* @param file where the catalog.xml is generated
|
429 |
*/
|
430 |
public void toXML(File services_xml) { |
431 |
Document dom=null; |
432 |
//get an instance of factory
|
433 |
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); |
434 |
try {
|
435 |
//get an instance of builder
|
436 |
DocumentBuilder db = dbf.newDocumentBuilder();
|
437 |
|
438 |
//create an instance of DOM
|
439 |
dom = db.newDocument(); |
440 |
|
441 |
}catch(ParserConfigurationException pce) { |
442 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + ":Error while trying to instantiate DocumentBuilder " + pce); |
443 |
} |
444 |
//create the root element <serverConfiguration>
|
445 |
Element rootEle = dom.createElement("serverConfiguration"); |
446 |
dom.appendChild(rootEle); |
447 |
|
448 |
//creates <global>
|
449 |
rootEle.appendChild(getGlobalXMLElement(dom)); |
450 |
|
451 |
//creates <services>
|
452 |
Element srvEle = dom.createElement("services"); |
453 |
rootEle.appendChild(srvEle); |
454 |
//adds wfs
|
455 |
srvEle.appendChild(wfs.getXMLElement(dom)); |
456 |
//adds wms
|
457 |
srvEle.appendChild(wms.getXMLElement(dom)); |
458 |
//write files
|
459 |
try
|
460 |
{ |
461 |
OutputFormat format = new OutputFormat(dom);
|
462 |
format.setIndenting(true);
|
463 |
XMLSerializer serializer = new XMLSerializer(
|
464 |
new FileOutputStream(services_xml), format); |
465 |
serializer.serialize(dom); |
466 |
} catch(IOException ioe) { |
467 |
PublishLogger.getLog().error("ERROR " + getClass().getName() + ": I can't generate the catlog.xml", ioe); |
468 |
} |
469 |
|
470 |
} |
471 |
/**
|
472 |
* Creates the global parameters in the XML
|
473 |
* @param dom
|
474 |
*/
|
475 |
private Node getGlobalXMLElement(Document dom){ |
476 |
//create global elements
|
477 |
Element globalEle = dom.createElement("global"); |
478 |
//loginLevel
|
479 |
Element paramEle = dom.createElement("loggingLevel"); |
480 |
Text txt = dom.createTextNode(this.getLoginLevel());
|
481 |
paramEle.appendChild(txt); |
482 |
globalEle.appendChild(paramEle); |
483 |
//loggingToFile
|
484 |
paramEle = dom.createElement("loggingToFile");
|
485 |
txt = dom.createTextNode(new Boolean(this.getLoginToFile()).toString()); |
486 |
paramEle.appendChild(txt); |
487 |
globalEle.appendChild(paramEle); |
488 |
//JaiMemoryCapacity
|
489 |
paramEle = dom.createElement("JaiMemoryCapacity");
|
490 |
txt = dom.createTextNode(new Double(this.getJaiMemoryCapacity()).toString()); |
491 |
paramEle.appendChild(txt); |
492 |
globalEle.appendChild(paramEle); |
493 |
//JaiMemoryThreshold
|
494 |
paramEle = dom.createElement("JaiMemoryThreshold");
|
495 |
txt = dom.createTextNode(new Double(this.getJaiMemoryThreshold()).toString()); |
496 |
paramEle.appendChild(txt); |
497 |
globalEle.appendChild(paramEle); |
498 |
//JaiTileThreads
|
499 |
paramEle = dom.createElement("JaiTileThreads");
|
500 |
txt = dom.createTextNode(new Integer(this.getJaiTileThreads()).toString()); |
501 |
paramEle.appendChild(txt); |
502 |
globalEle.appendChild(paramEle); |
503 |
//JaiTilePriority
|
504 |
paramEle = dom.createElement("JaiTilePriority");
|
505 |
txt = dom.createTextNode(new Integer(this.getJaiTilePriority()).toString()); |
506 |
paramEle.appendChild(txt); |
507 |
globalEle.appendChild(paramEle); |
508 |
//JaiRecycling
|
509 |
paramEle = dom.createElement("JaiRecycling");
|
510 |
txt = dom.createTextNode(new Boolean(this.getJaiRecycling()).toString()); |
511 |
paramEle.appendChild(txt); |
512 |
globalEle.appendChild(paramEle); |
513 |
//ImageIOCache
|
514 |
paramEle = dom.createElement("ImageIOCache");
|
515 |
txt = dom.createTextNode(new Boolean(this.getImageIOCache()).toString()); |
516 |
paramEle.appendChild(txt); |
517 |
globalEle.appendChild(paramEle); |
518 |
//JaiJPEGNative
|
519 |
paramEle = dom.createElement("JaiJPEGNative");
|
520 |
txt = dom.createTextNode(new Boolean(this.getJaiJPEGNative()).toString()); |
521 |
paramEle.appendChild(txt); |
522 |
globalEle.appendChild(paramEle); |
523 |
//JaiPNGNative
|
524 |
paramEle = dom.createElement("JaiPNGNative");
|
525 |
txt = dom.createTextNode(new Boolean(this.getJaiPNGNative()).toString()); |
526 |
paramEle.appendChild(txt); |
527 |
globalEle.appendChild(paramEle); |
528 |
//maxFeatures
|
529 |
paramEle = dom.createElement("maxFeatures");
|
530 |
paramEle.setAttribute("value",new Integer(this.getMaxFeatures()).toString()); |
531 |
globalEle.appendChild(paramEle); |
532 |
//verbose
|
533 |
paramEle = dom.createElement("verbose");
|
534 |
txt = dom.createTextNode(new Boolean(this.getVerbose()).toString()); |
535 |
paramEle.appendChild(txt); |
536 |
globalEle.appendChild(paramEle); |
537 |
//verboseExceptions
|
538 |
paramEle = dom.createElement("verboseExceptions");
|
539 |
txt = dom.createTextNode(new Boolean(this.getVerboseExceptions()).toString()); |
540 |
paramEle.appendChild(txt); |
541 |
globalEle.appendChild(paramEle); |
542 |
//numDecimals
|
543 |
paramEle = dom.createElement("numDecimals");
|
544 |
paramEle.setAttribute("value",new Integer(this.getNumDecimals()).toString()); |
545 |
globalEle.appendChild(paramEle); |
546 |
//charSet
|
547 |
paramEle = dom.createElement("charSet");
|
548 |
paramEle.setAttribute("value",this.getCharset()); |
549 |
globalEle.appendChild(paramEle); |
550 |
//adminUserName
|
551 |
paramEle = dom.createElement("adminUserName");
|
552 |
txt = dom.createTextNode(this.getAdminUser());
|
553 |
paramEle.appendChild(txt); |
554 |
globalEle.appendChild(paramEle); |
555 |
//adminPassword
|
556 |
paramEle = dom.createElement("adminPassword");
|
557 |
txt = dom.createTextNode(this.getAdminPassword());
|
558 |
paramEle.appendChild(txt); |
559 |
globalEle.appendChild(paramEle); |
560 |
|
561 |
return globalEle;
|
562 |
} |
563 |
|
564 |
} |