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